|
The Meta-Environment API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttoolbus.communication.AbstractConnectionHandler
toolbus.SocketConnectionHandler
public class SocketConnectionHandler
This class handles the establishing and closing of all TCP/IP connections.
| Field Summary | |
|---|---|
private java.nio.ByteBuffer |
handShakeBuffer
|
private static int |
HANDSHAKEBUFFERSIZE
|
private SocketReadMultiplexer |
readMultiplexer
|
private boolean |
running
|
private java.nio.channels.ServerSocketChannel |
serverSocketChannel
|
private ToolBus |
toolbus
|
private SocketWriteMultiplexer |
writeMultiplexer
|
| Constructor Summary | |
|---|---|
SocketConnectionHandler(ToolBus toolbus)
Constructor. |
|
| Method Summary | |
|---|---|
private void |
acceptConnection()
Accepts a connection with a remote application. |
void |
closeConnection(java.nio.channels.SocketChannel socketChannel)
Closes the connection associated with the given socket channel. |
int |
getPort()
Returns the port number the ToolBus is currently running on. |
SocketReadMultiplexer |
getReadMultiplexer()
Returns a reference to the read multiplexer. |
SocketWriteMultiplexer |
getWriteMultiplexer()
Returns a reference to the write multiplexer. |
void |
initialize()
Initializes the connection handler. |
void |
initialize(int port)
Initializes the connection handler on a user specified port. |
boolean |
isRunning()
Checks if this handler is running or not. |
private aterm.ATerm |
readTermFromChannel(aterm.pure.PureFactory factory,
java.nio.channels.SocketChannel socketChannel,
java.nio.ByteBuffer byteBuffer)
Reads a term from the given channel, using the given buffer. |
void |
run()
Main loop of this handler. |
private ToolInstance |
shakeHands(java.nio.channels.SocketChannel socketChannel)
|
void |
stopRunning()
Stops the execution of this handler. |
private void |
writeTermToChannel(aterm.ATerm aTerm,
java.nio.channels.SocketChannel socketChannel,
java.nio.ByteBuffer byteBuffer)
Transmits the term to the given socket channel, using the given buffer. |
| Methods inherited from class toolbus.communication.AbstractConnectionHandler |
|---|
closeDueToDisconnect, closeDueToException |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final int HANDSHAKEBUFFERSIZE
private final ToolBus toolbus
private final SocketReadMultiplexer readMultiplexer
private final SocketWriteMultiplexer writeMultiplexer
private final java.nio.channels.ServerSocketChannel serverSocketChannel
private final java.nio.ByteBuffer handShakeBuffer
private volatile boolean running
| Constructor Detail |
|---|
public SocketConnectionHandler(ToolBus toolbus)
toolbus - A reference to the main class of the Toolbus.| Method Detail |
|---|
public void initialize()
throws java.io.IOException
java.io.IOException
public void initialize(int port)
throws java.io.IOException
java.io.IOExceptionpublic int getPort()
public SocketReadMultiplexer getReadMultiplexer()
AbstractConnectionHandler
getReadMultiplexer in class AbstractConnectionHandlerAbstractConnectionHandler.getReadMultiplexer()public SocketWriteMultiplexer getWriteMultiplexer()
AbstractConnectionHandler
getWriteMultiplexer in class AbstractConnectionHandlerAbstractConnectionHandler.getWriteMultiplexer()public boolean isRunning()
public void stopRunning()
public void run()
run in interface java.lang.Runnable
private void acceptConnection()
throws java.io.IOException
java.io.IOException - Thrown when something goes wrong while accepting the connection, registering it
or instantiating the associated I/O handlers.
private ToolInstance shakeHands(java.nio.channels.SocketChannel socketChannel)
throws java.io.IOException,
ToolBusException
java.io.IOException
ToolBusException
private void writeTermToChannel(aterm.ATerm aTerm,
java.nio.channels.SocketChannel socketChannel,
java.nio.ByteBuffer byteBuffer)
throws java.io.IOException
aTerm - The term to write.socketChannel - The channel to write to.byteBuffer - The buffer to use.
java.io.IOException - Thrown when something goes wrong while writing to the channel.
private aterm.ATerm readTermFromChannel(aterm.pure.PureFactory factory,
java.nio.channels.SocketChannel socketChannel,
java.nio.ByteBuffer byteBuffer)
throws java.io.IOException
factory - The factory to use for parsing the term.socketChannel - The channel to read from.byteBuffer - The buffer to use.
java.io.IOException - Thrown when something goes wrong while reading the term from the channel.public void closeConnection(java.nio.channels.SocketChannel socketChannel)
AbstractConnectionHandler
closeConnection in class AbstractConnectionHandlersocketChannel - The socket channel, who's associated socket should be closed.AbstractConnectionHandler.closeConnection(SocketChannel)
|
The Meta-Environment API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||