Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


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, DescribableAddressProvider, SocketAddressProvider, java.lang.Iterable, java.util.Collection, java.util.Set
Direct Known Subclasses:
ConfigurableLocalAddressProvider

public class ConfigurableAddressProvider
extends java.util.AbstractSet
implements DescribableAddressProvider

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.

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
 boolean m_fResolve
          Specifies if the list of address need DNS resolution.
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  java.util.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 SocketAddressProvider.getNextAddress() method.
protected  void configure(XmlElement xmlConfig)
          Configure this ConfigurableAddressProvider based on the specified XML.
 boolean equals(java.lang.Object o)
          AddressProvider instances should compare to be equals() iff they should be expected to consistently produce the same resulting set of addresses.
 java.lang.String[] getAddressDescriptions()
          Retrieve a human readable description of underlying addresses.
 java.net.InetSocketAddress getNextAddress()
          Covariant of SocketAddressProvider.getNextAddress() which returns an InetSocketAddress.
 int hashCode()
          Return the hash code for this AddressProvider.
 java.util.Iterator iterator()
          Returns an iterator over the elements contained in this collection.
static AddressProvider makeProvider(XmlElement xmlConfig)
          Creates an instances of ConfigurableAddressProvider or RefreshableAddressProvider that refresh the address list of the ConfigurableAddressProvider asynchronously.
 void reject(java.lang.Throwable eCause)
          This method should be called by the client immediately after it determines that an attempt to use an address returned by the SocketAddressProvider.getNextAddress() method has failed.
protected  void reset()
          Make all addresses iterable, starting at the first address.
protected  void reset(int iLast)
          Make all addresses iterable, starting at the index after the specified one.
protected  java.net.InetSocketAddress resolveAddress(java.lang.String sHost, int nPort)
          Resolve an address and port.
 int size()
          Returns the number of elements in this collection.
protected  java.util.List sortHolders(java.util.List list)
          Sort the holders in the order to be returned by the getNextAddress() method.
 java.lang.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 java.util.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.

m_fResolve

public boolean m_fResolve
Specifies if the list of address need DNS resolution.

Constructor Detail

ConfigurableAddressProvider

public ConfigurableAddressProvider(XmlElement xmlConfig)
Construct an instance of ConfigurableAddressProvider based on the specified XML element.

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

makeProvider

public static AddressProvider makeProvider(XmlElement xmlConfig)
Creates an instances of ConfigurableAddressProvider or RefreshableAddressProvider that refresh the address list of the ConfigurableAddressProvider asynchronously.
Parameters:
xmlConfig - the XML element that contains the configuration info
Returns:
an instance of the corresponding AddressProvider implementation

getNextAddress

public java.net.InetSocketAddress getNextAddress()
Covariant of SocketAddressProvider.getNextAddress() which returns an InetSocketAddress.
Specified by:
getNextAddress in interface AddressProvider
Specified by:
getNextAddress in interface SocketAddressProvider
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 SocketAddressProvider.getNextAddress() method.
Specified by:
accept in interface SocketAddressProvider

reject

public void reject(java.lang.Throwable eCause)
This method should be called by the client immediately after it determines that an attempt to use an address returned by the SocketAddressProvider.getNextAddress() method has failed.
Specified by:
reject in interface SocketAddressProvider
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 java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection
Returns:
the number of elements in this collection

iterator

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

reset

protected void reset()
Make all addresses iterable, starting at the first address.

reset

protected void reset(int iLast)
Make all addresses iterable, starting at the index after the specified one.
Parameters:
iLast - the index of the last address returned

configure

protected void configure(XmlElement xmlConfig)
Configure this ConfigurableAddressProvider based on the specified XML.
Parameters:
xmlConfig - the XML element that contains the configuration info

sortHolders

protected java.util.List sortHolders(java.util.List list)
Sort the holders in the order to be returned by the getNextAddress() method. This implementation randomizes the holder list for simple load balancing.
Parameters:
list - the original list retrieved from the configuration
Returns:
the re-ordered list

equals

public boolean equals(java.lang.Object o)
AddressProvider instances should compare to be equals() iff they should be expected to consistently produce the same resulting set of addresses.

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 SocketAddressProvider
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.Set
Overrides:
equals in class java.util.AbstractSet
Parameters:
o - the Object to compare this AddressProvider to for equality
Returns:
true iff this AddressProvider is equal to the specified object

hashCode

public int hashCode()
Return the hash code for this AddressProvider.
Specified by:
hashCode in interface SocketAddressProvider
Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.Set
Overrides:
hashCode in class java.util.AbstractSet
Returns:
the hash code for this AddressProvider

toString

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

getAddressDescriptions

public java.lang.String[] getAddressDescriptions()
Retrieve a human readable description of underlying addresses.
Specified by:
getAddressDescriptions in interface DescribableAddressProvider
Returns:
a string array of addresses in human readable format

resolveAddress

protected java.net.InetSocketAddress resolveAddress(java.lang.String sHost,
                                                    int nPort)
Resolve an address and port.
Parameters:
sHost - the host
nPort - the port
Returns:
the InetSocketAddress

Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


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