001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc.distributed.jgroups;
019
020import net.sf.hajdbc.distributed.Member;
021
022import org.jgroups.Address;
023
024/**
025 * Identifies a group member using the JGroups Address.
026 * 
027 * @author Paul Ferraro
028 * @see org.jgroups.Address
029 */
030public class AddressMember implements Member
031{
032        private static final long serialVersionUID = -5777399287019796606L;
033        
034        private final Address address;
035        
036        /**
037         * Constructs a new AddressMember
038         * @param address the member's address
039         */
040        public AddressMember(Address address)
041        {
042                this.address = address;
043        }
044
045        public Address getAddress()
046        {
047                return this.address;
048        }
049
050        /**
051         * {@inheritDoc}
052         * @see java.lang.Object#equals(java.lang.Object)
053         */
054        @Override
055        public boolean equals(Object object)
056        {
057                if ((object == null) || !(object instanceof AddressMember)) return false;
058
059                AddressMember member = (AddressMember) object;
060                
061                return this.address.equals(member.address);
062        }
063
064        /**
065         * {@inheritDoc}
066         * @see java.lang.Object#hashCode()
067         */
068        @Override
069        public int hashCode()
070        {
071                return this.address.hashCode();
072        }
073
074        /**
075         * {@inheritDoc}
076         * @see java.lang.Object#toString()
077         */
078        @Override
079        public String toString()
080        {
081                return this.address.toString();
082        }
083
084        /**
085         * {@inheritDoc}
086         * @see java.lang.Comparable#compareTo(java.lang.Object)
087         */
088        @Override
089        public int compareTo(Member member)
090        {
091                return this.address.compareTo(((AddressMember) member).address);
092        }
093}