Overview | Package | Class | Tree | Index | Help

Oracle® Coherence Java API Reference
v3.5.3
E15583-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.net
Class RefreshableAddressProvider

    java.lang.Object
      com.tangosol.util.Base
          com.tangosol.net.RefreshableAddressProvider

All Implemented Interfaces:
  AddressProvider

    public abstract class RefreshableAddressProvider

extends Base
implements AddressProvider

A RefreshableAddressProvider is an abstract AddressProvider implementation that maintains a nearly up-to-date cache of Addresses that is periodically asynchronously refreshed. This ensures that the behaviour of this AddressProvider will be performant (specifically non-blocking).

Implementing subclasses should provide implementation logic for deciding how and when the address cache should be refreshed. That logic must reside in `getNextAddressInternal()` instead of `getNextAddress()`.

Note: subclasses must call `initialize()` before the AddressProvider is used.

Since:
  Coherence 3.5
Author:
  rhl 2008-12-14

Nested Class Summary
`protected class` | `RefreshableAddressProvider.RefreshThread`

Field Summary
`protected Daemon` | `m_daemonRefresh` The refresh daemon.
`protected java.util.Iterator` | `m_iterator` The iterator used to implement the AddressProvider interface.
`protected java.util.List` | `m_listCache` The cached addresses.
`static long` | `REFRESH_DEFAULT` Default refresh time of 10 seconds.

Constructor Summary
`RefreshableAddressProvider()` Default constructor.
`RefreshableAddressProvider(long lRefresh)` Construct a RefreshableAddressProvider with the specified refresh interval.

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.
`protected java.util.Iterator` | `ensureIterator()` Return the cache iterator.
`boolean` | `equals(java.lang.Object o)` AddressProvider instances are considered equivalent iff they consistently produce the same resulting set of addresses.
`protected void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`java.net.InetSocketAddress` | `getNextAddress()` Obtain a next available address to use.
`protected abstract java.net.InetSocketAddress` | `getNextAddressInternal()` Obtain the next available address to use.
`int` | `hashCode()` Return the hash code for this AddressProvider.
`protected void` | `initialize()` Initialize the RefreshableAddressProvider and prepare it for use by populating the address-list cache and starting the refresh thread.
`protected void` | `instantiateRefreshThread(long lRefresh)` Start the refresh thread.
`protected abstract boolean` | `isExpired()` Check if the cached address list should be refreshed.
`protected void` | `refreshAddressList()` Refresh the cached address list using the underlying provider.
`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 `AddressProvider.getNextAddress()` method has failed.

Field Detail

### REFRESH_DEFAULT

    public static final long REFRESH_DEFAULT

  Default refresh time of 10 seconds.

  See Also:
    Constant Field Values

### m_listCache

    protected volatile java.util.List m_listCache

  The cached addresses.

### m_iterator

    protected java.util.Iterator m_iterator

  The iterator used to implement the AddressProvider interface.

### m_daemonRefresh

    protected Daemon m_daemonRefresh

  The refresh daemon.

Constructor Detail

### RefreshableAddressProvider

    public RefreshableAddressProvider()

  Default constructor.

### RefreshableAddressProvider

    public RefreshableAddressProvider(long lRefresh)

  Construct a RefreshableAddressProvider with the specified refresh interval.

  Parameters:
    `lRefresh` - the refresh interval

Method Detail

### initialize

    protected void initialize()

  Initialize the RefreshableAddressProvider and prepare it for use by populating the address-list cache and starting the refresh thread.

### getNextAddressInternal

    protected abstract java.net.InetSocketAddress getNextAddressInternal()

  Obtain the next available address to use.

  Returns:
    the next available address or null if the list of available addresses was exhausted

### isExpired

    protected abstract boolean isExpired()

  Check if the cached address list should be refreshed. This method may be called frequently.

  Returns:
    true iff the cached address list should be refreshed

### equals

    public boolean equals(java.lang.Object o)

  AddressProvider 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 `AddressProvider`
  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 `AddressProvider`
  Returns:
    the hash code for this AddressProvider

### finalize

    protected void finalize()

  Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

### getNextAddress

    public final java.net.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 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 `AddressProvider.getNextAddress()` method.

  Specified by:
    `accept` in interface `AddressProvider`

### reject

    public final 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 `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

### refreshAddressList

    protected void refreshAddressList()

  Refresh the cached address list using the underlying provider.

### instantiateRefreshThread

    protected void instantiateRefreshThread(long lRefresh)

  Start the refresh thread.

### ensureIterator

    protected java.util.Iterator ensureIterator()

  Return the cache iterator.

  Returns:
    the cache iterator

Overview | Package | Class | Tree | Index | Help

Oracle® Coherence Java API Reference
v3.5.3
E15583-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2010, Oracle. All rights reserved.