Class PersistentQueryHandleBase

java.lang.Object
com.illumon.iris.controller.handle.PersistentQueryHandleBase
All Implemented Interfaces:
PersistentQueryHandle
Direct Known Subclasses:
CommunityPersistentQueryHandle, DoNothingHandle, EnterprisePersistentQueryHandle

public abstract class PersistentQueryHandleBase extends Object implements PersistentQueryHandle
  • Field Details

  • Constructor Details

    • PersistentQueryHandleBase

      protected PersistentQueryHandleBase(@NotNull com.fishlib.io.logger.Logger log, @NotNull Object queryHandleContext)
      Create a new PQ Handle. Note after creating the object, one of two things should happen: either start or restore should be called.
      Parameters:
      log - the log.
      queryHandleContext - A context object containing the required parameters for this object.
  • Method Details

    • onStartRequested

      protected abstract void onStartRequested()
    • onDispatcherConnected

      protected abstract boolean onDispatcherConnected(@NotNull QueryDispatcherConnection connection)
    • createWorkerHandle

      protected abstract WorkerHandle createWorkerHandle(RemoteProcessingRequest request, QueryDispatcherConnection dispatcherConnection)
    • getWorkerHandle

      @Nullable public WorkerHandle getWorkerHandle()
      Description copied from interface: PersistentQueryHandle
      Get the WorkerHandle for an active worker. May return null if the worker is not running.
      Specified by:
      getWorkerHandle in interface PersistentQueryHandle
      Returns:
      the WorkerHandle or null if the worker is not running
    • getVersion

      public long getVersion()
      Description copied from interface: PersistentQueryHandle
      Get the currently running version of the Persistent Query.
      Specified by:
      getVersion in interface PersistentQueryHandle
      Returns:
      the version of the running query
    • getState

      public PersistentQueryState getState()
      Description copied from interface: PersistentQueryHandle
      Get the current state object for the Persistent Query.
      Specified by:
      getState in interface PersistentQueryHandle
      Returns:
      the current state
    • start

      public void start(long whenToStopMillis)
      Description copied from interface: PersistentQueryHandle
      Start the worker. Only one of start() or restore() should be called after construction.
      Specified by:
      start in interface PersistentQueryHandle
      Parameters:
      whenToStopMillis - The scheduled stopping time for scheduled configs, or zero otherwise.
    • restore

      protected boolean restore(WorkerHandle workerHandle, PersistentQueryState oldState)
      If this PQ Handle object is being recreated from saved state, instead of start being called this method restores the object.
      Parameters:
      workerHandle - a worker handle to use as our own
      Returns:
      true if we were able to restore this object, false otherwise
    • shutdown

      public void shutdown(@Nullable UserContext userContext)
      Description copied from interface: PersistentQueryHandle
      Shutdown the worker, if it is running. This method blocks until shutdown is complete.
      Specified by:
      shutdown in interface PersistentQueryHandle
      Parameters:
      userContext - the user attempting the shutdown null indicates the controller itself.
    • setReplicaSlot

      public void setReplicaSlot(int replicaSlot)
      Description copied from interface: PersistentQueryHandle
      Set the replica slot for this handle.
      Specified by:
      setReplicaSlot in interface PersistentQueryHandle
      Parameters:
      replicaSlot - the replica slot.
    • ensureShutdown

      protected void ensureShutdown(boolean awaitDisconnection)
      Parameters:
      awaitDisconnection - Used to communicate whether we need to care further about ensuring disconnection, or not. If true, we block until interrupted or until another thread calls ensureShutdown(false). If false, we're asserting that the DB is already disconnected, or that we don't care (because no script was run yet).
    • checkQueryTerminatingOrTerminal

      protected boolean checkQueryTerminatingOrTerminal()
    • maybeSetTerminalStatus

      protected boolean maybeSetTerminalStatus(Supplier<PersistentQueryState.Status> statusSupplier)
    • onError

      protected void onError(@Nullable Throwable t)
    • onFailure

      protected void onFailure(@Nullable Throwable t, @Nullable String processInfoId, boolean awaitDisconnection)
    • onFailure

      protected void onFailure(@Nullable Throwable t, @Nullable String processInfoId, boolean awaitDisconnection, @Nullable String message)
    • publishState

      protected void publishState()
    • getScriptCode

      protected String getScriptCode()
    • infoLog

      protected com.fishlib.io.log.LogEntry infoLog()
    • warnLog

      protected com.fishlib.io.log.LogEntry warnLog()
    • errorLog

      protected com.fishlib.io.log.LogEntry errorLog()
    • getStateLock

      @NotNull public Object getStateLock()
      This method exposes the lock for the sole purpose of atomically swapping a single replica and spare. This currently lives in QueryTracker#ReshuffleRequest. Any further uses of this method MUST take care to avoid locking multiple states or avoiding a lock inversion.
      Specified by:
      getStateLock in interface PersistentQueryHandle
      Returns:
      the state lock