Class PointStorageStrategy

java.lang.Object
com.inductiveautomation.historian.gateway.api.storage.strategy.PointStorageStrategy
Direct Known Subclasses:
DebounceStorageStrategy, FailureHandlingStorageStrategy, ImmediateStorageStrategy

public abstract class PointStorageStrategy extends Object
Decides when and how points reach the storage engine: store immediately, buffer and batch, or divert. The engine registers a PointStorageStrategy.Listener and the strategy hands it ready batches.
  • Field Details

    • SHUTDOWN_FAILURE_CODE

      protected static final QualityCode SHUTDOWN_FAILURE_CODE
      Failure code for points rejected because the strategy shut down. An error-level code, since failureWithError(QualityCode, List) pairs it with an exception.
    • UNHANDLED_FAILURE_CODE

      protected static final QualityCode UNHANDLED_FAILURE_CODE
      Failure code for a batch that left the queue but that no listener settled.
  • Constructor Details

    • PointStorageStrategy

      public PointStorageStrategy()
  • Method Details

    • failureWithError

      protected static <P extends TemporalPoint<?,?>> StorageResult<P> failureWithError(QualityCode code, List<P> points)
      Builds a failure result that carries an exception as well as code. The exception is what makes store-and-forward retain the data; a bare failure code would let the points be dropped.
      Parameters:
      code - the quality code describing the failure.
      points - the points that were not stored.
      Returns:
      a result carrying code and a matching exception.
    • completeAsFailure

      protected static <P extends TemporalPoint<?,?>> void completeAsFailure(TemporalPointBatch<P> batch, QualityCode code)
      Completes batch as a failure with code, unless something already settled it.
      Parameters:
      batch - the batch to fail.
      code - the quality code describing the failure.
    • processAtomic

      public abstract CompletionStage<StorageResult<AtomicPoint<?>>> processAtomic(List<AtomicPoint<?>> atomicPoints)
      Processes atomic points asynchronously.
      Parameters:
      atomicPoints - the points to process.
      Returns:
      a stage completing with the storage result.
    • processComplex

      public abstract <C extends ComplexPoint<?>> CompletionStage<StorageResult<C>> processComplex(List<C> complexPoints)
      Processes complex points asynchronously.
      Type Parameters:
      C - the complex point type.
      Parameters:
      complexPoints - the points to process.
      Returns:
      a stage completing with the storage result.
    • processChanges

      public abstract <C extends ChangePoint<?>> CompletionStage<StorageResult<C>> processChanges(List<C> changePoints)
      Processes change points asynchronously.
      Type Parameters:
      C - the change point type.
      Parameters:
      changePoints - the points to process.
      Returns:
      a stage completing with the storage result.
    • pauseProcessing

      public void pauseProcessing()
      Suspends forwarding for a transient pause, such as an engine restart, while buffering strategies keep accepting and retaining points until resumeProcessing(). Unlike stopProcessing(), nothing is rejected. The default delegates to stopProcessing(), for strategies that cannot buffer (e.g. ImmediateStorageStrategy).
    • stopProcessing

      public abstract void stopProcessing()
      Stops processing, rejects further points and releases resources. Call when the engine is shutting down.
    • resumeProcessing

      public abstract void resumeProcessing()
      Resumes processing after pauseProcessing() or stopProcessing().
    • metrics

      public Optional<StorageStrategyMetrics> metrics()
      Returns how much data is queued and how long the oldest has waited. Buffering strategies override this; the default is empty, for strategies that hold no backlog.
      Returns:
      the current metrics, or empty if the strategy accumulates no data.
    • flushTelemetry

      public Optional<FlushTelemetry> flushTelemetry()
      Returns batch size, dwell and downstream duration over a window of recent flushes. Buffering strategies override this; the default is empty.
      Returns:
      the current telemetry, or empty if the strategy does not flush in batches.
    • flushNow

      public void flushNow()
      Starts draining any buffered data without waiting for timers; best-effort, and the drain may not have completed on return. The default does nothing, for strategies that hold no backlog.
    • joinSubBatchResults

      protected static <P extends TemporalPoint<?,?>> CompletableFuture<StorageResult<P>> joinSubBatchResults(List<CompletableFuture<StorageResult<P>>> subs)
      Merges sub-batch result futures into one, per StorageResult.join(StorageResult, StorageResult).
      Type Parameters:
      P - the point type.
      Parameters:
      subs - the per-sub-batch result futures.
      Returns:
      a future completing with the merged result once every sub-batch settles.
    • forwardPoints

      protected final boolean forwardPoints(TemporalPointBatch<?> batch)
      Hands a batch to the registered listener. A batch that reaches no listener is already out of its queue, so the caller must then complete its future.
      Parameters:
      batch - the batch to forward.
      Returns:
      true if a listener was invoked; false if the batch went nowhere.
    • onPointsReady

      public void onPointsReady(PointStorageStrategy.Listener pointsConsumer)
      Registers the listener for ready batches. Composite strategies override this to pass the listener on to their delegates.
      Parameters:
      pointsConsumer - the listener to register.