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 SocketAppSocket

    java.lang.Object
      rice.selector.SelectionKeyHandler
          rice.pastry.socket.SocketAppSocket

All Implemented Interfaces:
  AppSocket

    public class SocketAppSocket

extends SelectionKeyHandler
implements AppSocket

Private class which is tasked with reading the greeting message off of a newly connected socket. This greeting message says who the socket is coming from, and allows the connected to hand the socket off the appropriate node handle.

Version:
  $Id: SocketCollectionManager.java 3061 2006-02-14 00:56:04Z jeffh $
Author:
  jeffh

Field Summary
`protected java.nio.channels.SocketChannel` | `channel`
`static byte` | `CONNECTION_NO_ACCEPTOR`
`static byte` | `CONNECTION_NO_APP`
`static byte` | `CONNECTION_OK`
`static byte` | `CONNECTION_UNKNOWN`
`static byte` | `CONNECTION_UNKNOWN_ERROR`
`protected java.nio.channels.SelectionKey` | `key`
`protected AppSocketReceiver` | `reader`
`protected AppSocketReceiver` | `receiver`
`protected AppSocketReceiver` | `writer`

Constructor Summary
`SocketAppSocket(SocketCollectionManager manager, java.nio.channels.SelectionKey key, int appId)` Constructor which accepts an incoming connection, represented by the selection key.
`SocketAppSocket(SocketCollectionManager manager, SourceRoute path, int appId, AppSocketReceiver receiver, int timeout)` Constructor which creates an outgoing connection to the given node handle using the provided address as a source route intermediate node.

Method Summary
`protected void` | `acceptConnection(java.nio.channels.SelectionKey key)` Accepts a new connection on the given key these methods (createConnection/acceptConnection) could be synchronized, but they are only called in the constructor who does not expose his reference.
`void` | `close()` Method which closes down this socket manager, by closing the socket, cancelling the key and setting the key to be interested in nothing
`void` | `connect(java.nio.channels.SelectionKey key)` Specified by the SelectionKeyHandler interface - calling this tells this socket manager that the connection has completed and we can now read/write.
`protected void` | `createConnection(SourceRoute path)` Creates the outgoing socket to the remote handle
`void` | `modifyKey(java.nio.channels.SelectionKey key)` Method which should change the interestOps of the handler's key.
`long` | `read(java.nio.ByteBuffer[] dsts, int offset, int length)` Reads a sequence of bytes from this channel into a subsequence of the given buffers.
`void` | `read(java.nio.channels.SelectionKey key)` Reads from the socket attached to this connector.
`void` | `register(boolean wantToRead, boolean wantToWrite, int timeout, AppSocketReceiver receiver)` Must be called every time a Read/Write occurs to continue operation.
`void` | `shutdownOutput()` Method which initiates a shutdown of this socket by calling shutdownOutput().
`java.lang.String` | `toString()`
`long` | `write(java.nio.ByteBuffer[] srcs, int offset, int length)` Writes a sequence of bytes to this channel from a subsequence of the given buffers.
`void` | `write(java.nio.channels.SelectionKey key)` Writes to the socket attached to this socket manager.

Methods inherited from class rice.selector.SelectionKeyHandler
`accept`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### CONNECTION_UNKNOWN_ERROR

    public static final byte CONNECTION_UNKNOWN_ERROR

See Also:
  Constant Field Values

### CONNECTION_UNKNOWN

    public static final byte CONNECTION_UNKNOWN

See Also:
  Constant Field Values

### CONNECTION_OK

    public static final byte CONNECTION_OK

See Also:
  Constant Field Values

### CONNECTION_NO_APP

    public static final byte CONNECTION_NO_APP

See Also:
  Constant Field Values

### CONNECTION_NO_ACCEPTOR

    public static final byte CONNECTION_NO_ACCEPTOR

See Also:
  Constant Field Values

### key

    protected java.nio.channels.SelectionKey key

### channel

    protected java.nio.channels.SocketChannel channel

### receiver

    protected AppSocketReceiver receiver

### reader

    protected AppSocketReceiver reader

### writer

    protected AppSocketReceiver writer

Constructor Detail

