public abstract class MessageDecorator<T> extends Object implements Message<T>
Message
that delegates to an existing message. Extend this decorator class to
extend the message with additional features.Modifier | Constructor and Description |
---|---|
protected |
MessageDecorator(Message<T> delegate)
Initializes a new decorator with given
delegate message. |
Modifier and Type | Method and Description |
---|---|
protected void |
describeTo(StringBuilder stringBuilder)
Describe the message specific properties to the given
stringBuilder . |
protected String |
describeType()
Describe the type of message, used in
toString() . |
protected Message<T> |
getDelegate()
Returns the wrapped message delegate.
|
String |
getIdentifier()
Returns the identifier of this message.
|
MetaData |
getMetaData()
Returns the meta data for this message.
|
T |
getPayload()
Returns the payload of this message.
|
Class<T> |
getPayloadType()
Returns the type of the payload.
|
<S> SerializedObject<S> |
serializeMetaData(Serializer serializer,
Class<S> expectedRepresentation)
Serialize the meta data of this message to the
expectedRepresentation using given serializer . |
<S> SerializedObject<S> |
serializePayload(Serializer serializer,
Class<S> expectedRepresentation)
Serialize the payload of this message to the
expectedRepresentation using given serializer . |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
andMetaData, withMetaData
public String getIdentifier()
Message
getIdentifier
in interface Message<T>
public MetaData getMetaData()
Message
getMetaData
in interface Message<T>
public T getPayload()
Message
getPayload
in interface Message<T>
public Class<T> getPayloadType()
Message
getPayload().getClass()
, but allows implementations to optimize by using lazy
loading or deserialization.getPayloadType
in interface Message<T>
public <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation)
Message
expectedRepresentation
using given serializer
. This
method should return the same SerializedObject instance when invoked multiple times using the same
serializer.serializePayload
in interface Message<T>
S
- The type of the serialized dataserializer
- The serializer to serialize payload withexpectedRepresentation
- The type of data to serialize topublic <S> SerializedObject<S> serializeMetaData(Serializer serializer, Class<S> expectedRepresentation)
Message
expectedRepresentation
using given serializer
.
This method should return the same SerializedObject instance when invoked multiple times using the same
serializer.serializeMetaData
in interface Message<T>
S
- The type of the serialized dataserializer
- The serializer to serialize meta data withexpectedRepresentation
- The type of data to serialize toprotected Message<T> getDelegate()
protected void describeTo(StringBuilder stringBuilder)
stringBuilder
. Subclasses should override this
method, calling the super method and appending their own properties to the end (or beginning).
As convention, String values should be enclosed in single quotes, Objects in curly brackets and numeric values may be appended without enclosing. All properties should be preceded by a comma when appending, or finish with a comma when prefixing values.
stringBuilder
- the builder to append data toprotected String describeType()
toString()
.
Defaults to the simple class name of the actual instance.
Copyright © 2010–2024. All rights reserved.