fabric.messages
Class Message<N extends RemoteNode,R extends Message.Response>

java.lang.Object
  extended by fabric.messages.Message<N,R>
Type Parameters:
N - The class of nodes to which messages of this type may be sent.
R - The class of responses.
Direct Known Subclasses:
AbortTransactionMessage, AllocateMessage, CommitTransactionMessage, DissemReadMessage, GetCertificateChainMessage, InterWorkerMessage, ObjectUpdateMessage, PrepareTransactionMessage, ReadMessage, StalenessCheckMessage, UnauthenticatedAbortTransactionMessage, UnauthenticatedCommitTransactionMessage, UnauthenticatedPrepareTransactionMessage

public abstract class Message<N extends RemoteNode,R extends Message.Response>
extends java.lang.Object


Nested Class Summary
protected static class Message.MessageType
           
static interface Message.Response
           
 
Field Summary
protected  Message.MessageType messageType
          The MessageType corresponding to this class.
 
Constructor Summary
protected Message(Message.MessageType messageType)
           
 
Method Summary
 R dispatch(MessageHandlerThread handler)
          Calls the appropriate handle(...) method on the handler.
 R dispatch(MessageHandlerThread handler)
          Calls the appropriate handle(...) method on the handler.
static void receive(java.io.DataInput in, java.io.DataOutputStream out, MessageHandler handler)
          This reads a Message from the provided input stream, dispatches it to the given MessageHandler, and writes the response to the provided OutputStream.
abstract  R response(N node, java.io.DataInput in)
          Creates a Response message of the appropriate type using the provided input stream.
protected  R send(N node, boolean useSSL)
          Sends this message to the given node.
abstract  void write(java.io.DataOutput out)
          Writes this message out on the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageType

protected final Message.MessageType messageType
The MessageType corresponding to this class.

Constructor Detail

Message

protected Message(Message.MessageType messageType)
Method Detail

send

protected final R send(N node,
                       boolean useSSL)
                                         throws FabricException
Sends this message to the given node.

Returns:
The reply from the node.
Throws:
FabricException - if an error occurs at the remote node while handling the message.

receive

public static void receive(java.io.DataInput in,
                           java.io.DataOutputStream out,
                           MessageHandler handler)
                    throws java.io.IOException
This reads a Message from the provided input stream, dispatches it to the given MessageHandler, and writes the response to the provided OutputStream. Used only by the store.

Parameters:
in - The input stream to read the incoming message from.
out - The output stream to write the result to.
handler - The handler that will handle the message and generate the response
Throws:
java.io.IOException - If a malformed message is sent, or in the case of a failure in the i/o streams provided.
java.lang.ClassNotFoundException

dispatch

public R dispatch(MessageHandlerThread handler)
                                    throws FabricException
Calls the appropriate handle(...) method on the handler.

Parameters:
handler -
Returns:
the result computed by the handler
Throws:
FabricException

dispatch

public R dispatch(MessageHandlerThread handler)
                                    throws FabricException
Calls the appropriate handle(...) method on the handler.

Parameters:
handler -
Returns:
the result computed by the handler
Throws:
FabricException

response

public abstract R response(N node,
                           java.io.DataInput in)
                                             throws java.io.IOException,
                                                    FabricException
Creates a Response message of the appropriate type using the provided input stream.

Parameters:
node - the remote node from which the response originated.
in - Input stream containing the message.
Returns:
A Response message with the appropriate type.
Throws:
java.io.IOException
FabricException

write

public abstract void write(java.io.DataOutput out)
                    throws java.io.IOException
Writes this message out on the given output stream. Only used by the worker.

Throws:
java.io.IOException - if the output stream throws an IOException.