Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


com.tangosol.net
Class ConfigurableAddressProvider

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by com.tangosol.net.ConfigurableAddressProvider

All Implemented Interfaces:
AddressProvider, Iterable, Collection, Set

public class ConfigurableAddressProvider
extends AbstractSet
implements AddressProvider

ConfigurableAddressProvider is an implementation of the AddressProvider interface based on a static list of addresses configured in an XML element that contains one or more items in the following format:

 <socket-address>
   <address>...</address>
   <port>...</port>
 </socket-address>
 

The order of items in the configured list will be randomized to provide basic load balancing. <p/> This implementation is not thread safe.

Since:
Coherence 3.4
Author:
gg 2008-08-18

Nested Class Summary
protected  class ConfigurableAddressProvider.AddressHolder
          A stateful holder for an obtaining an InetSocketAddress object.

 

Field Summary
protected  boolean m_fSafe
          Specifies if the provider is only to return resolved addresses.
protected  int m_iLast
          Index of the last returned address.
protected  List m_listHolders
          A list of AddressHolder objects.

 

Constructor Summary
ConfigurableAddressProvider(XmlElement xmlConfig)
          Construct an instance of ConfigurableAddressProvider based on the specified XML element.
ConfigurableAddressProvider(XmlElement xmlConfig, boolean fSafe)
          Construct an instance of ConfigurableAddressProvider based on the specified XML element.

 

Method Summary
 void accept()
          This method should be called by the client immediately after it determines that it can successfully use an address returned by the AddressProvider.getNextAddress() method.
static AddressProvider createAddressProvider(XmlElement xmlConfig, ClassLoader loader)
          Instantiate an AddressProvider configured according to the specified XML.
 boolean equals(Object o)
          AddressProvider instances should compare to be equals() iff they should be expected to consistently produce the same resulting set of addresses.
 InetSocketAddress getNextAddress()
          Obtain a next available address to use.
 int hashCode()
          Return the hash code for this AddressProvider.
 Iterator iterator()
          Returns an iterator over the elements contained in this collection.
 void reject(Throwable eCause)
          This method should be called by the client immediately after it determines that an attempt to use an address returned by the AddressProvider.getNextAddress() method has failed.
protected  void reset()
          Reset the address provider making all previously returned addresses iterable.
 int size()
          Returns the number of elements in this collection.
 String toString()
          Return a string representation of this ConfigurableAddressProvider.

 

Methods inherited from class java.util.AbstractSet
removeAll

 

Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray

 

Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray

 

Field Detail

m_listHolders

protected List m_listHolders
A list of AddressHolder objects.

m_iLast

protected int m_iLast
Index of the last returned address.

m_fSafe

protected boolean m_fSafe
Specifies if the provider is only to return resolved addresses.

Constructor Detail

ConfigurableAddressProvider

public ConfigurableAddressProvider(XmlElement xmlConfig)
Construct an instance of ConfigurableAddressProvider based on the specified XML element. <p/> Unresolveable addresses will be skipped.
Parameters:
xmlConfig - the XML element that contains the configuration info

ConfigurableAddressProvider

public ConfigurableAddressProvider(XmlElement xmlConfig,
                                   boolean fSafe)
Construct an instance of ConfigurableAddressProvider based on the specified XML element.
Parameters:
xmlConfig - the XML element that contains the configuration info
fSafe - true if the provider is skips unresolved addresses

Method Detail

getNextAddress

public InetSocketAddress getNextAddress()
Obtain a next available address to use. If the caller can successfully use the returned address (e.g. a connection was established), it should call the AddressProvider's AddressProvider.accept() method.
Specified by:
getNextAddress in interface AddressProvider
Returns:
the next available address or null if the list of available addresses was exhausted

accept

public void accept()
This method should be called by the client immediately after it determines that it can successfully use an address returned by the AddressProvider.getNextAddress() method.
Specified by:
accept in interface AddressProvider

reject

public void reject(Throwable eCause)
This method should be called by the client immediately after it determines that an attempt to use an address returned by the AddressProvider.getNextAddress() method has failed.
Specified by:
reject in interface AddressProvider
Parameters:
eCause - (optional) an exception that carries the reason why the the caller rejected the previously returned address

size

public int size()
Returns the number of elements in this collection. If the collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Specified by:
size in interface Collection
Specified by:
size in interface Set
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this collection

iterator

public Iterator iterator()
Returns an iterator over the elements contained in this collection.
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface Set
Specified by:
iterator in class AbstractCollection
Returns:
an iterator over the elements contained in this collection

reset

protected void reset()
Reset the address provider making all previously returned addresses iterable.

createAddressProvider

public static AddressProvider createAddressProvider(XmlElement xmlConfig,
                                                    ClassLoader loader)
Instantiate an AddressProvider configured according to the specified XML. The passed XML has to conform to the following format:
   <!ELEMENT ... (socket-address+ | address-provider)>
   <!ELEMENT address-provider
     (class-name | (class-factory-name, method-name), init-params?>
   <!ELEMENT socket-address (address, port)>
 
Parameters:
xmlConfig - the XML element that contains the configuration info
loader - (optional) the ClassLoader that should be used to load necessary classes
Returns:
an instance of the corresponding AddressProvider implementation
See Also:
"remote-addresses" element declaration for the cache-config.dtd in the Coherence library

equals

public boolean equals(Object o)
AddressProvider instances should compare to be equals() iff they should be expected to consistently produce the same resulting set of addresses. <p/> Note: the general contract of hashCode and equals() should be preserved; AddressProviders which compare equals() should have the same hashCode.
Specified by:
equals in interface AddressProvider
Specified by:
equals in interface Collection
Specified by:
equals in interface Set
Overrides:
equals in class AbstractSet
Parameters:
o - the Object to compare this AddressProvider to for equality
Returns:
true iff this AddressProvider is equal to the specified object
See Also:
Object.equals(Object), Set.equals(Object), List.equals(Object)

hashCode

public int hashCode()
Return the hash code for this AddressProvider.
Specified by:
hashCode in interface AddressProvider
Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface Set
Overrides:
hashCode in class AbstractSet
Returns:
the hash code for this AddressProvider
See Also:
Object.hashCode(), Object.equals(Object)

toString

public String toString()
Return a string representation of this ConfigurableAddressProvider.
Overrides:
toString in class AbstractCollection
Returns:
a string representation of the list of configured addresses

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.