org.jgroups.stack

Class LogicalAddress

Implemented Interfaces:
Address, Cloneable, Comparable, Externalizable, 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

Field Summary

protected static int
count
protected String
host
protected int
id
protected boolean
multicast_addr
protected ArrayList
physical_addrs
List of physical addresses
protected long
timestamp

Constructor Summary

LogicalAddress()
LogicalAddress(String host_name, List physical_addrs)
Use this constructor to create an instance, not the null-constructor

Method Summary

void
addPhysicalAddress(SocketAddress addr)
For internal use only.
Object
clone()
int
compare(LogicalAddress other)
Establishes an order between 2 addresses.
int
compareTo(Object o)
implements the java.lang.Comparable interface
LogicalAddress
copy()
boolean
equals(Object obj)
byte[]
getAdditionalData()
Returns the additional_data.
String
getHost()
long
getId()
ArrayList
getPhysicalAddresses()
Returns a copy of the list of physical addresses.
SocketAddress
getPrimaryPhysicalAddress()
long
getTimestamp()
int
hashCode()
protected void
init(String host_name, List physical_addrs)
boolean
isMulticastAddress()
void
readExternal(ObjectInput in)
void
readFrom(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(SocketAddress addr)
For internal use only.
void
setAdditionalData(byte[] additional_data)
Sets the additional_data.
void
setPrimaryPhysicalAddress(SocketAddress primary_physical_addr)
int
size()
String
toString()
String
toString(boolean print_details)
void
writeExternal(ObjectOutput out)
void
writeTo(DataOutputStream out)
Write the entire state of the current object (including superclasses) to outstream.

Field Details

count

protected static int count

host

protected String host

id

protected int id

multicast_addr

protected boolean multicast_addr

physical_addrs

protected ArrayList physical_addrs
List of physical addresses

timestamp

protected long timestamp

Constructor Details

LogicalAddress

public LogicalAddress()

LogicalAddress

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

Method Details

addPhysicalAddress

public void addPhysicalAddress(SocketAddress addr)
For internal use only. Don't use this method!
Parameters:
addr -

clone

public Object clone()
            throws CloneNotSupportedException

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(Object o)
implements the java.lang.Comparable interface
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.
See Also:
Comparable

copy

public LogicalAddress copy()

equals

public boolean equals(Object obj)

getAdditionalData

public byte[] getAdditionalData()
Returns the additional_data.
Returns:
byte[]

getHost

public String getHost()

getId

public long getId()

getPhysicalAddresses

public 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)

getPrimaryPhysicalAddress

public SocketAddress getPrimaryPhysicalAddress()

getTimestamp

public long getTimestamp()

hashCode

public int hashCode()

init

protected void init(String host_name,
                    List physical_addrs)

isMulticastAddress

public boolean isMulticastAddress()
Specified by:
isMulticastAddress in interface Address

readExternal

public void readExternal(ObjectInput in)
            throws IOException,
                   ClassNotFoundException

readFrom

public void readFrom(DataInputStream in)
            throws IOException,
                   IllegalAccessException,
                   InstantiationException
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

removeAllPhysicalAddresses

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

removePhysicalAddress

public void removePhysicalAddress(SocketAddress addr)
For internal use only. Don't use this method !
Parameters:
addr -

setAdditionalData

public void setAdditionalData(byte[] additional_data)
Sets the additional_data.
Parameters:
additional_data - The additional_data to set

setPrimaryPhysicalAddress

public void setPrimaryPhysicalAddress(SocketAddress primary_physical_addr)

size

public int size()
Specified by:
size in interface Address

toString

public String toString()

toString

public String toString(boolean print_details)

writeExternal

public void writeExternal(ObjectOutput out)
            throws IOException

writeTo

public void writeTo(DataOutputStream out)
            throws IOException
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

Copyright B) 1998-2005 Bela Ban. All Rights Reserved.