Class RefreshableAddressProvider

java.lang.Object
com.tangosol.util.Base
com.tangosol.net.RefreshableAddressProvider
All Implemented Interfaces:
AddressProvider, DescribableAddressProvider, SocketAddressProvider

public class RefreshableAddressProvider extends Base implements DescribableAddressProvider
A RefreshableAddressProvider is an AddressProvider implementation that wraps another AddressProvider and refresh the address list of the provider asynchronously. This ensures that the behaviour of this AddressProvider will be performant (specifically non-blocking).
Since:
Coherence 3.5
Author:
rhl 2008-12-14
  • Field Details

    • REFRESH_DEFAULT

      public static final long REFRESH_DEFAULT
      Default refresh time of 10 seconds.
    • f_lRefresh

      protected final long f_lRefresh
      The interval with which to attempt to refresh the address list.
    • f_daemonRefresh

      protected final Daemon f_daemonRefresh
      The refresh daemon.
    • f_iterator

      protected final RefreshableAddressProvider.CircularIterator f_iterator
      An Iterator over the cached set of addresses.
    • m_listCache

      protected volatile List m_listCache
      The cached addresses.
    • m_ldtLastRefresh

      protected long m_ldtLastRefresh
      The last timestamp when the address list was refreshed.
    • m_apRefresh

      protected AddressProvider m_apRefresh
      The address provider to be refreshed.
  • Constructor Details

    • RefreshableAddressProvider

      public RefreshableAddressProvider(AddressProvider ap)
      Construct a RefreshableAddressProvider with the given AddressProvider using default refresh interval
    • RefreshableAddressProvider

      public RefreshableAddressProvider(AddressProvider ap, long lRefresh)
      Construct a RefreshableAddressProvider with the specified AddressProvider and refresh interval
      Parameters:
      lRefresh - the refresh interval
  • Method Details

    • getNextAddressInternal

      protected InetSocketAddress getNextAddressInternal()
      Obtain the next available address to use.
      Returns:
      the next available address or null if the list of available addresses was exhausted
    • equals

      public boolean equals(Object o)
      SocketAddressProvider instances are considered equivalent iff they consistently produce the same resulting set of addresses.

      Note: the general contract of hashCode and equals() should be preserved; AddressProviders that are "equal" should produce the same hashCode.

      Specified by:
      equals in interface SocketAddressProvider
      Overrides:
      equals in class Object
      Parameters:
      o - the Object to compare this SocketAddressProvider to for equality
      Returns:
      true iff this SocketAddressProvider is equal to the specified object
    • hashCode

      public int hashCode()
      Return the hash code for this SocketAddressProvider.
      Specified by:
      hashCode in interface SocketAddressProvider
      Overrides:
      hashCode in class Object
      Returns:
      the hash code for this SocketAddressProvider
    • getNextAddress

      public final InetSocketAddress getNextAddress()
      Covariant of SocketAddressProvider.getNextAddress() which returns an InetSocketAddress. If the internal iterator used to return addresses is exhausted then a new iterator is initialised and null is returned.
      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 final 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 final 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 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
    • getAddressDescriptions

      public 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
    • refreshAddressList

      protected void refreshAddressList()
      Refresh the cached address list using the underlying provider.
    • ensureRefreshThread

      protected void ensureRefreshThread()
      Start the refresh thread if not already running.