Class SwapListenerBase<T extends ListenerBase>

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 Details

    • DEBUG

      protected static final boolean DEBUG
  • Constructor Details

    • SwapListenerBase

      public SwapListenerBase(com.fishlib.io.logger.Logger log, BaseTable sourceTable)
  • Method Details

    • makeSnapshotControl

      public ConstructSnapshot.SnapshotControl 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 - The logical 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

      public void onFailure(Throwable originalException, UpdatePerformanceTracker.Entry sourceEntry)
      Description copied from interface: ListenerBase
      Notification of exceptions.
      Specified by:
      onFailure in interface ListenerBase
      Parameters:
      originalException - exception
      sourceEntry - 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 interface ListenerBase
      Parameters:
      originalException - exception
      sourceEntry - 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 to
      resultTable - The table that will result from this operation
    • subscribeForUpdates

      public abstract void subscribeForUpdates()
      Invoke DynamicTable.listenForUpdates(Listener) for the appropriate subclass of SwapListenerBase.