C# Class GSF.TimeSeries.Adapters.OutputAdapterBase

Represents the base class for any outgoing data stream.
This base class acts as a measurement queue so that output adapters can temporarily go offline without losing any measurements to be processed. Derived classes are expected to override ProcessMeasurements to handle queued measurements.
Inheritance: AdapterBase, IOutputAdapter
Exibir arquivo Open project: GridProtectionAlliance/gsf

Private Properties

Property Type Description
AttemptConnectionOperation void
RefreshMetadata void
m_connectionTimer_Elapsed void
m_measurementQueue_ProcessException void
m_monitorTimer_Elapsed void

Public Methods

Method Description
Flush ( ) : void

Blocks the current thread, if the OutputAdapterBase is connected, until all items in OutputAdapterBase queue are processed, and then stops processing.

It is possible for items to be added to the queue while the flush is executing. The flush will continue to process items as quickly as possible until the queue is empty. Unless the user stops queuing items to be processed, the flush call may never return (not a happy situation on shutdown).

The OutputAdapterBase does not clear queue prior to destruction. If the user fails to call this method before the class is destructed, there may be items that remain unprocessed in the queue.

Initialize ( ) : void

Initializes OutputAdapterBase.

QueueMeasurementForProcessing ( IMeasurement measurement ) : void

Queues a single measurement for processing. Measurement is automatically filtered to the defined IAdapter.InputMeasurementKeys.

QueueMeasurementsForProcessing ( IEnumerable measurements ) : void

Queues a collection of measurements for processing. Measurements are automatically filtered to the defined IAdapter.InputMeasurementKeys.

RemoveMeasurements ( int total ) : void

This removes a range of measurements from the internal measurement queue.

This method is typically only used to curtail size of measurement queue if it's getting too large. If more points are requested than there are points available - all points in the queue will be removed.

Start ( ) : void

Starts this OutputAdapterBase and initiates connection cycle to data output stream.

Stop ( ) : void

Stops this OutputAdapterBase and disconnects from data output stream.

Protected Methods

Method Description
AttemptConnection ( ) : void

Attempts to connect to data output stream.

Derived classes should attempt connection to data output stream here. Any exceptions thrown by this implementation will result in restart of the connection cycle.

AttemptDisconnection ( ) : void

Attempts to disconnect from data output stream.

Derived classes should attempt disconnect from data output stream here. Any exceptions thrown by this implementation will be reported to host via AdapterBase.ProcessException event.

Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the OutputAdapterBase object and optionally releases the managed resources.

ExecuteMetadataRefresh ( ) : void

Executes the metadata refresh in a synchronous fashion.

OnConnected ( ) : void

Called when data output source connection is established.

Derived classes should call this method manually if UseAsyncConnect is true.

OnDisconnected ( ) : void

Called when data input source is disconnected.

Derived classes should call this method manually if UseAsyncConnect is true.

OnUnprocessedMeasurements ( int unprocessedMeasurements ) : void

Raises the UnprocessedMeasurements event.

OutputAdapterBase ( ) : System

Constructs a new instance of the OutputAdapterBase.

ProcessMeasurements ( IMeasurement measurements ) : void

Serializes measurements to data output stream.

Derived classes must implement this function to process queued measurements. For example, this function would "archive" measurements if output adapter is for a historian.

