Search Results for

    Show / Hide Table of Contents

    Class MessageCollector<T1, T2, T3>

    This is a helper class that collects thread safe all messages until all message types are collected.

    Inheritance
    Object
    MessageCollector<T1, T2>
    MessageCollector<T1, T2, T3>
    MessageCollector<T1, T2, T3, T4>
    Inherited Members
    MessageCollector<T1, T2>.Messages1
    MessageCollector<T1, T2>.Messages2
    MessageCollector<T1, T2>.Push(Message)
    MessageCollector<T1, T2>.TryPush(Message)
    MessageCollector<T1, T2>.RemoveMessage(Message)
    MessageCollector<T1, T2>.PushAndExecute(Message, Action<MessageCollection<T1, T2>>, CancellationToken)
    MessageCollector<T1, T2>.PushAndContinue(Message, Action<MessageCollection<T1, T2>>, CancellationToken)
    MessageCollector<T1, T2>.ExecutePushAndExecute(Message, Action<MessageCollection>, CancellationToken)
    MessageCollector<T1, T2>.ExecutePushAndContinue(Message, Action<MessageCollection>, CancellationToken)
    MessageCollector<T1, T2>.GetCompleteSets(MessageDomain)
    MessageCollector<T1, T2>.IsCompleted(MessageDomain, MessageCollection)
    MessageCollector<T1, T2>.TryGetMessageFittingDomain<T>(MessageDomain, ConcurrentDictionary<MessageDomain, MessageStore<T>>, MessageStore<T>)
    MessageCollector<T1, T2>.Execute(MessageCollection)
    MessageCollector<T1, T2>.Aggregate(Message, Boolean)
    MessageCollector<T1, T2>.UpdateMessagePool<T>(T, ConcurrentDictionary<MessageDomain, MessageStore<T>>)
    Namespace: Agents.Net
    Assembly: Agents.Net.dll
    Syntax
    public class MessageCollector<T1, T2, T3> : MessageCollector<T1, T2> where T1 : Message where T2 : Message where T3 : Message
    Type Parameters
    Name Description
    T1
    T2
    T3
    Remarks

    The collector collects messages until all message types are collected. Afterwards it executes an action with the collected MessageCollection. In the following different scenarios are described, which explain the different aspects of this class.

    Overriding messages

    Assuming the message of type T1 was collected and T2 was not. When another message of type T1 is collected it replaces the old T1 message with the new message. No action is executed.

    Considering message domains

    Assuming the following MessageDomains and the collected messages:

     ---------------         ------------
    | DefaultDomain | ----> | SubDomain1 |
     ---------------  |      ------------
    T1 Message1       |      T1 Message2
                      |      T2 Message4
                      |
                      |      ------------
                      ----> | SubDomain2 |
                             ------------
                             T2 Message3
                             T2 Message5
    Here is what happens in this scenario. Message1 is collected. Message2 is collected. This does not override Message1 because it is from a different MessageDomain. It is stored parallel. Message3 is collected. Now SubDomain2 has a complete set of Message1 + Message3. Message 4 is collected. Now there is another completed set in SubDomain1 of Message2 + Message4. Message5 is collected. This overrides Message3 as it is in the same MessageDomain. A new set is executed with Message1 + Message5. In the end the following sets were executed inorder:
    1. Message1 + Message3
    2. Message2 + Message4
    3. Message1 + Message5

    Consumed vs not consumed messages

    Messages can be consumed during execution with the method MarkAsConsumed(Message). The consumed message is removed from the message collector immediately. Looking at the example above the Message1 is used twice. Assuming during the first execution of Message1 + Message3 the agent executed collection.MarkAsConsumed(Message1). In this case the third execution Message1 + Message5 would not have happened, as Message1 would have been cleared from the collector instance.

    Constructors

    | Improve this Doc View Source

    MessageCollector(Action<MessageCollection<T1, T2, T3>>)

    Declaration
    public MessageCollector(Action<MessageCollection<T1, T2, T3>> onMessagesCollected = null)
    Parameters
    Type Name Description
    Action<MessageCollection<T1, T2, T3>> onMessagesCollected

    Properties

    | Improve this Doc View Source

    Messages3

    Store for messages of type T3.

    Declaration
    protected ConcurrentDictionary<MessageDomain, MessageStore<T3>> Messages3 { get; }
    Property Value
    Type Description
    ConcurrentDictionary<MessageDomain, MessageStore<T3>>

    Methods

    | Improve this Doc View Source

    Aggregate(Message, Boolean)

    Overridden by inheriting classes to try to add the message to the collector dictionaries.

    Declaration
    protected override bool Aggregate(Message message, bool throwError)
    Parameters
    Type Name Description
    Message message

    The message to add

    Boolean throwError

    If set to true, throws an error if the message could not be added.

    Returns
    Type Description
    Boolean

    true if the message was added to any dictionary; otherwise false.

    Overrides
    Agents.Net.MessageCollector<T1, T2>.Aggregate(Agents.Net.Message, System.Boolean)
    | Improve this Doc View Source

    Execute(MessageCollection)

    Overridden by inheriting classes to execute the typeless message collection cast to the specific collector type..

    Declaration
    protected override void Execute(MessageCollection messageCollection)
    Parameters
    Type Name Description
    MessageCollection messageCollection

    The typeless collection.

    Overrides
    Agents.Net.MessageCollector<T1, T2>.Execute(Agents.Net.MessageCollection)
    | Improve this Doc View Source

    IsCompleted(MessageDomain, out MessageCollection)

    Overridden by inheriting classes to see if there is a completed set for the specified domain.

    Declaration
    protected override bool IsCompleted(MessageDomain domain, out MessageCollection messageCollection)
    Parameters
    Type Name Description
    MessageDomain domain

    The domain which should be completed.

    MessageCollection messageCollection

    The message collection with the complete set.

    Returns
    Type Description
    Boolean

    true if there is a completed set; otherwise false

    Overrides
    Agents.Net.MessageCollector<T1, T2>.IsCompleted(Agents.Net.MessageDomain, Agents.Net.MessageCollection)
    | Improve this Doc View Source

    PushAndContinue(Message, Action<MessageCollection<T1, T2, T3>>, CancellationToken)

    Add a message to the collector and continue with the specified action once when the set is found.

    Declaration
    public void PushAndContinue(Message message, Action<MessageCollection<T1, T2, T3>> onCollected, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    Message message

    The message which is added to the collector.

    Action<MessageCollection<T1, T2, T3>> onCollected

    The action which is executed when the complete set is found.

    CancellationToken cancellationToken

    Cancellation token to stop the continue operation.

    | Improve this Doc View Source

    PushAndExecute(Message, Action<MessageCollection<T1, T2, T3>>, CancellationToken)

    Add a message to the collector and wait of the complete set to execute the specified action.

    Declaration
    public bool PushAndExecute(Message message, Action<MessageCollection<T1, T2, T3>> onCollected, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    Message message

    The message which is added to the collector.

    Action<MessageCollection<T1, T2, T3>> onCollected

    The action which is executed when the complete set is found.

    CancellationToken cancellationToken

    Cancellation token to stop the wait operation.

    Returns
    Type Description
    Boolean

    true if the action was executed; otherwise false.

    Remarks

    This method is helpful for InterceptorAgents where the agent in the InterceptCore(Message) method must wait for a set of message before returning the InterceptionAction.

    Another example is when the InterceptorAgent wants to wait on a single message. In this case the first message is the message that is intercepted. The second message is the message the agent needs. The advantage is, that the collector respects message domains.

    | Improve this Doc View Source

    RemoveMessage(Message)

    Overriden by inheriting classes to remove the message passed to the method.

    Declaration
    protected override void RemoveMessage(Message message)
    Parameters
    Type Name Description
    Message message

    The message to remove from the collector.

    Overrides
    Agents.Net.MessageCollector<T1, T2>.RemoveMessage(Agents.Net.Message)
    • Improve this Doc
    • View Source
    In This Article
    Back to top © Copyright Tobias Wilker and contributors