Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rice.pastry.socket
Class SocketChannelWriter

    java.lang.Object
      rice.pastry.socket.SocketChannelWriter

    public class SocketChannelWriter

extends java.lang.Object

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.

Version:
  $Id: SocketChannelWriter.java,v 1.5 2004/03/08 19:53:57 amislove Exp $
Author:
  Alan Mislove

Field Summary
`protected Environment` | `environment` DESCRIBE THE FIELD
`protected Logger` | `logger` DESCRIBE THE FIELD
`protected SourceRoute` | `path` DESCRIBE THE FIELD

Constructor Summary
`SocketChannelWriter(Environment env, SourceRoute path)` Constructor for SocketChannelWriter.
`SocketChannelWriter(SocketPastryNode spn, SourceRoute path)` Constructor which creates this SocketChannelWriter with a pastry node and an object to write out.

Method Summary
`boolean` | `enqueue(byte[] msg)` DESCRIBE THE METHOD
`boolean` | `enqueue(Message msg)` DESCRIBE THE METHOD
`boolean` | `enqueue(SocketBuffer 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
`boolean` | `isEmpty()` Returns whether or not there are objects in the queue on in writing.
`void` | `reset()` Returns the queue of writes for the remote address
`protected void` | `setPath(SourceRoute path)` Sets this writer's path
`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

### path

    protected SourceRoute path

  DESCRIBE THE FIELD

### environment

    protected Environment environment

  DESCRIBE THE FIELD

### logger

    protected Logger logger

  DESCRIBE THE FIELD

Constructor Detail

### SocketChannelWriter

    public SocketChannelWriter(SocketPastryNode spn,
                               SourceRoute path)

  Constructor which creates this SocketChannelWriter with a pastry node and an object to write out.

  Parameters:
    `spn` - The spn the SocketChannelWriter servers
    `path` - DESCRIBE THE PARAMETER

### SocketChannelWriter

    public SocketChannelWriter(Environment env,
                               SourceRoute path)

  Constructor for SocketChannelWriter.

  Parameters:
    `env` - DESCRIBE THE PARAMETER
    `path` - DESCRIBE THE PARAMETER

Method Detail

### isEmpty

    public boolean isEmpty()

  Returns whether or not there are objects in the queue on in writing. If the result is true, it the safe to mark the SelectionKey as not being interested in writing.

  Returns:
    Whether or not there are objects still to be written.

### getQueue

    public java.util.LinkedList getQueue()

  Returns the queue of writes for the remote address

  Returns:
    the queue of writes for the remote address

### setPath

    protected void setPath(SourceRoute path)

  Sets this writer's path

  Parameters:
    `path` - The path this writer is using

### enqueue

    public boolean enqueue(Message msg)
                    throws java.io.IOException

  DESCRIBE THE METHOD

  Parameters:
    `msg` - DESCRIBE THE PARAMETER
  Returns:
    DESCRIBE THE RETURN VALUE
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### enqueue

    public boolean enqueue(byte[] msg)

  DESCRIBE THE METHOD

  Parameters:
    `msg` - DESCRIBE THE PARAMETER
  Returns:
    DESCRIBE THE RETURN VALUE

### enqueue

    public boolean enqueue(SocketBuffer o)

  Adds an object to this SocketChannelWriter's queue of pending objects to write. This methos is synchronized and therefore safe for use by multiple threads.

  Parameters:
    `o` - The object to be written.
  Returns:
    DESCRIBE THE RETURN VALUE

### reset

    public void reset()

  Returns the queue of writes for the remote address

### write

    public boolean write(java.nio.channels.SocketChannel sc)
                  throws java.io.IOException

  Method which is designed to be called when this writer should write out its data. Returns whether or not the message was completely written. If false is returns, write() will need to be called again when the SocketChannel is ready for data to be written.

  Parameters:
    `sc` - The SocketChannel to write to
  Returns:
    true if this output stream is done, false otherwise
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.