jgroup.relacs.config
Class HostSet

java.lang.Object
  extended by jgroup.relacs.config.HostSet
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Host>

public final class HostSet
extends java.lang.Object
implements java.lang.Cloneable, java.io.Externalizable, java.lang.Iterable<Host>

Collection class for storing information about a set of hosts.

Since:
Jgroup 1.2
Author:
Hein Meling
See Also:
Serialized Form

Constructor Summary
HostSet()
          Constructs an empty HostSet with default capacity and load factor.
HostSet(int maxEntries)
          Constructs an empty HostSet with default load factor, with space for maxEntries elements.
HostSet(int maxEntries, float loadFactor)
          Constructs an empty HostSet with space for maxEntries elements, using the specified load factor.
 
Method Summary
 boolean addHost(Host host)
          Add a new host to this HostSet.
 boolean addHost(int hostIntAdr)
          Add the given host to the this host set.
 boolean addHost(java.lang.String hostName, Domain domain, int port)
          Add a new host to this HostSet.
 void addHostListener(HostListener listener)
           
 void addHosts(HostSet hostSet)
          Add all hosts in the given HostSet to this HostSet.
 java.lang.Object clone()
          Returns a shallow copy of this HostSet instance.
 boolean containsAll(HostSet hostSet)
          Check if the given host set is fully contained in this HostSet.
 boolean containsHost(Host host)
          Check if the host is in this HostSet.
 boolean containsHost(java.net.InetAddress inetAddress)
          Check if the host represented by the given InetAddress is in this HostSet.
 boolean equals(java.lang.Object o)
           
 HostSet getAvailHosts()
          Returns the set of hosts that are considered available; i.e.
 Host getFirst()
          Returns the first Host returned by the iterators next method.
 Host getHost(java.net.InetAddress inetAddress)
          Returns the Host object associated with the specified InetAddress.
 Host getHost(MemberId member)
          Returns the Host object associated with the specified MemberId.
 int hashCode()
          Return a hash code for this host set.
 boolean isEmpty()
          Returns true if this HostSet is empty.
 java.util.Iterator<Host> iterator()
          Returns an iterator over the values of the HostSet.
 void readExternal(java.io.ObjectInput in)
           
 void removeAllHosts()
          Remove all hosts in this HostSet.
 Host removeFirst()
          Removes the first Host returned by the iterators next method.
 boolean removeHost(Host host)
          Remove a host from this HostSet.
 boolean removeHost(MemberId member)
          Remove a host (member) from this HostSet.
 void removeHosts(HostSet hostSet)
          Remove all hosts in the given HostSet from this HostSet.
 int size()
          Returns the number of hosts stored in this HostSet.
 Host[] toArray()
           
 int[] toIntArray()
          Returns an int[] array representing the content of this HostSet.
 java.lang.String toString()
          Returns a string representation of this object
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HostSet

public HostSet()
Constructs an empty HostSet with default capacity and load factor. Also the default constructor for externalization.


HostSet

public HostSet(int maxEntries)
Constructs an empty HostSet with default load factor, with space for maxEntries elements.


HostSet

public HostSet(int maxEntries,
               float loadFactor)
Constructs an empty HostSet with space for maxEntries elements, using the specified load factor.

Method Detail

addHostListener

public void addHostListener(HostListener listener)

getHost

public Host getHost(java.net.InetAddress inetAddress)
Returns the Host object associated with the specified InetAddress.

Parameters:
inetAddress - The InetAddress of the Host object to get.
Returns:
The Host object associated with the given InetAddress. null is returned if the given IP address host is not in this host set.

getHost

public Host getHost(MemberId member)
Returns the Host object associated with the specified MemberId.

Parameters:
member - The MemberId of the Host object to get.
Returns:
The Host object associated with the given MemberId. null is returned if the given member host is not in this host set.

addHost

public boolean addHost(java.lang.String hostName,
                       Domain domain,
                       int port)
                throws java.net.UnknownHostException
Add a new host to this HostSet.

