1 /* 2 * Copyright (c) 1998-2002 The Jgroup Team. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License version 2 as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * 17 */ 18 19 package jgroup.core; 20 21 import java.io.Externalizable; 22 23 import jgroup.relacs.types.LocalId; 24 import net.jini.jeri.Endpoint; 25 26 /** 27 * A class implementing this interface uniquely identify a member 28 * object in a group. <p> 29 * 30 * A member identifier is composed by three parts: 31 * <UL> 32 * <LI> an IP address, uniquely identifying the machine hosting the 33 * member; </LI> 34 * <LI> the incarnation time of the Jgroup subsystem hosting the 35 * member, i.e. the time at which the Jgroup subsystem was created; 36 * </LI> 37 * <LI> a member counter, which is used to distinguish multiple members 38 * running in the same Java virtual machine. </LI> 39 * </UL> 40 * 41 * When created, a Jgroup subsytem takes control over some UDP 42 * communication port. Given the UDP specification, it is impossible 43 * that two Jgroup subsystem share the same port in the same machine. 44 * In this way, it is possible to discover if a remote Jgroup subsystem 45 * has crashed and then recovered; in this case, their incarnation 46 * times differ (the more recent is greater than the older). 47 * 48 * When a <code>MemberId</code> is created, its IP address and its 49 * incarnation time are set equal to each member id created in that 50 * Java virtual machine. So, the identifiers of members hosted in the 51 * same Java virtual machine differs only for the member counter. <p> 52 * 53 * Member ids may be compared in the following ways: 54 * <UL> 55 * <LI> two <code>MembersId</code>s are equal (method <tt>equals</tt>) 56 * if and only if they have the same IP address, the same incarnation 57 * time and the same member counter; </LI> 58 * <LI> two <code>MembersId</code>s are <i>neighbours</i> (method 59 * <tt>isNeighbour</tt>) if and only if they have the same IP address 60 * and the same incarnation time; i.e., if they are hosted in the same 61 * virtual machine;</LI> 62 * <LI> a <code>MembersId</code> is <i>newer</i> than another 63 * <code>MembersId</code> (method <tt>isNewer</tt>) if and only if 64 * their IP addresses are the same and the incarnation time of the 65 * former id is greater than the incarnation time of the latter id; in 66 * other words, if the Java virtual machine hosting the latter member 67 * id has crashed (freeing the control over the UDP port) and then 68 * recovered. </LI> 69 * </UL> 70 * 71 * @author Alberto Montresor 72 * @author Hein Meling 73 * @author Marcin Solarski 74 * @since Jgroup 0.9 75 */ 76 public interface MemberId 77 extends Externalizable, Comparable<MemberId> 78 { 79 80 /** 81 * Returns the EndPoint (IP, port) of the java virtual machine 82 * hosting this member. 83 */ 84 public EndPoint getEndPoint(); 85 86 /** 87 * Returns the TcpEndpoint of this member. 88 */ 89 public Endpoint getTcpEndpoint(); 90 91 /** 92 * Returns a LocalId object used to distinguish this particular 93 * member from other members of the same group hosted in 94 * the same Java virtual machine. 95 */ 96 public LocalId getLocalId(); 97 98 /** 99 * Returns the canonical hostname associated with the 100 * JVM on which the member is running. 101 */ 102 public String getCanonicalHostName(); 103 104 /** 105 * Returns the server port associated with this member host. 106 * The server port is computed deterministically, based on the 107 * the host port number and the member number. 108 */ 109 public int getServerPort(); 110 111 /** 112 * Returns true if and only if the IP addresses of this member id and 113 * the specified id are the same, and the incarnation time of the former 114 * is greater than the incarnation time of the latter; in other words, 115 * if the Java virtual machine hosting the specified member id has crashed 116 * and then recovered. 117 */ 118 public boolean isNewer(MemberId id); 119 120 /** 121 * Returns true if and only if this member id and the specified member id 122 * have the same IP address and the same incarnation time; i.e., if they 123 * are hosted in the same virtual machine. 124 */ 125 public boolean isNeighbour(MemberId id); 126 127 } // END MemberId