Package com.tangosol.net
Class RefreshableAddressProvider
java.lang.Object
com.tangosol.util.Base
com.tangosol.net.RefreshableAddressProvider
- All Implemented Interfaces:
AddressProvider
,DescribableAddressProvider
,SocketAddressProvider
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
Modifier and TypeClassDescriptionprotected class
An Iterator implementation that can be converted intocircular mode
to allow the remaining addresses and previously skipped addresses to be used; typically set once an address has beenaccepted
.protected class
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Daemon
The refresh daemon.protected final RefreshableAddressProvider.CircularIterator
An Iterator over the cached set of addresses.protected final long
The interval with which to attempt to refresh the address list.protected AddressProvider
The address provider to be refreshed.protected long
The last timestamp when the address list was refreshed.protected List
The cached addresses.static final long
Default refresh time of 10 seconds. -
Constructor Summary
ConstructorDescriptionConstruct 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
Modifier and TypeMethodDescriptionfinal 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.protected void
Start the refresh thread if not already running.boolean
SocketAddressProvider instances are considered equivalent iff they consistently produce the same resulting set of addresses.String[]
Retrieve a human readable description of underlying addresses.final InetSocketAddress
Covariant ofSocketAddressProvider.getNextAddress()
which returns anInetSocketAddress
.protected InetSocketAddress
Obtain the next available address to use.int
hashCode()
Return the hash code for this SocketAddressProvider.protected void
Refresh the cached address list using the underlying provider.final void
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, 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 Details
-
REFRESH_DEFAULT
public static final long REFRESH_DEFAULTDefault refresh time of 10 seconds. -
f_lRefresh
protected final long f_lRefreshThe interval with which to attempt to refresh the address list. -
f_daemonRefresh
The refresh daemon. -
f_iterator
An Iterator over the cached set of addresses. -
m_listCache
The cached addresses. -
m_ldtLastRefresh
protected long m_ldtLastRefreshThe last timestamp when the address list was refreshed. -
m_apRefresh
The address provider to be refreshed.
-
-
Constructor Details
-
RefreshableAddressProvider
Construct a RefreshableAddressProvider with the given AddressProvider using default refresh interval -
RefreshableAddressProvider
Construct a RefreshableAddressProvider with the specified AddressProvider and refresh interval- Parameters:
lRefresh
- the refresh interval
-
-
Method Details
-
getNextAddressInternal
Obtain the next available address to use.- Returns:
- the next available address or null if the list of available addresses was exhausted
-
equals
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 interfaceSocketAddressProvider
- Overrides:
equals
in 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:
hashCode
in interfaceSocketAddressProvider
- Overrides:
hashCode
in classObject
- Returns:
- the hash code for this SocketAddressProvider
-
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:
getNextAddress
in interfaceAddressProvider
- Specified by:
getNextAddress
in 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:
accept
in interfaceSocketAddressProvider
-
reject
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:
reject
in interfaceSocketAddressProvider
- Parameters:
eCause
- (optional) an exception that carries the reason why the the caller rejected the previously returned address
-
getAddressDescriptions
Retrieve a human readable description of underlying addresses.- Specified by:
getAddressDescriptions
in 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.
-