Class AbstractDatasourceSink<T extends PersistentData>
- Type Parameters:
T
- the type ofPersistentData
that this sink can handle
- All Implemented Interfaces:
DataConsumer<T>
,DataSink<T>
- Direct Known Subclasses:
HistoricalRecordSink
-
Nested Class Summary
Nested classes/interfaces inherited from class com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractSink
AbstractSink.SinkWriter
-
Field Summary
FieldsFields inherited from class com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractSink
batchSize, flavor, name, status, storageId, storeMetric
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractDatasourceSink
(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize) Constructs an instance of AbstractDatasourceSink with the specified parameters.protected
AbstractDatasourceSink
(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize, boolean useDatasourceListener) Constructs an AbstractDatasourceSink instance with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected Datasource
Retrieves the configuredDatasource
instance associated with this data sink.protected QueryCache
Returns theQueryCache
for the Datasource belonging to this datasource sink.protected boolean
Checks whether the datasource is available and in a valid state.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
onStorageFailure
(List<T> data, Exception e) Handles a storage failure scenario by logging the error details and rethrowing aDataStorageException
.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.protected void
runFirstTimeChecks
(Connection conn) Runs a series of checks on the connection before allowing it to be used for storing data.void
Stores a list of persistent data.protected abstract void
storeToConnection
(SRConnection conn, List<T> data) Stores the given data to the specified connection.protected void
storeToDatasource
(Datasource datasource, List<T> data) Stores the list of supported TPersistentData
to the database.protected boolean
Returns whether JDBC batching should be used when inserting data.Methods inherited from class com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractSink
createLogger, getContext, getFaultError, getInfo, getLogger, getMetricPrefix, getName, getStorageId, getSupportedFlavor, getTypeDescription, getWriter, initialize, isAccepting, markStoreMetric, onFailure, shutdown, startup, toString, uninitialize, updateStatus, validateFlavor
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
-
Field Details
-
datasourceName
-
queryCache
-
-
Constructor Details
-
AbstractDatasourceSink
protected AbstractDatasourceSink(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize) Constructs an instance of AbstractDatasourceSink with the specified parameters. By default, aDatasourceListener
instance will be used for monitoring the status of the associated Datasource.- Parameters:
context
- the GatewayContext providing access to runtime context and system informationstorageId
- the unique identifier associated with the storage configurationflavor
- the PersistentFlavor representing the data format or type for persistencebatchSize
- the number of records to batch during data storage operations
-
AbstractDatasourceSink
protected AbstractDatasourceSink(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize, boolean useDatasourceListener) Constructs an AbstractDatasourceSink instance with the specified configuration.- Parameters:
context
- the GatewayContext object providing runtime context for the sinkstorageId
- the StorageId containing the storage configuration, including the engine identifierflavor
- the PersistentFlavor representing the type of persistent storagebatchSize
- the size of data batches for storage operationsuseDatasourceListener
- a flag indicating whether aDatasourceListener
should be used to monitor the status of the associated datasource
-
-
Method Details
-
onStartup
protected void onStartup()Description copied from class:AbstractSink
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.- Overrides:
onStartup
in classAbstractSink<T extends PersistentData>
-
onShutdown
protected void onShutdown()Description copied from class:AbstractSink
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.
- Overrides:
onShutdown
in classAbstractSink<T extends PersistentData>
-
onInitialize
Description copied from class:AbstractSink
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.- Overrides:
onInitialize
in classAbstractSink<T extends PersistentData>
- Throws:
Exception
- if an unhandled exception is thrown during initialization
-
onUninitialize
protected void onUninitialize()Description copied from class:AbstractSink
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.
- Overrides:
onUninitialize
in classAbstractSink<T extends PersistentData>
-
storeData
Description copied from interface:DataConsumer
Stores a list of persistent data.- Parameters:
data
- The data to be stored- Throws:
DataStorageException
- if an error occurs while storing data
-
getDatasource
Retrieves the configuredDatasource
instance associated with this data sink. The datasource provides access to a database connection pool and related database operations.- Returns:
- the configured
Datasource
instance
-
isDatasourceAvailable
protected boolean isDatasourceAvailable()Checks whether the datasource is available and in a valid state.This method retrieves the current datasource using the
getDatasource()
method and validates that it is notnull
and its extended status isVALID
.- Returns:
true
if the datasource is available and its extended status isVALID
;false
otherwise.
-
useBatching
protected boolean useBatching()Returns whether JDBC batching should be used when inserting data.- Returns:
- the flag indicating whether batching should be used
-
getQueryCache
Returns theQueryCache
for the Datasource belonging to this datasource sink.- Returns:
- the datasource query cache
-
storeToDatasource
Stores the list of supported TPersistentData
to the database. First, batching is done, and then the operation is handed off tostoreToConnection(SRConnection, List)
A commit occurs once all batches execute. If a failure occurs, then the transaction is rolled back.
- Parameters:
datasource
- the datasource to store persistent data todata
- the list of persistent data to store- Throws:
DataStorageException
- if an error occurs while storing data
-
storeToConnection
Stores the given data to the specified connection.- Parameters:
conn
- the connection to store the data todata
- the data to be stored- Throws:
Exception
- if there is an error storing the data
-
runFirstTimeChecks
Runs a series of checks on the connection before allowing it to be used for storing data. This includes checking whether the connection supports batch updates, and logging a warning if it does not.- Parameters:
conn
- the connection to check- Throws:
SQLException
- if there is an error while running the checks
-
onStorageFailure
Handles a storage failure scenario by logging the error details and rethrowing aDataStorageException
.- Parameters:
data
- the list of data items that failed to be storede
- the exception that caused the storage operation to fail- Throws:
DataStorageException
- rethrows the provided exception wrapped as aDataStorageException
-