Package com.tangosol.net
Class ConfigurableAddressProvider
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet
-
- com.tangosol.net.ConfigurableAddressProvider
-
- All Implemented Interfaces:
AddressProvider,DescribableAddressProvider,SocketAddressProvider,Iterable,Collection,Set
- Direct Known Subclasses:
ConfigurableLocalAddressProvider
public class ConfigurableAddressProvider extends 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> ... <address>...</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
Nested Classes Modifier and Type Class Description static classConfigurableAddressProvider.AddressHolderA stateful holder for an obtaining an InetSocketAddress object.
-
Field Summary
Fields Modifier and Type Field Description booleanm_fResolveDeprecated.protected booleanm_fSafeSpecifies if the provider is only to return resolved addresses.protected intm_iLastIndex of the last returned address.protected Iterator<InetSocketAddress>m_iterAddrAn address iterator for the previously resolved address.protected List<ConfigurableAddressProvider.AddressHolder>m_listHoldersA read-only list of ProvidedAddress objects.
-
Constructor Summary
Constructors Constructor Description ConfigurableAddressProvider(XmlElement xmlConfig)Deprecated.ConfigurableAddressProvider(XmlElement xmlConfig, boolean fSafe)Deprecated.ConfigurableAddressProvider(Iterable<ConfigurableAddressProvider.AddressHolder> addressHolders, boolean fSafe)Constructs aConfigurableAddressProviderusing the specifiedConfigurableAddressProvider.AddressHolders.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept()This method should be called by the client immediately after it determines that it can successfully use an address returned by theSocketAddressProvider.getNextAddress()method.protected voidconfigure(XmlElement xmlConfig)Deprecated.booleanequals(Object o)AddressProvider instances should compare to be equals() iff they should be expected to consistently produce the same resulting set of addresses.String[]getAddressDescriptions()Retrieve a human readable description of underlying addresses.InetSocketAddressgetNextAddress()Covariant ofSocketAddressProvider.getNextAddress()which returns anInetSocketAddress.inthashCode()Return the hash code for this AddressProvider.Iteratoriterator()Returns an iterator over the elements contained in this collection.static AddressProvidermakeProvider(XmlElement xmlConfig)Deprecated.voidreject(Throwable eCause)This method should be called by the client immediately after it determines that an attempt to use an address returned by theSocketAddressProvider.getNextAddress()method has failed.protected voidreset()Make all addresses iterable, starting at the first address.protected voidreset(int iLast)Make all addresses iterable, starting at the index after the specified one.protected Iterator<InetSocketAddress>resolveAddress(String sHost, int nPort)Resolve an address and port.intsize()Returns the number of elements in this collection.protected ListsortHolders(List list)Sort the holders in the order to be returned by thegetNextAddress()method.StringtoString()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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Field Detail
-
m_listHolders
protected List<ConfigurableAddressProvider.AddressHolder> m_listHolders
A read-only list of ProvidedAddress objects.
-
m_iterAddr
protected Iterator<InetSocketAddress> m_iterAddr
An address iterator for the previously resolved address.
-
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
@Deprecated public boolean m_fResolve
Deprecated.Specifies if the list of address need DNS resolution.
-
-
Constructor Detail
-
ConfigurableAddressProvider
@Deprecated public ConfigurableAddressProvider(XmlElement xmlConfig)
Deprecated.Construct an instance of ConfigurableAddressProvider based on the specified XML element.Unresolvable addresses will be skipped.
- Parameters:
xmlConfig- the XML element that contains the configuration info
-
ConfigurableAddressProvider
public ConfigurableAddressProvider(Iterable<ConfigurableAddressProvider.AddressHolder> addressHolders, boolean fSafe)
Constructs aConfigurableAddressProviderusing the specifiedConfigurableAddressProvider.AddressHolders.- Parameters:
addressHolders- theConfigurableAddressProvider.AddressHoldersfSafe- true if the provider skips unresolved addresses
-
ConfigurableAddressProvider
@Deprecated public ConfigurableAddressProvider(XmlElement xmlConfig, boolean fSafe)
Deprecated.Construct an instance of ConfigurableAddressProvider based on the specified XML element.- Parameters:
xmlConfig- the XML element that contains the configuration infofSafe- true if the provider skips unresolved addresses
-
-
Method Detail
-
makeProvider
@Deprecated public static AddressProvider makeProvider(XmlElement xmlConfig)
Deprecated.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 InetSocketAddress getNextAddress()
Covariant ofSocketAddressProvider.getNextAddress()which returns anInetSocketAddress.- Specified by:
getNextAddressin interfaceAddressProvider- Specified by:
getNextAddressin interfaceSocketAddressProvider- 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 theSocketAddressProvider.getNextAddress()method.- Specified by:
acceptin interfaceSocketAddressProvider
-
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 theSocketAddressProvider.getNextAddress()method has failed.- Specified by:
rejectin interfaceSocketAddressProvider- 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:
sizein interfaceCollection- Specified by:
sizein interfaceSet- Specified by:
sizein classAbstractCollection- Returns:
- the number of elements in this collection
-
iterator
public Iterator iterator()
Returns an iterator over the elements contained in this collection.- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceSet- Specified by:
iteratorin classAbstractCollection- 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
@Deprecated protected void configure(XmlElement xmlConfig)
Deprecated.Configure this ConfigurableAddressProvider based on the specified XML.- Parameters:
xmlConfig- the XML element that contains the configuration info
-
sortHolders
protected List sortHolders(List list)
Sort the holders in the order to be returned by thegetNextAddress()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(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:
equalsin interfaceCollection- Specified by:
equalsin interfaceSet- Specified by:
equalsin interfaceSocketAddressProvider- Overrides:
equalsin classAbstractSet- 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:
hashCodein interfaceCollection- Specified by:
hashCodein interfaceSet- Specified by:
hashCodein interfaceSocketAddressProvider- Overrides:
hashCodein classAbstractSet- Returns:
- the hash code for this AddressProvider
-
toString
public String toString()
Return a string representation of this ConfigurableAddressProvider.- Overrides:
toStringin classAbstractCollection- Returns:
- a string representation of the list of configured addresses
-
getAddressDescriptions
public String[] getAddressDescriptions()
Retrieve a human readable description of underlying addresses.- Specified by:
getAddressDescriptionsin interfaceDescribableAddressProvider- Returns:
- a string array of addresses in human readable format
-
resolveAddress
protected Iterator<InetSocketAddress> resolveAddress(String sHost, int nPort)
Resolve an address and port.- Parameters:
sHost- the hostnPort- the port- Returns:
- the InetSocketAddress
-
-