Package com.tangosol.net
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classRefreshableAddressProvider.CircularIteratorAn Iterator implementation that can be converted intocircular modeto allow the remaining addresses and previously skipped addresses to be used; typically set once an address has beenaccepted.protected classRefreshableAddressProvider.RefreshThread-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected Daemonf_daemonRefreshThe refresh daemon.protected RefreshableAddressProvider.CircularIteratorf_iteratorAn Iterator over the cached set of addresses.protected longf_lRefreshThe interval with which to attempt to refresh the address list.protected AddressProviderm_apRefreshThe address provider to be refreshed.protected longm_ldtLastRefreshThe last timestamp when the address list was refreshed.protected Listm_listCacheThe cached addresses.static longREFRESH_DEFAULTDefault refresh time of 10 seconds.
-
Constructor Summary
Constructors Constructor Description RefreshableAddressProvider(AddressProvider ap)Construct a RefreshableAddressProvider with the given AddressProvider using default refresh intervalRefreshableAddressProvider(AddressProvider ap, long lRefresh)Construct a RefreshableAddressProvider with the specified AddressProvider and refresh interval
-
Method Summary
All Methods Instance Methods Concrete 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 voidensureRefreshThread()Start the refresh thread if not already running.booleanequals(Object o)SocketAddressProvider instances are considered equivalent iff they 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.protected InetSocketAddressgetNextAddressInternal()Obtain the next available address to use.inthashCode()Return the hash code for this SocketAddressProvider.protected voidrefreshAddressList()Refresh the cached address list using the underlying provider.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.-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, newHashMap, newHashMap, newHashSet, newHashSet, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
-
-
-
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.
-
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 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:
equalsin interfaceSocketAddressProvider- Overrides:
equalsin classObject- 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:
hashCodein interfaceSocketAddressProvider- Overrides:
hashCodein classObject- Returns:
- the hash code for this SocketAddressProvider
-
getNextAddress
public final InetSocketAddress getNextAddress()
Covariant ofSocketAddressProvider.getNextAddress()which returns anInetSocketAddress. If the internal iterator used to return addresses is exhausted then a new iterator is initialised and null is returned.- 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 final 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 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 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
-
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
-
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.
-
-