### SocketAppSocket

    public SocketAppSocket(SocketCollectionManager manager,
                           java.nio.channels.SelectionKey key,
                           int appId)
                    throws java.io.IOException

  Constructor which accepts an incoming connection, represented by the selection key. This constructor builds a new SocketManager, and waits until the greeting message is read from the other end. Once the greeting is received, the manager makes sure that a socket for this handle is not already open, and then proceeds as normal.

  Parameters:
    `key` - The server accepting key for the channel
    `manager` - TODO
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### SocketAppSocket

    public SocketAppSocket(SocketCollectionManager manager,
                           SourceRoute path,
                           int appId,
                           AppSocketReceiver receiver,
                           int timeout)
                    throws java.io.IOException

  Constructor which creates an outgoing connection to the given node handle using the provided address as a source route intermediate node. This creates the connection by building the socket and sending accross the greeting message. Once the response greeting message is received, everything proceeds as normal.

  Parameters:
    `manager` - TODO
    `address` - The ultimate destination of this socket
    `proxy` - The intermediate destination of this socket (if a source route)
  Throws:
    `java.io.IOException` - An error

Method Detail

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### shutdownOutput

    public void shutdownOutput()

  Method which initiates a shutdown of this socket by calling shutdownOutput(). This has the effect of removing the manager from the open list.

  Specified by:
    `shutdownOutput` in interface `AppSocket`

### close

    public void close()

  Method which closes down this socket manager, by closing the socket, cancelling the key and setting the key to be interested in nothing

  Specified by:
    `close` in interface `AppSocket`

### modifyKey

    public void modifyKey(java.nio.channels.SelectionKey key)

  Method which should change the interestOps of the handler's key. This method should *ONLY* be called by the selection thread in the context of a select().

  Overrides:
    `modifyKey` in class `SelectionKeyHandler`
  Parameters:
    `key` - The key in question

### connect

    public void connect(java.nio.channels.SelectionKey key)

  Specified by the SelectionKeyHandler interface - calling this tells this socket manager that the connection has completed and we can now read/write.

  Overrides:
    `connect` in class `SelectionKeyHandler`
  Parameters:
    `key` - The key which is connectable.

### read

    public void read(java.nio.channels.SelectionKey key)

  Reads from the socket attached to this connector.

  Overrides:
    `read` in class `SelectionKeyHandler`
  Parameters:
    `key` - The selection key for this manager

### write

    public void write(java.nio.channels.SelectionKey key)

  Writes to the socket attached to this socket manager.

  Overrides:
    `write` in class `SelectionKeyHandler`
  Parameters:
    `key` - The selection key for this manager

### acceptConnection

    protected void acceptConnection(java.nio.channels.SelectionKey key)
                             throws java.io.IOException

  Accepts a new connection on the given key these methods (createConnection/acceptConnection) could be synchronized, but they are only called in the constructor who does not expose his reference.

  Parameters:
    `serverKey` - The server socket key
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### createConnection

    protected void createConnection(SourceRoute path)
                             throws java.io.IOException

  Creates the outgoing socket to the remote handle

  Parameters:
    `address` - The accress to connect to
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### read

    public long read(java.nio.ByteBuffer[] dsts,
                     int offset,
                     int length)
              throws java.io.IOException

  Description copied from interface: `AppSocket`
  Reads a sequence of bytes from this channel into a subsequence of the given buffers.

  Specified by:
    `read` in interface `AppSocket`
  Throws:
    `java.io.IOException`

### write

    public long write(java.nio.ByteBuffer[] srcs,
                      int offset,
                      int length)
               throws java.io.IOException

  Description copied from interface: `AppSocket`
  Writes a sequence of bytes to this channel from a subsequence of the given buffers.

  Specified by:
    `write` in interface `AppSocket`
  Throws:
    `java.io.IOException`

### register

    public void register(boolean wantToRead,
                         boolean wantToWrite,
                         int timeout,
                         AppSocketReceiver receiver)

  Description copied from interface: `AppSocket`
  Must be called every time a Read/Write occurs to continue operation.

  Specified by:
    `register` in interface `AppSocket`
  Parameters:
    `wantToRead` - if you want to read from this socket
    `wantToWrite` - if you want to write to this socket
    `timeout` - // the socket's timeout value (this is a TCP level param)
    `receiver` - will have receiveSelectResult() called on it note that you must call select() each time receiveSelectResult() is called. This is so your application can properly handle flow control

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.