public class SelectorThread
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Class and Description |
---|---|
protected class |
SelectorThread.Cleaner
Class for cleaning output connections after
max keep alive time has been reached.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.logging.Logger |
logger
The logger.
|
protected jadex.bridge.service.types.message.IMessageService |
msgservice
The message service for delivering received messages.
|
protected boolean |
running
Flag indicating the thread should be running (set to false for shutdown).
|
protected java.nio.channels.Selector |
selector
The NIO selector.
|
protected java.util.List<java.lang.Runnable> |
tasks
The tasks enqueued from external threads.
|
protected java.util.Timer |
timer
The cleanup timer.
|
protected java.util.Map<java.nio.channels.SocketChannel,java.util.List<jadex.commons.Tuple2<java.util.List<java.nio.ByteBuffer>,jadex.commons.future.Future<java.lang.Void>>>> |
writetasks
The write tasks of data waiting to be written to a connection.
|
Constructor and Description |
---|
SelectorThread(java.nio.channels.Selector selector,
jadex.bridge.service.types.message.IMessageService msgsservice,
java.util.logging.Logger logger)
Create a NIO selector thread.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeKeyAttachment(java.nio.channels.SelectionKey key) |
jadex.commons.future.IFuture<NIOTCPOutputConnection> |
getConnection(java.net.InetSocketAddress address)
Get a connection to one of the given addresses.
|
protected void |
handleAccept(java.nio.channels.SelectionKey key)
Accept a connection request.
|
protected void |
handleConnect(java.nio.channels.SelectionKey key)
Read data from a connection.
|
protected void |
handleRead(java.nio.channels.SelectionKey key)
Read data from a connection.
|
protected void |
handleWrite(java.nio.channels.SelectionKey key)
Write data to a connection.
|
protected java.lang.Object |
internalGetConnection(java.net.InetSocketAddress address) |
protected void |
internalPutConnection(java.net.InetSocketAddress address,
java.lang.Object con) |
protected void |
internalRemoveConnection(java.net.InetSocketAddress address) |
void |
run()
Main cycle.
|
jadex.commons.future.IFuture<java.lang.Void> |
sendMessage(NIOTCPOutputConnection con,
byte[] prolog,
byte[] data)
Send a message using the given connection.
|
void |
shutdown()
Set the running flag to false to gracefully terminate the thread.
|
protected boolean running
protected java.nio.channels.Selector selector
protected jadex.bridge.service.types.message.IMessageService msgservice
protected java.util.logging.Logger logger
protected java.util.List<java.lang.Runnable> tasks
protected java.util.Map<java.nio.channels.SocketChannel,java.util.List<jadex.commons.Tuple2<java.util.List<java.nio.ByteBuffer>,jadex.commons.future.Future<java.lang.Void>>>> writetasks
protected java.util.Timer timer
public SelectorThread(java.nio.channels.Selector selector, jadex.bridge.service.types.message.IMessageService msgsservice, java.util.logging.Logger logger)
public void run()
run
in interface java.lang.Runnable
protected void closeKeyAttachment(java.nio.channels.SelectionKey key)
public void shutdown()
public jadex.commons.future.IFuture<NIOTCPOutputConnection> getConnection(java.net.InetSocketAddress address)
addresses
- The address to connect to.public jadex.commons.future.IFuture<java.lang.Void> sendMessage(NIOTCPOutputConnection con, byte[] prolog, byte[] data)
sc
- The connection.msg
- The message.codecids
- The codec ids.protected void handleAccept(java.nio.channels.SelectionKey key)
protected void handleRead(java.nio.channels.SelectionKey key)
protected void handleConnect(java.nio.channels.SelectionKey key)
protected void handleWrite(java.nio.channels.SelectionKey key)
protected void internalPutConnection(java.net.InetSocketAddress address, java.lang.Object con)
protected java.lang.Object internalGetConnection(java.net.InetSocketAddress address)
protected void internalRemoveConnection(java.net.InetSocketAddress address)