Class Message<T extends WritableIdentifier,C extends Message<T,C>>
- java.lang.Object
-
- org.opendaylight.controller.cluster.access.concepts.Message<T,C>
-
- Type Parameters:
T
- Target identifier typeC
- Message type
- All Implemented Interfaces:
Serializable
,Immutable
,MutationBehaviour<Immutable>
@Beta public abstract class Message<T extends WritableIdentifier,C extends Message<T,C>> extends Object implements Immutable, Serializable
An abstract concept of a Message. This class cannot be instantiated directly, use its specializationsRequest
andResponse
.Messages have a target and a sequence number. Sequence numbers are expected to be assigned monotonically on a per-target basis, hence two targets can observe the same sequence number.
This class includes explicit versioning for forward- and backward- compatibility of serialization format. This is achieved by using the serialization proxy pattern. Subclasses are in complete control of what proxy is used to serialize a particular object on the wire. This class can serve as an explicit version marker, hence no further action is necessary in the deserialization path.
For the serialization path an explicit call from the user is required to select the appropriate serialization version. This is done via
toVersion(ABIVersion)
method, which should return a copy of this object with the requested ABI version recorded and should return the appropriate serialization proxy.This workflow allows least disturbance across ABI versions, as all messages not affected by a ABI version bump will remain working with the same serialization format for the new ABI version.
Note that this class specifies the
Immutable
contract, which means that all subclasses must follow this API contract.- Author:
- Robert Varga
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
Message.SerialForm<T extends WritableIdentifier,C extends Message<T,C>>
Externalizable proxy for use withMessage
subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected @NonNull MoreObjects.ToStringHelper
addToStringAttributes(@NonNull MoreObjects.ToStringHelper toStringHelper)
Add attributes to the output oftoString()
.protected abstract @NonNull C
cloneAsVersion(@NonNull ABIVersion targetVersion)
Create a copy of this message which will serialize to a stream corresponding to the specified method.protected abstract @NonNull Message.SerialForm<T,C>
externalizableProxy(@NonNull ABIVersion reqVersion)
Instantiate a serialization proxy for this object for the target ABI version.long
getSequence()
Get the logical sequence number.@NonNull T
getTarget()
Get the target identifier for this message.@NonNull ABIVersion
getVersion()
String
toString()
@NonNull C
toVersion(@NonNull ABIVersion toVersion)
Return a message which will end up being serialized in the specifiedABIVersion
.protected Object
writeReplace()
-
-
-
Method Detail
-
getTarget
public final @NonNull T getTarget()
Get the target identifier for this message.- Returns:
- Target identifier
-
getSequence
public final long getSequence()
Get the logical sequence number.- Returns:
- logical sequence number
-
getVersion
public final @NonNull ABIVersion getVersion()
-
toVersion
public final @NonNull C toVersion(@NonNull ABIVersion toVersion)
Return a message which will end up being serialized in the specifiedABIVersion
.- Parameters:
toVersion
- RequestABIVersion
- Returns:
- A new message which will use ABIVersion as its serialization.
-
cloneAsVersion
protected abstract @NonNull C cloneAsVersion(@NonNull ABIVersion targetVersion)
Create a copy of this message which will serialize to a stream corresponding to the specified method. This method should be implemented by the concrete final message class and should invoke the equivalent ofMessage(Message, ABIVersion)
.- Parameters:
targetVersion
- target ABI version- Returns:
- A message with the specified serialization stream
- Throws:
IllegalArgumentException
- if this message does not support the target ABI
-
addToStringAttributes
protected @NonNull MoreObjects.ToStringHelper addToStringAttributes(@NonNull MoreObjects.ToStringHelper toStringHelper)
Add attributes to the output oftoString()
. Subclasses wanting to contribute additional information should override this method. Any null attributes will be omitted from the output.- Parameters:
toStringHelper
- aMoreObjects.ToStringHelper
instance- Returns:
- The
MoreObjects.ToStringHelper
passed in as argument - Throws:
NullPointerException
- if toStringHelper is null
-
externalizableProxy
protected abstract @NonNull Message.SerialForm<T,C> externalizableProxy(@NonNull ABIVersion reqVersion)
Instantiate a serialization proxy for this object for the target ABI version. Implementations should return different objects for incompatibleABIVersion
s. This method should never fail, as any compatibility checks should have been done bycloneAsVersion(ABIVersion)
.- Parameters:
reqVersion
- Requested ABI version- Returns:
- Proxy for this object
-
writeReplace
protected final Object writeReplace()
-
-