Class MessageDecorator
The base class for message decorators.
Implements
Inherited Members
Namespace: Agents.Net
Assembly: Agents.Net.dll
Syntax
public abstract class MessageDecorator : Message, IDisposable
Remarks
This class is the only way to build a hierarchy of messages. This can be done with an InterceptorAgent or by the message producing agent itself.
When using Get<T>() the whole hierarchy of message decorators is searched for the specific message type.
Examples
This is the recommended way of writing a message decorator:
public class SpecificMessageDecorator : MessageDecorator
{
private SpecificMessageDecorator(Message decoratedMessage, IEnumerable<Message> additionalPredecessors = null) :
base(decoratedMessage, additionalPredecessors)
{
}
public static SpecificMessageDecorator Decorate(DecoratedMessage declaredMessage, IEnumerable<Message> additionalPredecessors = null)
{
return new SpecificMessageDecorator(declaredMessage);
}
protected override string DataToString()
{
//maybe log additional data
}
}
//Used in client code like this:
SpecificMessageDecorator.Decorate(decoratedMessage);
Constructors
| Improve this Doc View SourceMessageDecorator(Message, IEnumerable<Message>)
Initializes a new instance of MessageDecorator
Declaration
protected MessageDecorator(Message decoratedMessage, IEnumerable<Message> additionalPredecessors = null)
Parameters
Type | Name | Description |
---|---|---|
Message | decoratedMessage | The message that should be decorated. |
IEnumerable<Message> | additionalPredecessors | The |
Remarks
The decoratedMessage
is not necessarily the direct Agents.Net.Message.Child of this message, as it is undetermined which message decorator comes first when two decorators are applied at the same time. But it is thread safe to do so.
Methods
| Improve this Doc View SourceIsDecorated(Message)
Checks whether the message
is a decorated message or not.
Declaration
public static bool IsDecorated(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to check. |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
An example when this method can be used is shown in the FileManipulationBenchmark benchmark test.