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 booleanDEBUG -
Constructor Summary
Constructors Constructor Description SwapListenerBase(com.fishlib.io.logger.Logger log, BaseTable sourceTable) -
Method Summary
Modifier and Type Method Description protected voiddestroy()Attempt to release (destructively when necessary) resources held by this object.voiddropReference()Drop a previously-retained reference to this referent.protected booleanend(long clockCycle)Ends a snapshot.NotificationQueue.NotificationgetErrorNotification(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)Creates a notification for the exception.WeakReference<? extends LivenessReferent>getWeakReference()Get aWeakReferenceto this referent.voidinitializeTransientFieldsForLiveness()Package-private forSerializablesub-classes to use inreadObjectonly.ConstructSnapshot.SnapshotControlmakeSnapshotControl()voidonFailure(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)Notification of exceptions.protected voidonReferenceCountAtZero()Callback method that will be invoked when the reference count returns to zero.voidsetListenerAndResult(T listener, NotificationStepReceiver resultTable)Set the listener that will eventually become the listener, if we have a successful swap.protected booleanstart(long clockCycle)Starts a snapshot.abstract voidsubscribeForUpdates()InvokeDynamicTable.listenForUpdates(Listener)for the appropriate subclass ofSwapListenerBase.booleantryManage(LivenessReferent referent)Attempt to add the specified referent to this manager.booleantryRetainReference()If this referent is "live", behave asLivenessReferent.retainReference()and return true.Methods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanageMethods inherited from class com.illumon.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCountMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.illumon.iris.db.util.liveness.LivenessManager
manage, tryManageMethods 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 clockcycle 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:ListenerBaseNotification of exceptions.- Specified by:
onFailurein interfaceListenerBase- Parameters:
originalException- exceptionsourceEntry- performance tracking
-
getErrorNotification
public NotificationQueue.Notification getErrorNotification(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)Description copied from interface:ListenerBaseCreates a notification for the exception.- Specified by:
getErrorNotificationin 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 forSerializablesub-classes to use inreadObjectonly. 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:LivenessReferentIf this referent is "live", behave asLivenessReferent.retainReference()and return true. Otherwise, returns false rather than throwing an exception.- Specified by:
tryRetainReferencein interfaceLivenessReferent- Returns:
- True if this referent was retained, false otherwise
-
dropReference
public final void dropReference()Description copied from interface:LivenessReferentDrop a previously-retained reference to this referent.- Specified by:
dropReferencein interfaceLivenessReferent
-
getWeakReference
Description copied from interface:LivenessReferentGet aWeakReferenceto this referent. This may be cached, or newly created.- Specified by:
getWeakReferencein interfaceLivenessReferent- Returns:
- A new or cached reference to this referent
-
tryManage
Description copied from interface:LivenessManagerAttempt to add the specified referent to this manager.- Specified by:
tryManagein 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:ReferenceCountedCallback method that will be invoked when the reference count returns to zero.- Specified by:
onReferenceCountAtZeroin classReferenceCounted
-