java.lang.Object
com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractSink<T>
Type Parameters:
T - a subclass of PersistentData
All Implemented Interfaces:
DataConsumer<T>, DataSink<T>
Direct Known Subclasses:
AbstractDatasourceSink, RemoteHistorianSink, TagHistoryDataSinkBridge

public abstract class AbstractSink<T extends PersistentData> extends Object implements DataSink<T>
The abstract base class for all data sinks.
  • Field Details

    • RETRY_TIME

      protected static final int RETRY_TIME
      See Also:
    • flavor

      protected final PersistentFlavor<T extends PersistentData> flavor
    • storageId

      protected final StorageId storageId
    • name

      protected final String name
    • status

      protected SinkStatus status
    • faultError

      @Nullable protected Exception faultError
    • storeMetric

      protected com.codahale.metrics.Meter storeMetric
    • lastInitAttempt

      protected long lastInitAttempt
    • faultedTimestamp

      protected long faultedTimestamp
    • batchSize

      protected int batchSize
  • Constructor Details

  • Method Details

    • startup

      public void startup()
      Description copied from interface: DataSink
      Starts up the data sink.
      Specified by:
      startup in interface DataSink<T extends PersistentData>
    • shutdown

      public void shutdown()
      Description copied from interface: DataSink
      Shuts down the data sink.
      Specified by:
      shutdown in interface DataSink<T extends PersistentData>
    • isAccepting

      public boolean isAccepting()
      Description copied from interface: DataSink
      Determines whether the data sink is currently accepting data.
      Specified by:
      isAccepting in interface DataSink<T extends PersistentData>
      Returns:
      true if the data sink is accepting data, false otherwise
    • getWriter

      public BatchWriter<T> getWriter()
      Description copied from interface: DataSink
      Gets a writer object for writing to the data sink. This can be used for batching data together when writing.
      Specified by:
      getWriter in interface DataSink<T extends PersistentData>
      Returns:
      a BatchWriter object for writing to the data sink
    • getInfo

      public DataSinkInformation getInfo()
      Description copied from interface: DataSink
      Returns descriptive information about this data sink.
      Specified by:
      getInfo in interface DataSink<T extends PersistentData>
      Returns:
      the descriptive information pertaining to this data sink
    • getSupportedFlavor

      public PersistentFlavor<T> getSupportedFlavor()
      Description copied from interface: DataSink
      Returns the flavor of data that the data sink supports.
      Specified by:
      getSupportedFlavor in interface DataSink<T extends PersistentData>
      Returns:
      a PersistentFlavor object representing the supported flavor
    • validateFlavor

      public QualityCode validateFlavor(PersistentFlavor<?> flavor)
      Description copied from interface: DataConsumer
      Validates a given PersistentFlavor. The default implementation always gives an uncertain quality code.
      Specified by:
      validateFlavor in interface DataConsumer<T extends PersistentData>
      Parameters:
      flavor - The flavor to be validated
      Returns:
      A QualityCode denoting the evaluated quality of the flavor. By default, returns QualityCode.Uncertain.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getStorageId

      public StorageId getStorageId()
    • getContext

      protected GatewayContext getContext()
      Returns the GatewayContext within this data sink.
      Returns:
      the gateway context
    • getMetricPrefix

      protected String getMetricPrefix()
      Returns the metric prefix to be used for the metrics registered to the metric registry.
      Returns:
      the string metric prefix for registering metrics to metric registry
    • getLogger

      protected LoggerEx getLogger()
      Returns the LoggerEx instance that can be used to log messages. If the logger hasn't yet been defined, one will be created using createLogger().
      Returns:
      the LoggerEx instance to be used for logging messages
    • createLogger

      protected LoggerEx createLogger()
      Creates and returns a new LoggerEx instance to be used for this sink.
      Returns:
      a LoggerEx instance for this sink
    • initialize

      protected void initialize() throws Exception
      Initializes the sink. Any work that needs to be done to prepare the sink for accepting data should be done here. This method is called by the internalInit() method.
      Throws:
      Exception - if failure occurs while initializing
    • uninitialize

      protected void uninitialize()
      Uninitializes the sink.
    • getName

      protected String getName()
      Returns the name of the sink.
      Returns:
      the name of the sink
    • isStarted

      protected boolean isStarted()
      Returns true if the sink is in the "started" state, false otherwise.
      Returns:
      flag indicating whether the sink has started
    • isInitialized

      protected boolean isInitialized()
      Returns true if the sink is in the "initialized" state, false otherwise.
      Returns:
      flag indicating whether the sink is initialized
    • maybeInit

      protected boolean maybeInit()
      Attempts to initialize the sink if it is not already initialized, not in the process of initializing, and the last initialization attempt was made more than RETRY_TIME milliseconds ago. If an exception is thrown during initialization, it is logged and rethrown.
      Returns:
      flag indicating whether the sink is initialized
    • isFaulted

      public boolean isFaulted()
      Returns true if the sink is in the "faulted" state, false otherwise.
      Returns:
      flag indicating whether the sink is in a faulted state
    • getFaultReason

      public Optional<Exception> getFaultReason()
      Returns an optional containing the reason for the fault if the sink is in a faulted state.
      Returns:
      the optional fault reason
    • onException

      public void onException(String message, Exception e)
      Sets the status of this data sink to faulted and logs an error message.
      Parameters:
      message - a message describing the exception that occurred
      e - the exception that occurred, or null if no exception was thrown
    • markStoreMetric

      protected void markStoreMetric(int count)
      Marks a Meter for the data amount stored in this data sink.
      Parameters:
      count - the data amount to mark as stored
    • getTypeDescription

      @Nonnull protected abstract LocalizedString getTypeDescription()