Search Results for

    Show / Hide Table of Contents

    Class MessageAggregator<T>

    This class is deprecated. Please use MessageGate<TStart, TEnd> instead.

    Inheritance
    Object
    MessageAggregator<T>
    Namespace: Agents.Net
    Assembly: Agents.Net.dll
    Syntax
    public class MessageAggregator<T> : object where T : Message
    Type Parameters
    Name Description
    T

    The type of the message which should be aggregated.

    Remarks

    When a batch of messages is published using the OnMessages(IReadOnlyCollection<Message>) they can be united again when all last messages of the execution chain are of the same type.

     --------------         ---------------------          -----------------
    | SplitMessage | ----> | IntermediateMessage | -----> | FinishedMessage |
     --------------         ---------------------  |       -----------------
                                                   |
                                                   |       ------------------
                                                    ----> | ExceptionMessage |
                                                           ------------------

    Looking at the example above it would not be possible to unite the SplitMessages again using this class as at least one IntermediateMessage let to an ExceptionMessage.

    Here a typical example how to setup and use the aggregator in a class:
    [Consumes(typeof(FinishedMessage))]
    public class MessageAggregatorAgent : Agent
    {
        private readonly MessageAggregator<FinishedMessage> aggregator;
    
    public MessageAggregatorAgent(IMessageBoard messageBoard) : base(messageBoard)
    {
        aggregator = new MessageAggregator&lt;FinishedMessage>(OnAggregated);
    }
    
    private void OnAggregated(IReadOnlyCollection&lt;FinishedMessage> aggregate)
    {
        //Execute your code here
    }
    
    protected override void ExecuteCore(Message messageData)
    {
        aggregator.Aggregate(messageData);
    }
    

    }

    Constructors

    | Improve this Doc View Source

    MessageAggregator(Action<IReadOnlyCollection<T>>, Boolean)

    Initialized a new instance of the class MessageAggregator<T>.

    Declaration
    public MessageAggregator(Action<IReadOnlyCollection<T>> onAggregated, bool autoTerminate = true)
    Parameters
    Type Name Description
    Action<IReadOnlyCollection<T>> onAggregated

    The action which is executed when all messages were aggregated.

    Boolean autoTerminate

    If set to true, the aggregator will terminate all message domains of the aggregated messages before the execution. Default is true.

    Methods

    | Improve this Doc View Source

    Aggregate(Message)

    Adds the message to this instance.

    Declaration
    public void Aggregate(Message message)
    Parameters
    Type Name Description
    Message message

    The message to add to this instance.

    | Improve this Doc View Source

    TryAggregate(Message)

    Tries to add the message to this instance.

    Declaration
    public bool TryAggregate(Message message)
    Parameters
    Type Name Description
    Message message

    The message to add to this instance.

    Returns
    Type Description
    Boolean

    true if the message was added; otherwise false

    Remarks

    This is useful, when the Agent consumes more than the aggregated message.

    • Improve this Doc
    • View Source
    In This Article
    Back to top © Copyright Tobias Wilker and contributors