Parameters:
hostName - The host name.
domain - The Domain associated with this host.
port - The port number for this host.
Returns:
True if the HostSet did not already contain this host.
Throws:
java.net.UnknownHostException - Is raised if the host was not recognized.

addHost

public boolean addHost(Host host)
Add a new host to this HostSet.

Parameters:
host - A host object.
Returns:
True if the HostSet did not already contain this host.

addHost

public boolean addHost(int hostIntAdr)
                throws java.net.UnknownHostException
Add the given host to the this host set. The given host is represented as an integer, and must already exist as a Host object in the DistributedSystemConfig object.

Parameters:
hostIntAdr - An int representation of the host to add to this host set.
Returns:
True if the HostSet did not already contain this host.
Throws:
java.net.UnknownHostException - If the int representation of the host does not correspond to a valid host address, or if it could not be found.

addHosts

public void addHosts(HostSet hostSet)
Add all hosts in the given HostSet to this HostSet.

Parameters:
hostSet - The set of hosts to add to this host set.

removeHost

public boolean removeHost(MemberId member)
Remove a host (member) from this HostSet.

Parameters:
member - A member object representing a host object.
Returns:
True if the Host was removed from the HostSet, that is if it was present in the HostSet; false otherwise.

removeHost

public boolean removeHost(Host host)
Remove a host from this HostSet.

Parameters:
host - A host object.
Returns:
True if the Host was removed from the HostSet, that is if it was present in the HostSet; false otherwise.

removeHosts

public void removeHosts(HostSet hostSet)
Remove all hosts in the given HostSet from this HostSet.

Parameters:
hostSet - The set of hosts to remove from this host set.

removeAllHosts

public void removeAllHosts()
Remove all hosts in this HostSet.


containsAll

public boolean containsAll(HostSet hostSet)
Check if the given host set is fully contained in this HostSet.

Parameters:
hostSet - A host set.
Returns:
True if the given HostSet is contained in this host set.

containsHost

public boolean containsHost(Host host)
Check if the host is in this HostSet.

Parameters:
host - A host object.
Returns:
True if the HostSet contained the specified host.

containsHost

public boolean containsHost(java.net.InetAddress inetAddress)
Check if the host represented by the given InetAddress is in this HostSet.

Parameters:
inetAddress - The InetAddress representation of the host to test for presence in the HostSet.
Returns:
True if the HostSet contained the specified host.

size

public int size()
Returns the number of hosts stored in this HostSet.


isEmpty

public boolean isEmpty()
Returns true if this HostSet is empty.


iterator

public java.util.Iterator<Host> iterator()
Returns an iterator over the values of the HostSet. The values returned by the next method call of the iterator should be cast to Host.

Specified by:
iterator in interface java.lang.Iterable<Host>
Returns:
An Iterator for the HostSet.

getAvailHosts

public HostSet getAvailHosts()
Returns the set of hosts that are considered available; i.e. running an ExecService instance.


toArray

public Host[] toArray()

toIntArray

public int[] toIntArray()
Returns an int[] array representing the content of this HostSet.


getFirst

public Host getFirst()
Returns the first Host returned by the iterators next method. There is no guarantees that this method returns the same host for multiple invocations, nor does it promise to return a different host on the next invocation. This method is useful to obtain just one host in the HostSet, when it does not matter which host to get.

Returns:
The Host object found.
Throws:
java.util.NoSuchElementException - Raised if there are no hosts in this HostSet.

removeFirst

public Host removeFirst()
Removes the first Host returned by the iterators next method. There is no guarantees that this method returns the same host for multiple invocations. This method is useful to obtain just one host in the HostSet, when it does not matter which host to get.

Returns:
The Host object found.
Throws:
java.util.NoSuchElementException - Raised if there are no hosts in this HostSet.

clone

public java.lang.Object clone()
Returns a shallow copy of this HostSet instance. (The elements themselves are not copied.)

Overrides:
clone in class java.lang.Object
Returns:
a clone of this HostSet instance.

equals

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

hashCode

public int hashCode()
Return a hash code for this host set.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of this object

Overrides:
toString in class java.lang.Object

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


Copyright © 1998-2006 The Jgroup/ARM development team. All Rights Reserved.