|
Rice Pastry API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--rice.pastry.wire.SocketChannelWriter
Class which serves as an "writer" for all of the messages sent across the wire in Pastry. This class serializes and properly formats all messages, and then waits to be called with an available SocketChannel in order to write the message out. If the messagae could not be written in one go, subsequent calls to the write() method will finish writing out the message. This class also maintains an internal queue of messages waiting to be sent across the wire. Calling isEmpty() will tell clients if it is safe to mark the SelectionKey as not being interested in writing.
Field Summary | |
protected static byte[] |
MAGIC_NUMBER
|
static int |
MAXIMUM_QUEUE_LENGTH
|
Constructor Summary | |
SocketChannelWriter(rice.pastry.wire.WirePastryNode spn,
rice.pastry.wire.messaging.socket.SocketCommandMessage msg)
Constructor which creates this SocketChannelWriter with a pastry node and an object to write out. |
Method Summary | |
void |
enqueue(java.lang.Object o)
Adds an object to this SocketChannelWriter's queue of pending objects to write. |
java.util.LinkedList |
getQueue()
Returns the queue of writes for the remote address |
void |
greetingReceived()
|
boolean |
isEmpty()
Returns whether or not there are objects in the queue on in writing. |
void |
reset(rice.pastry.wire.messaging.socket.SocketCommandMessage msg)
Resets the SocketChannelWriter, by clearing both the buffer and the queue. |
static java.nio.ByteBuffer |
serialize(java.lang.Object o)
Method which serializes a given object into a ByteBuffer, in order to prepare it for writing. |
boolean |
write(java.nio.channels.SocketChannel sc)
Method which is designed to be called when this writer should write out its data. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int MAXIMUM_QUEUE_LENGTH
protected static byte[] MAGIC_NUMBER
Constructor Detail |
public SocketChannelWriter(rice.pastry.wire.WirePastryNode spn, rice.pastry.wire.messaging.socket.SocketCommandMessage msg)
spn
- The PastryNode the SocketChannelWriter serversMethod Detail |
public void enqueue(java.lang.Object o)
o
- The object to be written.public boolean isEmpty()
public java.util.LinkedList getQueue()
public void reset(rice.pastry.wire.messaging.socket.SocketCommandMessage msg)
msg
- The greeting message that should be enqueued firstpublic void greetingReceived()
public boolean write(java.nio.channels.SocketChannel sc) throws java.io.IOException
sc
- The SocketChannel to write to
java.io.IOException
public static java.nio.ByteBuffer serialize(java.lang.Object o) throws java.io.IOException
o
- The object to serialize
java.io.IOException
|
Rice Pastry API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |