public class Message extends java.lang.Object implements MessageTypes, java.io.Externalizable
Each message has a type (MessageTypes
) which defines the how the
message is to be treated.
Synchronous uses of the protocol (e.g. for a remote object or remote procedure call implementation) us the request ID field. This is an integer code used to match requests and replies.
There is always a RoutingKey
which specifies the destination.
There is a Serializable
(or Externalizable
)
payload for each message. This should not be null
but to
simulate a null
payload, one can use the following (a zero
sized array of objects):
new Object[] {}
Implementing your payload completely as an Externalizable
is
highly recommended as it will improve performance.
Modifier and Type | Field and Description |
---|---|
private RoutingKey |
key
Routing and requested method information.
|
private java.io.Serializable |
payload
Message payload.
|
private int |
requestID
Request ID (only used with a synchronous request/reply).
|
private int |
type
Message type.
|
ADDRESS_REPLY, ADDRESS_REQUEST, BEGIN_REPLY, ECHO, ECHO_REPLY, END_REPLY, INIT_CONVERSATION, INIT_REPLY, INIT_ROUTER, INIT_STANDARD, REPLY_ASYNC, REPLY_EXCEPTION_ASYNC, REPLY_EXCEPTION_SYNC, REPLY_SYNC, REQUEST_ASYNCH, REQUEST_SYNCH, UNKNOWN
Constructor and Description |
---|
Message()
Constructs an empty message.
|
Message(int type)
Constructs an empty message of specified type.
|
Message(int type,
int requestID,
RoutingKey key,
java.io.Serializable payload)
Constructs a complete message.
|
Message(int type,
RoutingKey key,
java.io.Serializable payload)
Constructs a message of specified type with specified
RoutingKey and payload. |
Message(int type,
java.io.Serializable payload)
Constructs a message of specified type and with provided payload.
|
Message(Message msg)
Copy constructor.
|
Message(RoutingKey key,
java.io.Serializable payload)
Constructs a synchronous request message with specified
RoutingKey and payload. |
Modifier and Type | Method and Description |
---|---|
RoutingKey |
getKey()
Get
RoutingKey instance assigned to message. |
java.io.Serializable |
getPayload()
Get the message payload.
|
int |
getRequestID()
Get the synchronous request ID.
|
int |
getType()
Get the message type.
|
boolean |
isAsyncReply()
Determine if the message is an async reply (the type is
MessageTypes.REPLY_ASYNC ,
MessageTypes.REPLY_EXCEPTION_ASYNC or the routing key is part of the
RoutingKey.INTERRUPT_SESSION group). |
boolean |
isAsyncRequest()
Determine if the message is an async request (the type is
MessageTypes.REQUEST_ASYNCH
or the routing key is part of the RoutingKey.INTERRUPT_SESSION group). |
boolean |
isDispatcherRequest()
Determine if the message is one of the types processed by the
Dispatcher . |
boolean |
isEchoRequest()
Check if message is an ECHO request.
|
boolean |
isReply()
Determine if message is a reply (
ADDRESS_REPLY, ECHO_REPLY,
INIT_REPLY, REPLY, REPLY_EXCEPTION ). |
boolean |
isRouterRequest()
Determine if the message is one of types which are processed by the
Router . |
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
void |
setKey(RoutingKey key)
Assign
RoutingKey to the message. |
void |
setPayload(java.io.Serializable payload)
Assign new payload to the message.
|
void |
setRequestID(int requestID)
Assigns synchronous request ID to message.
|
void |
setType(int type)
Change message type to specified one.
|
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
private int type
private int requestID
private RoutingKey key
private java.io.Serializable payload
public Message()
RoutingKey
instance should be assigned to the
message before it can be sent.public Message(int type)
RoutingKey
instance should be assigned to the message
before it can be sent.type
- Message type.public Message(int type, int requestID, RoutingKey key, java.io.Serializable payload)
type
- Message type.requestID
- Synchronous request ID assigned to message.key
- An instance of RoutingKey
which points to
required entry point/node.payload
- Message payload.public Message(int type, RoutingKey key, java.io.Serializable payload)
RoutingKey
and payload.type
- Message type.key
- An instance of RoutingKey
which points to
required entry point/node.payload
- Message payload.public Message(int type, java.io.Serializable payload)
RoutingKey
instance should be assigned to the
message before it can be sent.type
- Message type.payload
- Message payload.public Message(RoutingKey key, java.io.Serializable payload)
RoutingKey
and payload.key
- An instance of RoutingKey
which points to
required entry point/node.payload
- Message payload.public Message(Message msg)
msg
- Message to copy. Must not be null
.public RoutingKey getKey()
RoutingKey
instance assigned to message.public java.io.Serializable getPayload()
public int getRequestID()
public int getType()
public boolean isDispatcherRequest()
Dispatcher
.true
if the message must be processed by the
Dispatcher
.public boolean isEchoRequest()
true
if the message has type ECHO
.public boolean isReply()
ADDRESS_REPLY, ECHO_REPLY,
INIT_REPLY, REPLY, REPLY_EXCEPTION
).true
if the message is any form of reply.public boolean isAsyncReply()
MessageTypes.REPLY_ASYNC
,
MessageTypes.REPLY_EXCEPTION_ASYNC
or the routing key is part of the
RoutingKey.INTERRUPT_SESSION
group).true
if the message is an async reply.public boolean isAsyncRequest()
MessageTypes.REQUEST_ASYNCH
or the routing key is part of the RoutingKey.INTERRUPT_SESSION
group).true
if the message is an async reply.public boolean isRouterRequest()
Router
.true
if the message must be processed by the
Router
.public void setKey(RoutingKey key)
RoutingKey
to the message.key
- New instance of RoutingKey
.public void setPayload(java.io.Serializable payload)
payload
- New message payload.public void setRequestID(int requestID)
requestID
- New synchronous request ID.public void setType(int type)
type
- New message type.public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
RoutingKey
instance for the
key
it is explicitly instantiated and then its fields are
restored by calling the appropriate method.readExternal
in interface java.io.Externalizable
in
- The input source from which fields will be restored.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
key
as an ordinary object, it's saved by calling
appropriate method. This can be done because there is no need to save
type information in the stream so we can save few bytes of packet size.writeExternal
in interface java.io.Externalizable
out
- The output destination to which fields will be saved.java.io.IOException
- In case of I/O errors.