| 
The Meta-Environment API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttoolbus.communication.SocketIOHandler
public class SocketIOHandler
This class handles all communication with remote applications through sockets. It uses NIO / asynchroneous I/O. It will use 64k of staticly allocated native memory for I/O buffers.
| Nested Class Summary | |
|---|---|
protected static class | 
SocketIOHandler.OperationTermPair
A structure that links a term with an operation.  | 
| Field Summary | |
|---|---|
private  aterm.pure.binary.BinaryReader | 
binaryReader
 | 
private  aterm.pure.binary.BinaryWriter | 
binaryWriter
 | 
private  int | 
blockLength
 | 
private static byte | 
BLOCKLENGTHBYTES
 | 
private static int | 
BUFFERSIZE
 | 
private  AbstractConnectionHandler | 
connectionHandler
 | 
private  IDataHandler | 
dataHandler
 | 
private  boolean | 
doneWithBlock
 | 
static byte | 
END_OPC
 | 
private  boolean | 
expectingDisconnect
 | 
private  java.nio.ByteBuffer | 
lengthReadBuffer
 | 
private  java.nio.ByteBuffer | 
lengthWriteBuffer
 | 
private  byte | 
operation
 | 
private static byte | 
OPERATIONBYTES
 | 
private  java.nio.ByteBuffer | 
operationReadBuffer
 | 
private  java.nio.ByteBuffer | 
readBuffer
 | 
private  java.nio.channels.SocketChannel | 
socketChannel
 | 
private  java.nio.ByteBuffer | 
writeBuffer
 | 
private  toolbus.util.collections.RotatingQueue<SocketIOHandler.OperationTermPair> | 
writeQueue
 | 
| Constructor Summary | |
|---|---|
SocketIOHandler(IDataHandler dataHandler,
                               AbstractConnectionHandler connectionHandler,
                               java.nio.channels.SocketChannel socketChannel)
Constructor.  | 
|
| Method Summary | |
|---|---|
 void | 
exceptionOccured()
Notifies the I/O handler that an exception has occured so it can take the nessacary steps.  | 
private  void | 
forcedWrite(java.nio.ByteBuffer buffer)
Forces the writing of the content of the given buffer to the socket channel.  | 
private  void | 
handleDisconnect()
Handles the received disconnect.  | 
 boolean | 
hasMoreToWrite()
Checks if there is data left that needs to be written.  | 
protected  void | 
read()
This method triggers the reading of data from the socket.  | 
private  boolean | 
readFromChannel(java.nio.ByteBuffer buffer)
Reads bytes from the socket channel and inserts them into the given byte buffer.  | 
 void | 
receive(byte op,
               aterm.ATerm aTerm)
Receives a term from the remote location.  | 
private  boolean | 
receiveBlockLength()
Reads the data block length from the socket channel (2 bytes, little endian encoded).  | 
private  boolean | 
receiveDataBlock()
Reads the data from the current data block from the socket channel.  | 
private  boolean | 
receiveOperation()
Reads the operation byte from the socket channel.  | 
 void | 
send(byte op,
         aterm.ATerm aTerm)
Adds the term to the list of terms that needs to be send.  | 
private  void | 
sendBlockLength(int length)
Writes the block length to the socket channel.  | 
private  boolean | 
sendDataBlock()
Writes a block of data to the socket channel.  | 
private  void | 
sendOperation(byte op)
Writes the operation byte to the stream.  | 
 void | 
shutDown()
Shuts down this ioHandler and it's associated datahandler.  | 
 void | 
terminate()
Terminates the connection with the in this socket I/O handler contained socket channel in an orderly manner.  | 
protected  void | 
write()
This method triggers the writing of data from the socket.  | 
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static final byte END_OPC
private static final byte OPERATIONBYTES
private static final byte BLOCKLENGTHBYTES
private static final int BUFFERSIZE
private final java.nio.ByteBuffer operationReadBuffer
private final java.nio.ByteBuffer lengthReadBuffer
private final java.nio.ByteBuffer readBuffer
private final java.nio.ByteBuffer lengthWriteBuffer
private final java.nio.ByteBuffer writeBuffer
private final java.nio.channels.SocketChannel socketChannel
private final AbstractConnectionHandler connectionHandler
private final IDataHandler dataHandler
private boolean expectingDisconnect
private aterm.pure.binary.BinaryReader binaryReader
private byte operation
private int blockLength
private final toolbus.util.collections.RotatingQueue<SocketIOHandler.OperationTermPair> writeQueue
private aterm.pure.binary.BinaryWriter binaryWriter
private boolean doneWithBlock
| Constructor Detail | 
|---|
public SocketIOHandler(IDataHandler dataHandler,
                       AbstractConnectionHandler connectionHandler,
                       java.nio.channels.SocketChannel socketChannel)
dataHandler - The data handler that is associated with this socket I/O handler.connectionHandler - The connection handler that created this socket I/O handler.socketChannel - The socket channel that will be used by this socket I/O handler.| Method Detail | 
|---|
public void send(byte op,
                 aterm.ATerm aTerm)
send in interface IIOHandlerop - The operation associated with the term we need to send.aTerm - The term that needs to be send.IIOHandler.send(byte, ATerm)
public void receive(byte op,
                    aterm.ATerm aTerm)
IIOHandler
receive in interface IIOHandlerop - The operation associated with the term we received.aTerm - The term that was received.IIOHandler.receive(byte, ATerm)protected void read()
private boolean receiveOperation()
private boolean receiveBlockLength()
private boolean receiveDataBlock()
private boolean readFromChannel(java.nio.ByteBuffer buffer)
buffer - The buffer to insert the received data into.
protected void write()
private void sendOperation(byte op)
op - The operation byte that indicates what the upcoming data package represents.private void sendBlockLength(int length)
length - The length of the block of data that will be written.private boolean sendDataBlock()
private void forcedWrite(java.nio.ByteBuffer buffer)
buffer - The buffer to write to.public boolean hasMoreToWrite()
public void terminate()
terminate in interface IIOHandlerIIOHandler.terminate()public void shutDown()
IIOHandler
shutDown in interface IIOHandlerIIOHandler.shutDown()public void exceptionOccured()
IIOHandler
exceptionOccured in interface IIOHandlerIIOHandler.exceptionOccured()private void handleDisconnect()
  | 
The Meta-Environment API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||