Module org.snmp4j
Package org.snmp4j.transport
Class AbstractTransportServerThread<A extends Address,S extends AbstractSocketEntry<A>>
java.lang.Object
org.snmp4j.transport.AbstractTransportServerThread<A,S>
- Type Parameters:
A
- the address type supported.S
- the socket entry supported.
- All Implemented Interfaces:
Runnable
,WorkerTask
- Direct Known Subclasses:
DefaultTcpTransportMapping.ServerThread
public abstract class AbstractTransportServerThread<A extends Address,S extends AbstractSocketEntry<A>>
extends Object
implements WorkerTask
The
AbstractTransportServerThread
is a WorkerTask
that serves server connections
using Java NIO for ConnectionOrientedTransportMapping
s.- Since:
- 3.7.0
- Author:
- Frank Fock
-
Field Summary
Modifier and TypeFieldDescriptionprotected Throwable
protected final LinkedList
<S> protected Selector
protected final A
protected ServerSocketChannel
protected boolean
protected final AbstractConnectionOrientedTransportMapping
<A, S> -
Constructor Summary
ConstructorDescriptionAbstractTransportServerThread
(AbstractConnectionOrientedTransportMapping<A, S> transportMapping, A serverAddress) Create a server thread for anAbstractConnectionOrientedTransportMapping
on the specified server address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
closeChannel
(SelectableChannel channel) protected void
connectChannel
(SelectionKey sk, A incomingAddress) protected void
connectSocketToSendMessage
(A address, byte[] message, SocketChannel socketChannel, S entry, Map<A, S> sockets) protected abstract A
createIncomingAddress
(SocketChannel socket) protected abstract S
createSocketEntry
(A address, SocketChannel socketChannel, boolean useClientMode, TransportStateReference tmStateReference) protected void
Do the NIO server processing.protected void
void
Interrupts this task.void
join()
Waits until this task has been finished.protected abstract SocketChannel
openSocketChannel
(ProtocolFamily family) protected abstract void
protected abstract boolean
readMessage
(SelectionKey sk, SocketChannel readChannel, A incomingAddress, S socketEntry) abstract S
removeSocketEntry
(A incomingAddress) abstract void
run()
void
sendMessage
(A address, byte[] message, TransportStateReference tmStateReference, Map<A, S> sockets) Send a message to the specified address and update to specified socket entry map if a new client connection needs to be created for that.void
TheWorkerPool
might call this method to hint the activeWorkTask
instance to complete execution as soon as possible.protected A
writeData
(SelectionKey sk, A incomingAddress) protected void
writeMessage
(S entry, SocketChannel sc)
-
Field Details
-
transportMapping
protected final AbstractConnectionOrientedTransportMapping<A extends Address,S extends AbstractSocketEntry<A>> transportMapping -
serverAddress
-
stop
protected volatile boolean stop -
selector
-
pending
-
lastError
-
ssc
-
-
Constructor Details
-
AbstractTransportServerThread
public AbstractTransportServerThread(AbstractConnectionOrientedTransportMapping<A, S> transportMapping, A serverAddress) throws IOExceptionCreate a server thread for anAbstractConnectionOrientedTransportMapping
on the specified server address.- Parameters:
transportMapping
- the transport mapping using this thread to serve server messages.serverAddress
- the listen address for the server.- Throws:
IOException
- if initializing NIO selector or listen address socket channel fails.
-
-
Method Details
-
connectSocketToSendMessage
protected void connectSocketToSendMessage(A address, byte[] message, SocketChannel socketChannel, S entry, Map<A, S> sockets) throws ClosedChannelException- Throws:
ClosedChannelException
-
createSocketEntry
protected abstract S createSocketEntry(A address, SocketChannel socketChannel, boolean useClientMode, TransportStateReference tmStateReference) -
sendMessage
public void sendMessage(A address, byte[] message, TransportStateReference tmStateReference, Map<A, S> sockets) throws IOExceptionSend a message to the specified address and update to specified socket entry map if a new client connection needs to be created for that.- Parameters:
address
- the remote address to send the message to.message
- the message to be sent.tmStateReference
- transport mapping state reference needed by transport mappings supporting message protocolsMPv3
or higher.sockets
- the client connections available and to be updated.- Throws:
IOException
- if sending the message failed because of IO exceptions.
-
getSelector
-
openSocketChannel
- Throws:
IOException
-
run
public abstract void run() -
readMessage
protected abstract boolean readMessage(SelectionKey sk, SocketChannel readChannel, A incomingAddress, S socketEntry) throws IOException - Throws:
IOException
-
doServer
Do the NIO server processing.- Parameters:
sockets
- the sockets to serve.
-
fireIncrementCounterSessionClose
protected void fireIncrementCounterSessionClose() -
processQueues
protected abstract void processQueues() -
removeSocketEntry
-
connectChannel
-
writeData
-
createIncomingAddress
- Throws:
IOException
-
closeChannel
-
writeMessage
- Throws:
IOException
-
close
public void close() -
terminate
public void terminate()Description copied from interface:WorkerTask
TheWorkerPool
might call this method to hint the activeWorkTask
instance to complete execution as soon as possible.- Specified by:
terminate
in interfaceWorkerTask
-
join
public void join()Description copied from interface:WorkerTask
Waits until this task has been finished.- Specified by:
join
in interfaceWorkerTask
-
interrupt
public void interrupt()Description copied from interface:WorkerTask
Interrupts this task.- Specified by:
interrupt
in interfaceWorkerTask
- See Also:
-