org.axonframework.serializer
Class SerializationAwareDomainEventMessage<T>

java.lang.Object
  extended by org.axonframework.serializer.SerializationAwareEventMessage<T>
      extended by org.axonframework.serializer.SerializationAwareDomainEventMessage<T>
Type Parameters:
T - The payload type of the Message
All Implemented Interfaces:
Serializable, DomainEventMessage<T>, EventMessage<T>, Message<T>, SerializationAware

public class SerializationAwareDomainEventMessage<T>
extends SerializationAwareEventMessage<T>
implements DomainEventMessage<T>

Wrapper around a DomainEventMessage that adds "Serialization Awareness" to the message it wraps. This implementation ensures that, when the payload or meta data is being serialized more than once using the same serializer, only a single serialization will actually occur. Subsequent invocations will return the same SerializedObject instance as the first.

Since:
2.0
Author:
Allard Buijze
See Also:
Serialized Form

Constructor Summary
protected SerializationAwareDomainEventMessage(DomainEventMessage<T> message)
          Initialize a new wrapper for the given message.
 
Method Summary
 DomainEventMessage<T> andMetaData(Map<String,?> metaData)
          Returns a copy of this EventMessage with it MetaData merged with the given metaData.
 Object getAggregateIdentifier()
          Returns the identifier of the Aggregate that generated this DomainEvent.
 long getSequenceNumber()
          Returns the sequence number that allows DomainEvents originating from the same Aggregate to be placed in the order of generation.
 DomainEventMessage<T> withMetaData(Map<String,?> metaData)
          Returns a copy of this EventMessage with the given metaData.
static
<T> DomainEventMessage<T>
wrap(DomainEventMessage<T> message)
          Wrap the given message to make it SerializationAware.
protected  Object writeReplace()
          Replacement function for Java Serialization API.
 
Methods inherited from class org.axonframework.serializer.SerializationAwareEventMessage
getIdentifier, getMetaData, getPayload, getPayloadType, getTimestamp, serializeMetaData, serializePayload, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axonframework.domain.EventMessage
getIdentifier, getTimestamp
 
Methods inherited from interface org.axonframework.domain.Message
getMetaData, getPayload, getPayloadType
 

Constructor Detail

SerializationAwareDomainEventMessage

protected SerializationAwareDomainEventMessage(DomainEventMessage<T> message)
Initialize a new wrapper for the given message.

Parameters:
message - The message to wrap
Method Detail

wrap

public static <T> DomainEventMessage<T> wrap(DomainEventMessage<T> message)
Wrap the given message to make it SerializationAware. The returning object can be safely cast to SerializationAware. If the given message already implements SerializationAware, it is returned as-is. It is therefore not safe to assume the returning message is an instance of SerializationAwareDomainEventMessage.

Type Parameters:
T - The payload type of the message
Parameters:
message - The message to wrap
Returns:
a serialization aware version of the given message

getSequenceNumber

public long getSequenceNumber()
Description copied from interface: DomainEventMessage
Returns the sequence number that allows DomainEvents originating from the same Aggregate to be placed in the order of generation.

Specified by:
getSequenceNumber in interface DomainEventMessage<T>
Returns:
the sequence number of this Event

getAggregateIdentifier

public Object getAggregateIdentifier()
Description copied from interface: DomainEventMessage
Returns the identifier of the Aggregate that generated this DomainEvent. Note that the value returned does not necessarily have to be the same instance that was provided at creation time. It is possible that (due to serialization, for example) the value returned here has a different structure.

Specified by:
getAggregateIdentifier in interface DomainEventMessage<T>
Returns:
the identifier of the Aggregate that generated this DomainEvent

withMetaData

public DomainEventMessage<T> withMetaData(Map<String,?> metaData)
Description copied from interface: EventMessage
Returns a copy of this EventMessage with the given metaData. The payload, Timestamp and Identifier remain unchanged.

Specified by:
withMetaData in interface DomainEventMessage<T>
Specified by:
withMetaData in interface EventMessage<T>
Specified by:
withMetaData in interface Message<T>
Overrides:
withMetaData in class SerializationAwareEventMessage<T>
Parameters:
metaData - The new MetaData for the Message
Returns:
a copy of this message with the given MetaData

andMetaData

public DomainEventMessage<T> andMetaData(Map<String,?> metaData)
Description copied from interface: EventMessage
Returns a copy of this EventMessage with it MetaData merged with the given metaData. The payload, Timestamp and Identifier remain unchanged.

Specified by:
andMetaData in interface DomainEventMessage<T>
Specified by:
andMetaData in interface EventMessage<T>
Specified by:
andMetaData in interface Message<T>
Overrides:
andMetaData in class SerializationAwareEventMessage<T>
Parameters:
metaData - The MetaData to merge with
Returns:
a copy of this message with the given MetaData

writeReplace

protected Object writeReplace()
Replacement function for Java Serialization API. When this object is serialized, it is replaced by the implementation it wraps.

Overrides:
writeReplace in class SerializationAwareEventMessage<T>
Returns:
the DomainEventMessage wrapped by this message


Copyright © 2010-2016. All Rights Reserved.