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 ConnectionOrientedTransportMappings.- Since:
- 3.7.0
- Author:
- Frank Fock
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Throwableprotected final LinkedList<S> protected Selectorprotected final Aprotected ServerSocketChannelprotected booleanprotected final AbstractConnectionOrientedTransportMapping<A, S> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractTransportServerThread(AbstractConnectionOrientedTransportMapping<A, S> transportMapping, A serverAddress) Create a server thread for anAbstractConnectionOrientedTransportMappingon the specified server address. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidcloseChannel(SelectableChannel channel) protected voidconnectChannel(SelectionKey sk, A incomingAddress) protected voidconnectSocketToSendMessage(A address, byte[] message, SocketChannel socketChannel, S entry, Map<A, S> sockets) protected abstract AcreateIncomingAddress(SocketChannel socket) protected abstract ScreateSocketEntry(A address, SocketChannel socketChannel, boolean useClientMode, TransportStateReference tmStateReference) protected voidDo the NIO server processing.protected voidvoidInterrupts this task.voidjoin()Waits until this task has been finished.protected abstract SocketChannelopenSocketChannel(ProtocolFamily family) protected abstract voidprotected abstract booleanreadMessage(SelectionKey sk, SocketChannel readChannel, A incomingAddress, S socketEntry) abstract SremoveSocketEntry(A incomingAddress) abstract voidrun()voidsendMessage(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.voidTheWorkerPoolmight call this method to hint the activeWorkTaskinstance to complete execution as soon as possible.protected AwriteData(SelectionKey sk, A incomingAddress) protected voidwriteMessage(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 anAbstractConnectionOrientedTransportMappingon 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 protocolsMPv3or 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:WorkerTaskTheWorkerPoolmight call this method to hint the activeWorkTaskinstance to complete execution as soon as possible.- Specified by:
terminatein interfaceWorkerTask
-
join
public void join()Description copied from interface:WorkerTaskWaits until this task has been finished.- Specified by:
joinin interfaceWorkerTask
-
interrupt
public void interrupt()Description copied from interface:WorkerTaskInterrupts this task.- Specified by:
interruptin interfaceWorkerTask- See Also:
-