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.ReferenceCountedLivenessNode
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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
end
(long clockCycle) Ends a snapshot.getErrorNotification
(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry) Creates a notification for the exception.void
onFailure
(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry) Notification of exceptions.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
InvokeDynamicTable.listenForUpdates(Listener)
for the appropriate subclass ofSwapListenerBase
.Methods inherited from class com.illumon.iris.db.util.liveness.LivenessArtifact
manageWithCurrentScope, unmanage, unmanage
Methods inherited from class com.illumon.iris.db.util.liveness.ReferenceCountedLivenessNode
destroy, dropReference, getWeakReference, initializeTransientFieldsForLiveness, onReferenceCountAtZero, tryManage, tryRetainReference
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
-
SwapListenerBase
-
-
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
.
-