|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object rice.selector.SelectionKeyHandler rice.pastry.socket.SocketAppSocket
public class SocketAppSocket
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.
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 |
---|
public static final byte CONNECTION_UNKNOWN_ERROR
public static final byte CONNECTION_UNKNOWN
public static final byte CONNECTION_OK
public static final byte CONNECTION_NO_APP
public static final byte CONNECTION_NO_ACCEPTOR
protected java.nio.channels.SelectionKey key
protected java.nio.channels.SocketChannel channel
protected AppSocketReceiver receiver
protected AppSocketReceiver reader
protected AppSocketReceiver writer
Constructor Detail |
---|
public SocketAppSocket(SocketCollectionManager manager, java.nio.channels.SelectionKey key, int appId) throws java.io.IOException
key
- The server accepting key for the channelmanager
- TODO
java.io.IOException
- DESCRIBE THE EXCEPTIONpublic SocketAppSocket(SocketCollectionManager manager, SourceRoute path, int appId, AppSocketReceiver receiver, int timeout) throws java.io.IOException
manager
- TODOaddress
- The ultimate destination of this socketproxy
- The intermediate destination of this socket (if a source route)
java.io.IOException
- An errorMethod Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public void shutdownOutput()
shutdownOutput
in interface AppSocket
public void close()
close
in interface AppSocket
public void modifyKey(java.nio.channels.SelectionKey key)
modifyKey
in class SelectionKeyHandler
key
- The key in questionpublic void connect(java.nio.channels.SelectionKey key)
connect
in class SelectionKeyHandler
key
- The key which is connectable.public void read(java.nio.channels.SelectionKey key)
read
in class SelectionKeyHandler
key
- The selection key for this managerpublic void write(java.nio.channels.SelectionKey key)
write
in class SelectionKeyHandler
key
- The selection key for this managerprotected void acceptConnection(java.nio.channels.SelectionKey key) throws java.io.IOException
serverKey
- The server socket key
java.io.IOException
- DESCRIBE THE EXCEPTIONprotected void createConnection(SourceRoute path) throws java.io.IOException
address
- The accress to connect to
java.io.IOException
- DESCRIBE THE EXCEPTIONpublic long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
AppSocket
read
in interface AppSocket
java.io.IOException
public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
AppSocket
write
in interface AppSocket
java.io.IOException
public void register(boolean wantToRead, boolean wantToWrite, int timeout, AppSocketReceiver receiver)
AppSocket
register
in interface AppSocket
wantToRead
- if you want to read from this socketwantToWrite
- if you want to write to this sockettimeout
- // 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
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |