public class ConflatingRecoveryPointAdapter extends java.lang.Object implements RecoveryPointAdapter
RecoveryPointAdapter
interface that is meant
to act as a wrapper around another recovery point adapter instance,
delegating periodic updates to its wrapped adapter on an asynchronous
update thread (which this instance starts). The intent is to decouple
recovery state updates from message discards on a bookmark replay
subscriptions so that fast paced subscriptions don't cause a rate of
updates that consume too much bandwidth or overwhelm recovery point
adapter implementations that use slower storage (slowing message
discards).Modifier and Type | Class and Description |
---|---|
protected class |
ConflatingRecoveryPointAdapter.UpdateThread
Internal thread for asynchronously delegating recovery state updates
to the wrapper recovery point adapter.
|
Modifier and Type | Field and Description |
---|---|
protected RecoveryPointAdapter |
_adapter
The wrapped recovery point adapter instance we delegate to.
|
protected boolean |
_closed
Indicates whether this bookmark store has been closed.
|
protected java.util.concurrent.ConcurrentHashMap<Field,java.lang.Long> |
_counts
A concurrent hash map of subscription id's (known to this adapter)
mapped to Long's that count how many updates have occurred for that
subscription.
|
protected java.beans.ExceptionListener |
_exceptionListener
The exception listener for this client and both underlying HAClient
instances.
|
protected java.util.concurrent.ConcurrentHashMap<Field,RecoveryPoint> |
_latestUpdates
A concurrent hash map of subscription id's mapped to the RecoveryPoint
received from the most recent update.
|
protected ConflatingRecoveryPointAdapter.UpdateThread |
_thread
The background worker thread that persists subscription discard state
to the SOW.
|
protected long |
_timeoutMillis
The threshold used to determine if a subscription is due for an update
operation, based upon whether this many milliseconds have elapsed
since the last update operation.
|
protected java.util.concurrent.ConcurrentHashMap<Field,java.lang.Long> |
_timers
A concurrent hash map of subscription id's (known to this adapter)
mapped to Long's that represent the timestamp of when
the subscription's state was last written to the adapter.
|
protected boolean |
_updateAll
Indicates whether all updates should be flushed regardless.
|
protected long |
_updateIntervalMillis
The threshold for idle time between updates when timers should
be checked again.
|
protected long |
_updateThreshold
The threshold used to determine if a subscription is due for an update
operation, based upon whether the subscription's update count exceeds
this threshold since the last update operation.
|
Constructor and Description |
---|
ConflatingRecoveryPointAdapter(RecoveryPointAdapter adapter)
Constructs an instance of the recovery point adapter interface that is
meant to act as a wrapper around another recovery point adapter instance,
delegating periodic updates to its wrapped adapter on an asynchronous
update thread (which this instance starts).
|
ConflatingRecoveryPointAdapter(RecoveryPointAdapter adapter,
long updateThreshold,
long timeoutMillis,
long updateIntervalMillis)
Constructs an instance of the recovery point adapter interface that is
meant to act as a wrapper around another recovery point adapter instance,
delegating periodic updates to its wrapped adapter on an asynchronous
update thread (which this instance starts).
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Force all updates to the underlying adapter, then close it.
|
java.beans.ExceptionListener |
getExceptionListener()
Returns the
ExceptionListener instance used for
communicating absorbed exceptions. |
boolean |
hasNext()
Implements
Iterator.hasNext() . |
java.util.Iterator<RecoveryPoint> |
iterator()
Implements
Iterable.iterator() to return this instance. |
RecoveryPoint |
next()
Implements
Iterator.next() for a message stream. |
void |
purge()
This method is responsible for removing or purging all recovery point
information from the instance(self) and from the wrapped adapter.
|
void |
purge(Field subId)
Remove all recovery point information for subId from self and adapter.
|
void |
remove()
Operation not supported.
|
protected void |
runUpdateAll() |
void |
setExceptionListener(java.beans.ExceptionListener exceptionListener)
Sets the
ExceptionListener instance used for
communicating absorbed exceptions. |
void |
update(RecoveryPoint recoveryPoint)
Conflate an update to the newest recovery point.
|
void |
updateAll()
Force all held updates to be flushed to the underlying adapter.
|
protected RecoveryPointAdapter _adapter
protected final java.util.concurrent.ConcurrentHashMap<Field,java.lang.Long> _counts
protected final java.util.concurrent.ConcurrentHashMap<Field,java.lang.Long> _timers
protected final java.util.concurrent.ConcurrentHashMap<Field,RecoveryPoint> _latestUpdates
protected volatile long _updateThreshold
protected volatile long _timeoutMillis
protected volatile long _updateIntervalMillis
protected ConflatingRecoveryPointAdapter.UpdateThread _thread
protected volatile boolean _closed
protected volatile boolean _updateAll
protected volatile java.beans.ExceptionListener _exceptionListener
public ConflatingRecoveryPointAdapter(RecoveryPointAdapter adapter)
adapter
- The adapter that is sent conflated updates.public ConflatingRecoveryPointAdapter(RecoveryPointAdapter adapter, long updateThreshold, long timeoutMillis, long updateIntervalMillis)
adapter
- The adapter that is sent conflated updates.updateThreshold
- The maximum number of updates to a subId
before a conflated update is delivered.timeoutMillis
- The maximum amount of time in milliseconds
between conflated updates for each subId.updateIntervalMillis
- The maximum amount of time in milliseconds
the update thread can sit idle before checking
for timeouts.public void setExceptionListener(java.beans.ExceptionListener exceptionListener)
ExceptionListener
instance used for
communicating absorbed exceptions.exceptionListener
- The exception listener instance to invoke for
internal exceptions.public java.beans.ExceptionListener getExceptionListener()
ExceptionListener
instance used for
communicating absorbed exceptions.public void update(RecoveryPoint recoveryPoint)
update
in interface RecoveryPointAdapter
recoveryPoint
- The newest recovery point to save.public void purge() throws java.lang.Exception
purge
in interface RecoveryPointAdapter
java.lang.Exception
- Should be thrown for any error deleting recovery
state from the external store.BookmarkStore.purge()
public void purge(Field subId) throws java.lang.Exception
purge
in interface RecoveryPointAdapter
subId
- The subId to remove.java.lang.Exception
- Should be thrown for any error deleting recovery
state from the external store.BookmarkStore.purge(com.crankuptheamps.client.fields.Field)
public void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
public boolean hasNext()
Iterator.hasNext()
. This method is part of an iterator and
checks if there is another element to be iterated over. It delegates the
hasNext() functionality to another object _adapter, which likely represents
an underlying data source or collection. If _adapter says there's a next
element, this method returns true. If there isn't a nest element, it returns
false.hasNext
in interface java.util.Iterator<RecoveryPoint>
public RecoveryPoint next()
Iterator.next()
for a message stream. This is another
iterator method and is used to get the next element in the iteration. Similar
to hasNext(), it delegates the functionality to _adapter, which provides the
next
element. It returns this next element.next
in interface java.util.Iterator<RecoveryPoint>
public void remove()
Iterator.remove()
to throw
UnsupportedOperationException. This method is intended to remove elements
from the underlying data source, but it's not supported. It throws an
UnsupportedOperationException, indicating that the removal operation is not
allowed.remove
in interface java.util.Iterator<RecoveryPoint>
public java.util.Iterator<RecoveryPoint> iterator()
Iterable.iterator()
to return this instance. This method is
used to obtain an iterator for the elements in this class, effectively
allowing you to iterate over its elements. It returns the current instance
(i.e., this) as an iterator.iterator
in interface java.lang.Iterable<RecoveryPoint>
public void updateAll()
protected void runUpdateAll()