Class AbstractSink<T extends PersistentData>
java.lang.Object
com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractSink<T>
- Type Parameters:
T
- a subclass ofPersistentData
- All Implemented Interfaces:
DataConsumer<T>
,DataSink<T>
- Direct Known Subclasses:
AbstractDatasourceSink
,RemoteHistorianSink
,TagHistoryDataSinkBridge
The abstract base class for all data sinks.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected long
protected Exception
protected final PersistentFlavor<T>
protected long
protected final String
protected static final int
protected 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.Returns an optional containing the reason for the fault if the sink is in a faulted state.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 void
Initializes the sink.boolean
Determines whether the data sink is currently accepting data.boolean
Returns true if the sink is in the "faulted" state, false otherwise.protected boolean
Returns true if the sink is in the "initialized" state, false otherwise.protected boolean
Returns true if the sink is in the "started" state, false otherwise.protected void
markStoreMetric
(int count) Marks aMeter
for the data amount stored in this data sink.protected boolean
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 thanRETRY_TIME
milliseconds ago.void
onException
(String message, Exception e) Sets the status of this data sink to faulted and logs an error message.void
shutdown()
Shuts down the data sink.void
startup()
Starts up the data sink.toString()
protected void
Uninitializes the sink.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
-
RETRY_TIME
protected static final int RETRY_TIME- See Also:
-
flavor
-
storageId
-
name
-
status
-
faultError
-
storeMetric
protected com.codahale.metrics.Meter storeMetric -
lastInitAttempt
protected long lastInitAttempt -
faultedTimestamp
protected long faultedTimestamp -
batchSize
protected int batchSize
-
-
Constructor Details
-
AbstractSink
protected AbstractSink(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize) -
AbstractSink
-
-
Method Details
-
startup
public void startup()Description copied from interface:DataSink
Starts up the data sink.- Specified by:
startup
in interfaceDataSink<T extends PersistentData>
-
shutdown
public void shutdown()Description copied from interface:DataSink
Shuts down the data sink.- Specified by:
shutdown
in interfaceDataSink<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 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
-
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
-
initialize
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 theinternalInit()
method.- Throws:
Exception
- if failure occurs while initializing
-
uninitialize
protected void uninitialize()Uninitializes the sink. -
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 thanRETRY_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
Returns an optional containing the reason for the fault if the sink is in a faulted state.- Returns:
- the optional fault reason
-
onException
Sets the status of this data sink to faulted and logs an error message.- Parameters:
message
- a message describing the exception that occurrede
- the exception that occurred, or null if no exception was thrown
-
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
-
getTypeDescription
-