Package com.illumon.iris.db.v2
Class SwapListenerBase<T extends ListenerBase>
java.lang.Object
com.illumon.util.referencecounting.ReferenceCounted
com.illumon.iris.db.util.liveness.LivenessArtifact
com.illumon.iris.db.v2.SwapListenerBase<T>
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,LivenessManager
,LivenessNode
,LivenessReferent
,ListenerBase
,Serializable
- Direct Known Subclasses:
ShiftAwareSwapListener
,SwapListener
public abstract class SwapListenerBase<T extends ListenerBase> extends LivenessArtifact implements ListenerBase
Watch for ticks and when initialization is complete forward to the eventual listener.
The SwapListenerBase is attached to a table so that we can listen for updates during the LTM cycle; and if any updates
occur, we'll be able to notice them and retry initialization. If no ticks were received before the result is ready,
then we should forward all calls to our eventual listener.
Callers should use our start and end functions. The start function is called at the beginning of a data snapshot;
and allows us to setup our state variables. At the end of the snapshot attempt, end() is called; and if there were
no clock changes, we were not gotNotification, and no notifications were enqueued; then we have a successful snapshot and
can return true. We then set the currentListener, so that all future calls are forwarded to the listener.
Use either
SwapListener
or ShiftAwareSwapListener
depending on which Listener interface you are using.- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
DEBUG
-
Constructor Summary
Constructors Constructor Description SwapListenerBase(com.fishlib.io.logger.Logger log, BaseTable sourceTable)
-
Method Summary
Modifier and Type Method Description protected void
destroy()
Attempt to release (destructively when necessary) resources held by this object.void
dropReference()
Drop a previously-retained reference to this referent.protected boolean
end(long clockCycle)
Ends a snapshot.NotificationQueue.Notification
getErrorNotification(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)
Creates a notification for the exception.WeakReference<? extends LivenessReferent>
getWeakReference()
Get aWeakReference
to this referent.void
initializeTransientFieldsForLiveness()
Package-private forSerializable
sub-classes to use inreadObject
only.ConstructSnapshot.SnapshotControl
makeSnapshotControl()
void
onFailure(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)
Notification of exceptions.protected void
onReferenceCountAtZero()
Callback method that will be invoked when the reference count returns to zero.void
setListenerAndResult(T listener, NotificationStepReceiver resultTable)
Set the listener that will eventually become the listener, if we have a successful swap.protected boolean
start(long clockCycle)
Starts a snapshot.abstract void
subscribeForUpdates()
InvokeDynamicTable.listenForUpdates(Listener)
for the appropriate subclass ofSwapListenerBase
.boolean
tryManage(LivenessReferent referent)
Attempt to add the specified referent to this manager.boolean
tryRetainReference()
If this referent is "live", behave asLivenessReferent.retainReference()
and return true.Methods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanage
Methods inherited from class com.illumon.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.util.liveness.LivenessManager
manage, tryManage
Methods inherited from interface com.illumon.iris.db.util.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReference
-
Field Details
-
DEBUG
protected static final boolean DEBUG
-
-
Constructor Details
-
Method Details
-
makeSnapshotControl
-
start
protected boolean start(long clockCycle)Starts a snapshot.- Parameters:
clockCycle
- the clockCycle we are starting a snapshot on- Returns:
- true if we should use previous values, false if we should use current values.
-
end
protected boolean end(long clockCycle)Ends a snapshot.- Parameters:
clockCycle
- Thelogical clock
cycle we are ending a snapshot on- Returns:
- true if the snapshot was successful, false if we should try again.
- Throws:
IllegalStateException
- If the snapshot was successful (consistent), but the snapshot function failed to set the eventual listener or eventual result
-
onFailure
Description copied from interface:ListenerBase
Notification of exceptions.- Specified by:
onFailure
in interfaceListenerBase
- Parameters:
originalException
- exceptionsourceEntry
- performance tracking
-
getErrorNotification
public NotificationQueue.Notification getErrorNotification(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)Description copied from interface:ListenerBase
Creates a notification for the exception.- Specified by:
getErrorNotification
in interfaceListenerBase
- Parameters:
originalException
- exceptionsourceEntry
- performance tracking- Returns:
- exception notification
-
setListenerAndResult
public void setListenerAndResult(@NotNull T listener, @NotNull NotificationStepReceiver resultTable)Set the listener that will eventually become the listener, if we have a successful swap.- Parameters:
listener
- The listener that we will eventually forward all updates toresultTable
- The table that will result from this operation
-
subscribeForUpdates
public abstract void subscribeForUpdates()InvokeDynamicTable.listenForUpdates(Listener)
for the appropriate subclass ofSwapListenerBase
. -
initializeTransientFieldsForLiveness
Package-private forSerializable
sub-classes to use inreadObject
only. Public to allow unit tests in another package to work around mock issues where the constructor is never invoked. -
tryRetainReference
public final boolean tryRetainReference()Description copied from interface:LivenessReferent
If this referent is "live", behave asLivenessReferent.retainReference()
and return true. Otherwise, returns false rather than throwing an exception.- Specified by:
tryRetainReference
in interfaceLivenessReferent
- Returns:
- True if this referent was retained, false otherwise
-
dropReference
public final void dropReference()Description copied from interface:LivenessReferent
Drop a previously-retained reference to this referent.- Specified by:
dropReference
in interfaceLivenessReferent
-
getWeakReference
Description copied from interface:LivenessReferent
Get aWeakReference
to this referent. This may be cached, or newly created.- Specified by:
getWeakReference
in interfaceLivenessReferent
- Returns:
- A new or cached reference to this referent
-
tryManage
Description copied from interface:LivenessManager
Attempt to add the specified referent to this manager.- Specified by:
tryManage
in interfaceLivenessManager
- Parameters:
referent
- The referent to add- Returns:
- Whether the referent was in fact added
-
destroy
protected void destroy()Attempt to release (destructively when necessary) resources held by this object. This may render the object unusable for subsequent operations. Implementations should be sure to call super.destroy().
This is intended to only ever be used as a side effect of decreasing the reference count to 0.
-
onReferenceCountAtZero
protected final void onReferenceCountAtZero()Description copied from class:ReferenceCounted
Callback method that will be invoked when the reference count returns to zero.- Specified by:
onReferenceCountAtZero
in classReferenceCounted
-