Class 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 Detail

      • 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.
      • 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 Detail

      • 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 Detail

      • 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
      • 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.