Class AbstractSink<T extends PersistentData>
- Type Parameters:
T
- a subclass ofPersistentData
- All Implemented Interfaces:
DataConsumer<T>
,DataSink<T>
- Direct Known Subclasses:
AbstractDatasourceSink
,com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractRemoteSink
,TagHistoryDataSinkBridge
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected final PersistentFlavor<T>
protected final String
protected AtomicReference<SinkStatus>
protected final StorageId
protected com.codahale.metrics.Meter
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractSink
(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor) protected
AbstractSink
(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize) -
Method Summary
Modifier and TypeMethodDescriptionprotected LoggerEx
Creates and returns a newLoggerEx
instance to be used for this sink.protected GatewayContext
Returns theGatewayContext
within this data sink.getInfo()
Returns descriptive information about this data sink.protected LoggerEx
Returns theLoggerEx
instance that can be used to log messages.protected String
Returns the metric prefix to be used for the metrics registered to the metric registry.protected String
getName()
Returns the name of the sink.Returns the flavor of data that the data sink supports.protected abstract LocalizedString
Gets a writer object for writing to the data sink.protected final void
Initializes the data sink by transitioning its status toSinkStatus.INITIALIZING
, performing custom initialization logic, and transitioning toSinkStatus.ACCEPTING
upon successful initialization.boolean
Determines whether the data sink is currently accepting data.protected void
markStoreMetric
(int count) Marks aMeter
for the data amount stored in this data sink.protected void
Handles a critical failure encountered by the data sink.protected void
Synchronized lifecycle hook intended to be implemented or overridden by subclasses to perform initialization tasks specific to the sink.protected void
Synchronized lifecycle hook intended to be implemented or overridden by subclasses ofAbstractSink
to define custom behavior that should occur during the shutdown phase of the sink's lifecycle.protected void
This method is a synchronized lifecycle hook intended to be implemented or overridden by subclasses ofAbstractSink
.protected void
Synchronized lifecycle hook intended to be implemented or overridden by subclasses ofAbstractSink
to define custom teardown or cleanup operations that should occur during the uninitialization phase of the sink's lifecycle.final void
shutdown()
Shuts down the data sink by transitioning its status toSinkStatus.STOPPED
and invoking any subclass-specific shutdown logic defined inonShutdown()
.final void
startup()
Starts the data sink by transitioning its status toSinkStatus.STARTED
and invoking any additional startup logic specific to the sink.toString()
protected final void
Uninitializes the data sink by transitioning its status toSinkStatus.UNINITIALIZED
and invoking any subclass-specific teardown logic defined inonUninitialize()
.protected boolean
updateStatus
(SinkStatus status) Updates the current status of the sink to the provided value.validateFlavor
(PersistentFlavor<?> flavor) Validates a givenPersistentFlavor
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.inductiveautomation.ignition.gateway.storeforward.DataConsumer
storeData, storeData
-
Field Details
-
flavor
-
storageId
-
name
-
status
-
storeMetric
protected com.codahale.metrics.Meter storeMetric -
batchSize
protected int batchSize
-
-
Constructor Details
-
AbstractSink
protected AbstractSink(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize) -
AbstractSink
-
-
Method Details
-
startup
public final void startup()Starts the data sink by transitioning its status toSinkStatus.STARTED
and invoking any additional startup logic specific to the sink.If the status update to
STARTED
is successful, a log message is generated at the debug level, indicating that the sink is beginning its startup process. The method then callsonStartup()
, a lifecycle hook that subclasses can implement to define custom startup behavior.This method is thread-safe due to the use of synchronization, ensuring that only one thread can execute the startup sequence at any given time.
If any unexpected exceptions are thrown during the startup process (including from
onStartup()
), they will be caught and handled by transitioning the sink toSinkStatus.FAULTED
state. The exception will be logged and stored as the fault error, leaving the sink in a faulted state rather than an inconsistent state.- Specified by:
startup
in interfaceDataSink<T extends PersistentData>
-
onStartup
protected void onStartup()This method is a synchronized lifecycle hook intended to be implemented or overridden by subclasses ofAbstractSink
. It is invoked during the startup phase of the data sink.Subclasses can implement this method to define specific behavior that should occur when the sink becomes active, such as initializing resources, registering metrics, or preparing underlying systems. This method is invoked within the
startup()
method.It is thread-safe due to the use of synchronization and ensures that only one thread can execute this method at any given time.
Any exceptions thrown from this method will be caught and handled by the startup process, causing the sink to transition to
SinkStatus.FAULTED
state. The exception will be logged and stored as the fault error, ensuring the sink does not remain in an inconsistent state. -
initialize
protected final void initialize()Initializes the data sink by transitioning its status toSinkStatus.INITIALIZING
, performing custom initialization logic, and transitioning toSinkStatus.ACCEPTING
upon successful initialization.This method is synchronized to ensure thread safety, allowing only one thread to execute the initialization process at any given time. It first attempts to update the sink's status to
INITIALIZING
. If the status update is successful, a debug log message is generated, indicating that the sink is being initialized.During initialization, the
onInitialize()
method is invoked, allowing subclasses to define specific setup behavior required for the sink. Any exceptions thrown byonInitialize()
are caught and handled by callingonFailure(Exception)
, which logs the error, sets the sink status toSinkStatus.FAULTED
, and stores the exception as the fault error. If no exceptions are thrown and no faults are encountered (monitored via thefaultError
field), the status of the sink is transitioned toACCEPTING
.Subclasses implementing custom logic within the
onInitialize()
method can throw exceptions to signal initialization failures. These exceptions will be properly handled and will cause the sink to fault rather than progress to an operational state. -
onInitialize
Synchronized lifecycle hook intended to be implemented or overridden by subclasses to perform initialization tasks specific to the sink. This method is invoked during the initialization phase of the sink's lifecycle.Subclasses can use this method to define custom logic for setting up resources, configurations, or other components necessary for the sink to function properly. The method is designed to ensure that only one thread can execute it at any given time due to synchronization.
Any exceptions thrown from this method will be handled by the initialization process and will cause the sink to fault. When an exception is thrown, the sink's status will be set to
SinkStatus.FAULTED
and the exception will be logged and stored as the fault error.- Throws:
Exception
- if an unhandled exception is thrown during initialization
-
uninitialize
protected final void uninitialize()Uninitializes the data sink by transitioning its status toSinkStatus.UNINITIALIZED
and invoking any subclass-specific teardown logic defined inonUninitialize()
.If the status update to
SinkStatus.UNINITIALIZED
is successful, a debug log message is generated indicating that the data sink is being uninitialized. The method then callsonUninitialize()
, a lifecycle hook for performing cleanup tasks or releasing resources.This method is thread-safe due to the use of synchronization, ensuring that only one thread can execute the uninitialization process at any given time.
Subclasses overriding
onUninitialize()
should ensure that no unhandled exceptions are thrown, as such failures could disrupt the uninitialization process and leave the data sink in an inconsistent state. -
onUninitialize
protected void onUninitialize()Synchronized lifecycle hook intended to be implemented or overridden by subclasses ofAbstractSink
to define custom teardown or cleanup operations that should occur during the uninitialization phase of the sink's lifecycle.This method is invoked by the
uninitialize()
method and provides a safe point for releasing resources, deregistering metrics, or any other tasks necessary to prepare the sink for deactivation or shutdown.Subclasses overriding this method should ensure no unhandled exceptions are thrown, as this could disrupt the uninitialization process. Due to synchronization, it is guaranteed that only one thread will execute this method at a time.
-
shutdown
public final void shutdown()Shuts down the data sink by transitioning its status toSinkStatus.STOPPED
and invoking any subclass-specific shutdown logic defined inonShutdown()
.If the status update to
STOPPED
is successful, a debug log message is generated, indicating that the sink is shutting down. The method then callsonShutdown()
, a lifecycle hook that subclasses can implement to define custom shutdown behavior.This method is thread-safe due to the use of synchronization, ensuring that only one thread can execute the shutdown sequence at any given time.
Subclasses overriding
onShutdown()
should ensure that no unhandled exceptions are thrown, as such failures may disrupt the shutdown process and leave the data sink in an inconsistent state.- Specified by:
shutdown
in interfaceDataSink<T extends PersistentData>
-
onShutdown
protected void onShutdown()Synchronized lifecycle hook intended to be implemented or overridden by subclasses ofAbstractSink
to define custom behavior that should occur during the shutdown phase of the sink's lifecycle.This method is invoked within the
shutdown()
method and provides a safe point for performing cleanup or resource release tasks. Subclasses can use this method to deregister metrics, close connections, or perform other operations needed to gracefully shut down the sink.Due to synchronization, it ensures that only one thread can execute this method at any given time. Subclasses overriding this method should ensure that no unhandled exceptions are thrown, as this could disrupt the shutdown process.
-
onFailure
Handles a critical failure encountered by the data sink. This method is synchronized to ensure thread safety when logging an error, updating the status of the sink, and setting the fault error.- Parameters:
exception
- theException
representing the critical failure encountered
-
isAccepting
public boolean isAccepting()Description copied from interface:DataSink
Determines whether the data sink is currently accepting data.- Specified by:
isAccepting
in interfaceDataSink<T extends PersistentData>
- Returns:
- true if the data sink is accepting data, false otherwise
-
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 interfaceDataSink<T extends PersistentData>
- Returns:
- a
BatchWriter
object for writing to the data sink
-
getInfo
Description copied from interface:DataSink
Returns descriptive information about this data sink.- Specified by:
getInfo
in interfaceDataSink<T extends PersistentData>
- Returns:
- the descriptive information pertaining to this data sink
-
getSupportedFlavor
Description copied from interface:DataSink
Returns the flavor of data that the data sink supports.- Specified by:
getSupportedFlavor
in interfaceDataSink<T extends PersistentData>
- Returns:
- a
PersistentFlavor
object representing the supported flavor
-
validateFlavor
Description copied from interface:DataConsumer
Validates a givenPersistentFlavor
. The default implementation always gives an uncertain quality code.- Specified by:
validateFlavor
in interfaceDataConsumer<T extends PersistentData>
- Parameters:
flavor
- The flavor to be validated- Returns:
- A
QualityCode
denoting the evaluated quality of the flavor. By default, returnsQualityCode.Uncertain
.
-
toString
-
getStorageId
-
getFaultError
-
getContext
Returns theGatewayContext
within this data sink.- Returns:
- the gateway context
-
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
Returns theLoggerEx
instance that can be used to log messages. If the logger hasn't yet been defined, one will be created usingcreateLogger()
.- Returns:
- the
LoggerEx
instance to be used for logging messages
-
createLogger
Creates and returns a newLoggerEx
instance to be used for this sink.- Returns:
- a
LoggerEx
instance for this sink
-
getName
Returns the name of the sink.- Returns:
- the name of the sink
-
markStoreMetric
protected void markStoreMetric(int count) Marks aMeter
for the data amount stored in this data sink.- Parameters:
count
- the data amount to mark as stored
-
updateStatus
Updates the current status of the sink to the provided value. If the new status differs from the previous status, the change is captured.- Parameters:
status
- the newSinkStatus
to set for the sink- Returns:
- true if the new status differs from the previous status, false otherwise
-
getTypeDescription
-