org.jgroups.stack
Class LogicalAddress

java.lang.Object
  extended by org.jgroups.stack.LogicalAddress
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Address, Streamable

public class LogicalAddress
extends java.lang.Object
implements Address

Logical address that spans the lifetime of a member. Assigned at member (JVM) startup, and retained until member is shutdown. Note that the address does not change on disconnect-connect sequences. For example, when a member is shunned and subsequently readmitted to the group, the member's address (LogicalAddress) remains the same.
An instance of LogicalAddress is generated by the transport protocol. Currently, only UDP_NIO generates LogicalAddresses.
Note that host, timestamp and id are supposed to make LogicalAddress as unique as possible. However, there is a remote chance that 2 instances started on the same machine create their address at exactly the same time, resulting in identical addresses (leading to problems). In the future, I will try to make this totally unique, by for example using the PID of the current process (once available though the JDK, or by locking on a common resource (e.g. /dev/random) to serialize creation. However, as for now, chances are you will never experience this problem.

Author:
Bela Ban, Dec 23 2003
See Also:
Serialized Form

Field Summary
protected static int count
           
protected  java.lang.String host
           
protected  int id
           
protected  boolean multicast_addr
           
protected  java.util.ArrayList physical_addrs
          List of physical addresses
protected  long timestamp
           
 
Constructor Summary
LogicalAddress()
           
LogicalAddress(java.lang.String host_name, java.util.List physical_addrs)
          Use this constructor to create an instance, not the null-constructor
 
Method Summary
 void addPhysicalAddress(java.net.SocketAddress addr)
          For internal use only.
 java.lang.Object clone()
           
 int compare(LogicalAddress other)
          Establishes an order between 2 addresses.
 int compareTo(java.lang.Object o)
          implements the java.lang.Comparable interface
 LogicalAddress copy()
           
 boolean equals(java.lang.Object obj)
           
 byte[] getAdditionalData()
          Returns the additional_data.
 java.lang.String getHost()
           
 long getId()
           
 java.util.ArrayList getPhysicalAddresses()
          Returns a copy of the list of physical addresses.
 java.net.SocketAddress getPrimaryPhysicalAddress()
           
 long getTimestamp()
           
 int hashCode()
           
protected  void init(java.lang.String host_name, java.util.List physical_addrs)
           
 boolean isMulticastAddress()
          Checks whether this is an address that represents multiple destinations; e.g., a class D address in the Internet.
 void readExternal(java.io.ObjectInput in)
           
 void readFrom(java.io.DataInputStream in)
          Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed
 void removeAllPhysicalAddresses()
          For internal use only.
 void removePhysicalAddress(java.net.SocketAddress addr)
          For internal use only.
 void setAdditionalData(byte[] additional_data)
          Sets the additional_data.
 void setPrimaryPhysicalAddress(java.net.SocketAddress primary_physical_addr)
           
 int size()
          Returns serialized size of this address
 java.lang.String toString()
           
 java.lang.String toString(boolean print_details)
           
 void writeExternal(java.io.ObjectOutput out)
           
 void writeTo(java.io.DataOutputStream out)
          Write the entire state of the current object (including superclasses) to outstream.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

count

protected static int count

host

protected java.lang.String host

timestamp

protected long timestamp

id

protected int id

multicast_addr

protected boolean multicast_addr

physical_addrs

protected java.util.ArrayList physical_addrs
List of physical addresses

Constructor Detail

LogicalAddress

public LogicalAddress()

LogicalAddress

public LogicalAddress(java.lang.String host_name,
                      java.util.List physical_addrs)
Use this constructor to create an instance, not the null-constructor

Method Detail

init

protected void init(java.lang.String host_name,
                    java.util.List physical_addrs)

getHost

public java.lang.String getHost()

getTimestamp

public long getTimestamp()

getId

public long getId()

getPrimaryPhysicalAddress

public java.net.SocketAddress getPrimaryPhysicalAddress()

setPrimaryPhysicalAddress

public void setPrimaryPhysicalAddress(java.net.SocketAddress primary_physical_addr)

getPhysicalAddresses

public java.util.ArrayList getPhysicalAddresses()
Returns a copy of the list of physical addresses. Reason for the copy is that the list is not supposed to be modified (should be immutable).

Returns:
List of physical addresses (return value maybe null)

addPhysicalAddress

public void addPhysicalAddress(java.net.SocketAddress addr)
For internal use only. Don't use this method!

Parameters:
addr -

removePhysicalAddress

public void removePhysicalAddress(java.net.SocketAddress addr)
For internal use only. Don't use this method !

Parameters:
addr -

removeAllPhysicalAddresses

public void removeAllPhysicalAddresses()
For internal use only. Don't use this method !


isMulticastAddress

public boolean isMulticastAddress()
Description copied from interface: Address
Checks whether this is an address that represents multiple destinations; e.g., a class D address in the Internet.

Specified by:
isMulticastAddress in interface Address
Returns:
true if this is a multicast address, false if it is a unicast address

size

public int size()
Description copied from interface: Address
Returns serialized size of this address

Specified by:
size in interface Address

getAdditionalData

public byte[] getAdditionalData()
Returns the additional_data.

Returns:
byte[]

setAdditionalData

public void setAdditionalData(byte[] additional_data)
Sets the additional_data.

Parameters:
additional_data - The additional_data to set

compare

public int compare(LogicalAddress other)
Establishes an order between 2 addresses. Assumes other contains non-null IpAddress. Excludes channel_name from comparison.

Returns:
0 for equality, value less than 0 if smaller, greater than 0 if greater.

compareTo

public int compareTo(java.lang.Object o)
implements the java.lang.Comparable interface

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - - the Object to be compared
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - - if the specified object's type prevents it from being compared to this Object.
See Also:
Comparable

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(boolean print_details)

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeTo

public void writeTo(java.io.DataOutputStream out)
             throws java.io.IOException
Description copied from interface: Streamable
Write the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed

Specified by:
writeTo in interface Streamable
Throws:
java.io.IOException

readFrom

public void readFrom(java.io.DataInputStream in)
              throws java.io.IOException,
                     java.lang.IllegalAccessException,
                     java.lang.InstantiationException
Description copied from interface: Streamable
Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed

Specified by:
readFrom in interface Streamable
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

copy

public LogicalAddress copy()


Copyright ? 1998-2006 Bela Ban. All Rights Reserved.