It is important that consumers "resume" connection cycle if processing fails (e.g., connection to archive is lost). Here is an example: protected virtual void ProcessMeasurements(IMeasurement[] measurements) { try { // Process measurements... foreach (IMeasurement measurement in measurement) { ArchiveMeasurement(measurement); } } catch (Exception) { // So long as user hasn't requested to stop, restart connection cycle if (Enabled) Start(); } }

Private Methods

Method Description
AttemptConnectionOperation ( ) : void
RefreshMetadata ( ) : void
m_connectionTimer_Elapsed ( object sender, EventArgs e ) : void
m_measurementQueue_ProcessException ( object sender, EventArgs e ) : void
m_monitorTimer_Elapsed ( object sender, EventArgs e ) : void

Method Details

AttemptConnection() protected abstract method

Attempts to connect to data output stream.
Derived classes should attempt connection to data output stream here. Any exceptions thrown by this implementation will result in restart of the connection cycle.
protected abstract AttemptConnection ( ) : void
return void

AttemptDisconnection() protected abstract method

Attempts to disconnect from data output stream.
Derived classes should attempt disconnect from data output stream here. Any exceptions thrown by this implementation will be reported to host via AdapterBase.ProcessException event.
protected abstract AttemptDisconnection ( ) : void
return void

Dispose() protected method

Releases the unmanaged resources used by the OutputAdapterBase object and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

ExecuteMetadataRefresh() protected method

Executes the metadata refresh in a synchronous fashion.
protected ExecuteMetadataRefresh ( ) : void
return void

Flush() public method

Blocks the current thread, if the OutputAdapterBase is connected, until all items in OutputAdapterBase queue are processed, and then stops processing.

It is possible for items to be added to the queue while the flush is executing. The flush will continue to process items as quickly as possible until the queue is empty. Unless the user stops queuing items to be processed, the flush call may never return (not a happy situation on shutdown).

The OutputAdapterBase does not clear queue prior to destruction. If the user fails to call this method before the class is destructed, there may be items that remain unprocessed in the queue.

public Flush ( ) : void
return void

Initialize() public method

Initializes OutputAdapterBase.
public Initialize ( ) : void
return void

OnConnected() protected method

Called when data output source connection is established.
Derived classes should call this method manually if UseAsyncConnect is true.
protected OnConnected ( ) : void
return void

OnDisconnected() protected method

Called when data input source is disconnected.
Derived classes should call this method manually if UseAsyncConnect is true.
protected OnDisconnected ( ) : void
return void

OnUnprocessedMeasurements() protected method

Raises the UnprocessedMeasurements event.
protected OnUnprocessedMeasurements ( int unprocessedMeasurements ) : void
unprocessedMeasurements int Total measurements in the queue that have not been processed.
return void

OutputAdapterBase() protected method

Constructs a new instance of the OutputAdapterBase.
protected OutputAdapterBase ( ) : System
return System

ProcessMeasurements() protected abstract method

Serializes measurements to data output stream.

Derived classes must implement this function to process queued measurements. For example, this function would "archive" measurements if output adapter is for a historian.

It is important that consumers "resume" connection cycle if processing fails (e.g., connection to archive is lost). Here is an example: protected virtual void ProcessMeasurements(IMeasurement[] measurements) { try { // Process measurements... foreach (IMeasurement measurement in measurement) { ArchiveMeasurement(measurement); } } catch (Exception) { // So long as user hasn't requested to stop, restart connection cycle if (Enabled) Start(); } }

protected abstract ProcessMeasurements ( IMeasurement measurements ) : void
measurements IMeasurement
return void

QueueMeasurementForProcessing() public method

Queues a single measurement for processing. Measurement is automatically filtered to the defined IAdapter.InputMeasurementKeys.
public QueueMeasurementForProcessing ( IMeasurement measurement ) : void
measurement IMeasurement Measurement to queue for processing.
return void

QueueMeasurementsForProcessing() public method

Queues a collection of measurements for processing. Measurements are automatically filtered to the defined IAdapter.InputMeasurementKeys.
public QueueMeasurementsForProcessing ( IEnumerable measurements ) : void
measurements IEnumerable Measurements to queue for processing.
return void

RemoveMeasurements() public method

This removes a range of measurements from the internal measurement queue.
This method is typically only used to curtail size of measurement queue if it's getting too large. If more points are requested than there are points available - all points in the queue will be removed.
public RemoveMeasurements ( int total ) : void
total int
return void

Start() public method

Starts this OutputAdapterBase and initiates connection cycle to data output stream.
public Start ( ) : void
return void

Stop() public method

Stops this OutputAdapterBase and disconnects from data output stream.
public Stop ( ) : void
return void