jgroup.relacs.config
Class DomainSet

java.lang.Object
  extended by jgroup.relacs.config.DomainSet
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Domain>

public final class DomainSet
extends java.lang.Object
implements java.lang.Iterable<Domain>, java.io.Serializable

Collection class for storing information about a set of domains.

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

Field Summary
static java.util.Comparator<Domain> domainComparator
          Comparator to be provided to domain sets in order to order domains correctly, ignoring the number of replicas in each domain.
 
Constructor Summary
DomainSet()
          Constructs an empty DomainSet.
DomainSet(java.util.Comparator<Domain> comparator)
          Constructs an empty DomainSet whose iteration order is defined by the given comparator.
DomainSet(DomainSet domains, java.util.Comparator<Domain> comparator)
          Constructs a new DomainSet containg the given domain set, whose iteration order is defined by the given comparator.
 
Method Summary
 boolean addDomain(Domain domain)
          Add a new domain to this DomainSet.
 boolean addDomain(java.lang.String domainName, java.lang.String mcastAdr, int port, int jdaemons)
          Add a new domain to this DomainSet.
 void addListener(DomainListener listener)
           
 boolean contains(java.net.InetAddress inetAdr)
          Returns true if this domain set contains the given InetAddress.
 boolean containsDomain(Domain domain)
          Check if the specified domain is in this DomainSet.
 Domain first()
          Returns the first Domain in the domain set; the domain returned is the one with the lowest replica count.
 Domain getDomain(Domain theDomain)
          Returns the Domain object stored in this domain set corresponding to the provided domain.
 Domain getDomain(java.net.InetAddress mcastAdr)
          Returns the Domain object stored in this domain set corresponding to the provided multicast InetAddress.
 Domain getHostDomain(java.net.InetAddress hostAdr)
          Returns the Domain object stored in this domain set corresponding to the provided host InetAddress.
 Domain getLargestDomain()
          Returns the domain that contains the largest number of hosts.
static Domain getLargestReplicaDomain(MemberId[] members)
          Given a set of members, return the Domain that contains the most members.
 int hashCode()
           
 boolean isEmpty()
          Returns true if this DomainSet is empty.
 java.util.Iterator<Domain> iterator()
          Returns an iterator over the values of the DomainSet.
 boolean removeDomain(Domain domain)
          Remove the specified domain from this DomainSet.
 void setComparator(java.util.Comparator<Domain> comparator)
           
 int size()
          Returns the number of domains stored in this DomainSet.
 Domain[] toArray()
          Returns an array of domain objects, in sorted order.
 java.lang.String toString()
          Returns a string representation of this object
 java.lang.String toString(boolean full)
          Returns a string representation of this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

domainComparator

public static final java.util.Comparator<Domain> domainComparator
Comparator to be provided to domain sets in order to order domains correctly, ignoring the number of replicas in each domain. That is override the default ordering for domain sets which is based on the number of replicas in each domain.

Constructor Detail

DomainSet

public DomainSet()
Constructs an empty DomainSet.


DomainSet

public DomainSet(java.util.Comparator<Domain> comparator)
Constructs an empty DomainSet whose iteration order is defined by the given comparator.

Parameters:
comparator -

DomainSet

public DomainSet(DomainSet domains,
                 java.util.Comparator<Domain> comparator)
Constructs a new DomainSet containg the given domain set, whose iteration order is defined by the given comparator.

Parameters:
domains -
comparator -
Method Detail

addListener

public void addListener(DomainListener listener)

addDomain

public boolean addDomain(java.lang.String domainName,
                         java.lang.String mcastAdr,
                         int port,
                         int jdaemons)
                  throws java.net.UnknownHostException
Add a new domain to this DomainSet.

Parameters:
domainName - The domain name.
mcastAdr - The multicast address for this domain.
port - The multicast port for this domain.
jdaemons - The number of Jgroup daemons that should exist in the new domain.
Returns:
True if the DomainSet did not already contain this domain.
Throws:
java.net.UnknownHostException - Is raised if the multicast address is not recognized.

addDomain

public boolean addDomain(Domain domain)
Add a new domain to this DomainSet.

Parameters:
domain - A domain object.
Returns:
True if the DomainSet did not already contain this domain.

removeDomain

public boolean removeDomain(Domain domain)
Remove the specified domain from this DomainSet.

Parameters:
domain - A domain object.
Returns:
True if the specified domain was removed from this DomainSet; false otherwise.

containsDomain

public boolean containsDomain(Domain domain)
Check if the specified domain is in this DomainSet.

Parameters:
domain - A domain object.
Returns:
True if the specified domain is in this DomainSet; false otherwise.

contains

public boolean contains(java.net.InetAddress inetAdr)
Returns true if this domain set contains the given InetAddress.

Parameters:
inetAdr -
Returns:

getDomain

public Domain getDomain(Domain theDomain)
Returns the Domain object stored in this domain set corresponding to the provided domain. If no domain matching the provided domain is available in this domain set, null is returned.


getDomain

public Domain getDomain(java.net.InetAddress mcastAdr)
Returns the Domain object stored in this domain set corresponding to the provided multicast InetAddress. If no domain matching the provided domain is available in this domain set, null is returned.

Throws:
java.lang.IllegalArgumentException - if the provided InetAddress is not a multicast address.

getHostDomain

public Domain getHostDomain(java.net.InetAddress hostAdr)
Returns the Domain object stored in this domain set corresponding to the provided host InetAddress. If no domain contains the provided host address in this domain set, null is returned.

Parameters:
hostAdr - the host address whose domain object to return.
Returns:
the domain in which the given host resides.
Throws:
java.lang.IllegalArgumentException - if the provided InetAddress is a multicast address instead of a regular host address.

setComparator

public void setComparator(java.util.Comparator<Domain> comparator)
Parameters:
comparator - The comparator to set.

size

public int size()
Returns the number of domains stored in this DomainSet.


isEmpty

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


iterator

public java.util.Iterator<Domain> iterator()
Returns an iterator over the values of the DomainSet. The values returned by the next method call of the iterator should be cast to Domain. This iterator returns the sorted order of the domains in this set.

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

toArray

public Domain[] toArray()
Returns an array of domain objects, in sorted order.

Returns:

first

public Domain first()
Returns the first Domain in the domain set; the domain returned is the one with the lowest replica count.

Returns:
The Domain object found.
Throws:
java.util.NoSuchElementException - Raised if there are no domains in this DomainSet.

getLargestDomain

public Domain getLargestDomain()
Returns the domain that contains the largest number of hosts.


getLargestReplicaDomain

public static Domain getLargestReplicaDomain(MemberId[] members)
Given a set of members, return the Domain that contains the most members. It is not specified which domain is returned when more than one domain contains an equal number of members.

Parameters:
members - The members from which to find the domain.
Returns:
The domain with the largest number of members amongst the provided set.

hashCode

public int hashCode()
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

toString

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



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