N
- The kind of node that can send messages of this type.R
- The response typeE
- The exception type that may occur at the remote node while handling
the message.public abstract class Message<R extends Message.Response,E extends FabricException>
extends java.lang.Object
Message
class itself provides facilities for serialization and
deserialization, while the concrete subclasses give the structure of each
type of message.
Messages are intended to be used in a synchronous, call-return style. To
support this, each Message type is bound to a specific Response type. On the
sender side, this allows type safety in the send
method, for
example:
ReadMessage.Response r = new ReadMessage(...).send(...);while on the receiver side, type safety is enforced by only accepting
R
in the respond(...)
method.
Messages use two instances of the visitor pattern, one for Messages bound for
the store (MessageToStore
) and one for Messages bound for the worker
(MessageToWorker
). These interfaces would be subclasses of
Message
, except that some message types (e.g.
CommitTransactionMessage
) go to both, and Java doesn't support
multiple inheritance.
Modifier and Type | Class and Description |
---|---|
protected static class |
Message.MessageType
This enum gives a mapping between message types and ordinals.
|
static class |
Message.NoException
Concrete message implementations may use this class to indicate that no
exceptions should be thrown during message processing.
|
static interface |
Message.Response
Marker interface for Message responses.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.Class<E> |
exceptionClass
The class of Exceptions that may be thrown in response to this Message
|
protected Message.MessageType |
messageType
The
MessageType corresponding to this class. |
Modifier | Constructor and Description |
---|---|
protected |
Message(Message.MessageType messageType,
java.lang.Class<E> exceptionClass)
Constructs a message of the given
MessageType |
Modifier and Type | Method and Description |
---|---|
abstract R |
dispatch(RemoteIdentity<RemoteWorker> client,
MessageHandler handler)
Visitor method.
|
protected <T> T |
readObject(java.io.DataInput in,
java.lang.Class<T> type)
Deserialize a java object from a DataOutput
|
protected static Object._Proxy |
readRef(java.lang.Class<?> type,
java.io.DataInput in)
Deserializes a fabric object reference.
|
protected abstract R |
readResponse(java.io.DataInput in)
Creates a Response message of the appropriate type using the provided
DataOutput |
static Message<?,?> |
receive(java.io.DataInput in)
Read a Message from the given
DataInput |
void |
respond(java.io.DataOutput out,
FabricException e)
Send a response to this message that indicates an exception.
|
void |
respond(java.io.DataOutput out,
Message.Response response)
Send a successful response this message.
|
R |
send(SubSocket<?> s)
Sends this message to the given node and awaits a response.
|
protected abstract void |
writeMessage(java.io.DataOutput out)
Writes this message out on the given output stream.
|
protected void |
writeObject(java.io.DataOutput out,
java.lang.Object o)
Serialize a java object to a DataOutput
|
protected void |
writeRef(Object._Proxy ref,
java.io.DataOutput out)
Serializes a fabric object reference.
|
protected abstract void |
writeResponse(java.io.DataOutput out,
R response)
Writes a Response message of the appropriate type using the provided
DataOutput . |
protected final Message.MessageType messageType
MessageType
corresponding to this class.protected final java.lang.Class<E extends FabricException> exceptionClass
protected Message(Message.MessageType messageType, java.lang.Class<E> exceptionClass)
MessageType
exceptionClass
- TODOexceptionClass
- TODOpublic final R send(SubSocket<?> s) throws java.io.IOException, E extends FabricException
E
- if an error occurs at the remote node while handling the message.java.io.IOException
- in the event of a communications failure.E extends FabricException
public abstract R dispatch(RemoteIdentity<RemoteWorker> client, MessageHandler handler) throws ProtocolError, E extends FabricException
client
- the node that is issuing the request.handler
- the handler to which this message is to be dispatched.ProtocolError
E extends FabricException
public static Message<?,?> receive(java.io.DataInput in) throws java.io.IOException
DataInput
java.io.IOException
- If a malformed message is sent, or in the case of a failure in
the DataInput
provided.public void respond(java.io.DataOutput out, Message.Response response) throws java.io.IOException
out
- the channel on which to send the responseresponse
- the response to send.java.io.IOException
- if the provided DataOutput
fails.public void respond(java.io.DataOutput out, FabricException e) throws java.io.IOException
out
- the channel on which to send the responsee
- the exception to sendjava.io.IOException
- if the provided DataOutput
fails.protected void writeRef(Object._Proxy ref, java.io.DataOutput out) throws java.io.IOException
java.io.IOException
protected static Object._Proxy readRef(java.lang.Class<?> type, java.io.DataInput in) throws java.io.IOException
type
- The type of the reference being read. This must be the interface
corresponding to the Fabric type, and not the _Proxy or _Impl
classes.java.io.IOException
protected void writeObject(java.io.DataOutput out, java.lang.Object o) throws java.io.IOException
java.io.IOException
protected <T> T readObject(java.io.DataInput in, java.lang.Class<T> type) throws java.io.IOException
java.io.IOException
protected abstract void writeMessage(java.io.DataOutput out) throws java.io.IOException
java.io.IOException
- if the DataOutput
fails.protected abstract R readResponse(java.io.DataInput in) throws java.io.IOException
DataOutput
java.io.IOException
- if the response is malformed, or if the DataInput
fails.protected abstract void writeResponse(java.io.DataOutput out, R response) throws java.io.IOException
DataOutput
.java.io.IOException
- if the DataOutput
fails.