Class BaseMessageQueue<TMessage, TItem>
- Namespace
- ATAS.DataFeedsCore
- Assembly
- ATAS.DataFeedsCore.dll
A queue processed by its own thread.
The queue runs in sessions: Start(IDataFeedConnector, Action<TMessage>) begins one (the first connector of a shared queue), Stop(IDataFeedConnector)
ends it (the last connector). An item belongs to the session it was queued in: the items still queued when the
session ends are dropped - also when the next session has already begun (a connect issued right after a disconnect)
and the thread of the stopped session goes on to serve it. A message or an action queued while no session runs waits
for the next session (unless a thread of the stopped queue is still alive and drops it); a continuation
(EnqueueContinuation(IDataFeedConnector, Action)) queued after a session ended is dropped, it never runs in a later session.
public abstract class BaseMessageQueue<TMessage, TItem> : BaseLoggerSource, ILoggerSource
Type Parameters
TMessageTItem
- Inheritance
-
objectBaseLoggerSourceBaseMessageQueue<TMessage, TItem>
- Implements
- Derived
- Extension Methods
Constructors
BaseMessageQueue()
Initializes the queue with the logger name "Queue" and the logging level inherited from its parent.
protected BaseMessageQueue()
Properties
HeartbeatTimeout
Interval of the Heartbeat event; System.TimeSpan.Zero disables it. It also bounds how long the idle thread waits for an item, so the heartbeat is raised when no items arrive.
public TimeSpan HeartbeatTimeout { get; set; }
Property Value
- TimeSpan
Methods
CreateItem(IDataFeedConnector, TMessage?, Action?)
Packs a message or an action of a connector into a queue item; exactly one of message and
action is set.
Added in ATAS 8.0.15.
protected abstract TItem CreateItem(IDataFeedConnector connector, TMessage? message, Action? action)
Parameters
connectorIDataFeedConnectorThe connector the item belongs to.
messageTMessageThe message, or null for an action.
actionActionThe action, or null for a message.
Returns
- TItem
The queue item.
DescribeItem(TItem)
Short representation of a queued item for debug logging. Full message dumps are logged by connectors on receive; dumping them again here would double the cost.
Added in ATAS 8.0.15.
protected virtual object? DescribeItem(TItem item)
Parameters
itemTItem
Returns
- object
Enqueue(IDataFeedConnector, Action)
Queues an action to run on the connector's thread.
public void Enqueue(IDataFeedConnector connector, Action action)
Parameters
connectorIDataFeedConnectorThe connector the action belongs to.
actionActionThe action.
Exceptions
- ArgumentNullException
connectororactionis null.
Enqueue(IDataFeedConnector, TMessage)
Queues a message of the connector for its handler.
public void Enqueue(IDataFeedConnector connector, TMessage message)
Parameters
connectorIDataFeedConnectorThe connector the message belongs to.
messageTMessageThe message.
Exceptions
- ArgumentNullException
connectorormessageis null.
EnqueueContinuation(IDataFeedConnector, Action)
Not in ATAS 8.0.15 yet: available from the next version.
public void EnqueueContinuation(IDataFeedConnector connector, Action continuation)
Parameters
connectorIDataFeedConnectorcontinuationAction
Exceptions
- ArgumentNullException
connectororcontinuationis null.
OnProcess(TItem)
Processes an item of the running session on the process thread: passes the message to the handler of its connector or runs the action. An exception is logged and processing goes on.
protected abstract void OnProcess(TItem item)
Parameters
itemTItemThe item.
OnStart(IDataFeedConnector, Action<TMessage>)
Registers the handler of a connector; called by Start(IDataFeedConnector, Action<TMessage>) under the queue's lifetime lock.
protected abstract void OnStart(IDataFeedConnector connector, Action<TMessage> handler)
Parameters
connectorIDataFeedConnectorThe connector.
handlerAction<TMessage>The connector's message handler.
OnStop(IDataFeedConnector)
Unregisters a connector; called by Stop(IDataFeedConnector) under the queue's lifetime lock.
protected abstract bool OnStop(IDataFeedConnector connector)
Parameters
connectorIDataFeedConnectorThe connector.
Returns
- bool
true when no connector is left and the session may end.
Start(IDataFeedConnector, Action<TMessage>)
Registers the connector's handler (OnStart(IDataFeedConnector, Action<TMessage>)) and begins a session if none runs; starts the process thread unless the thread of the stopped session is still alive, which then serves the new session.
public void Start(IDataFeedConnector connector, Action<TMessage> handler)
Parameters
connectorIDataFeedConnectorThe connector.
handlerAction<TMessage>Processes a message of the connector on the process thread.
Exceptions
- ArgumentNullException
connectororhandleris null.
Stop(IDataFeedConnector)
Unregisters the connector (OnStop(IDataFeedConnector)) and, when that was the last one, ends the session: the items still queued are dropped and the process thread exits once the queue is empty.
public void Stop(IDataFeedConnector connector)
Parameters
connectorIDataFeedConnectorThe connector.
Exceptions
- ArgumentNullException
connectoris null.
Events
Heartbeat
Raised on the process thread every HeartbeatTimeout while a session runs; the first interval of the thread only starts the count and raises nothing.
Added in ATAS 8.0.15.
public event Action? Heartbeat
Event Type
- Action