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, TLSTM.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 Details

    • transportMapping

      protected final AbstractConnectionOrientedTransportMapping<A extends Address, S extends AbstractSocketEntry<A>> transportMapping
    • serverAddress

      protected final A extends Address serverAddress
    • stop

      protected volatile boolean stop
      A flag indicating whether the server thread should stop its execution. This variable is checked periodically by the thread's main loop to determine if it should terminate its operation. It is marked as volatile to ensure visibility across threads.
    • shutdown

      protected volatile boolean shutdown
      A flag indicating whether the server thread should initiate the shutdown process. When set to true, this variable signals the thread to terminate its execution gracefully, allowing for any necessary cleanup operations to complete.

      This variable is declared as volatile to ensure visibility of its value across multiple threads, enabling proper coordination between the server thread and the controlling threads that trigger or monitor the shutdown process.

      Since:
      3.10.0
    • selector

      protected Selector selector
    • pending

      protected final LinkedList<S extends AbstractSocketEntry<A>> pending
    • lastError

      protected Throwable lastError
    • ssc

      protected ServerSocketChannel ssc
    • exitLatch

      protected CountDownLatch exitLatch
  • Constructor Details

  • 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 IOException
      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.
      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 protocols MPv3 or higher.
      sockets - the client connections available and to be updated.
      Throws:
      IOException - if sending the message failed because of IO exceptions.
    • getSelector

      public Selector getSelector()
    • openSocketChannel

      protected abstract SocketChannel openSocketChannel(ProtocolFamily family) throws IOException
      Throws:
      IOException
    • run

      public abstract void run()
      Specified by:
      run in interface Runnable
    • readMessage

      protected abstract boolean readMessage(SelectionKey sk, SocketChannel readChannel, A incomingAddress, S socketEntry) throws IOException
      Throws:
      IOException
    • doServer

      protected void doServer(Map<A,S> sockets)
      Do the NIO server processing.
      Parameters:
      sockets - the sockets to serve.
    • fireIncrementCounterSessionClose

      protected void fireIncrementCounterSessionClose()
    • processQueues

      protected abstract void processQueues()
    • removeSocketEntry

      public abstract S removeSocketEntry(A incomingAddress)
    • connectChannel

      protected void connectChannel(SelectionKey sk, A incomingAddress)
    • writeData

      protected A writeData(SelectionKey sk, A incomingAddress)
    • createIncomingAddress

      protected abstract A createIncomingAddress(SocketChannel socket) throws IOException
      Throws:
      IOException
    • closeChannel

      protected void closeChannel(SelectableChannel channel)
    • writeMessage

      protected void writeMessage(S entry, SocketChannel sc) throws IOException
      Throws:
      IOException
    • close

      public void close()
    • terminate

      public void terminate()
      Description copied from interface: WorkerTask
      The WorkerPool might call this method to hint the active WorkTask instance to complete execution as soon as possible.
      Specified by:
      terminate in interface WorkerTask
    • join

      public void join() throws InterruptedException
      Description copied from interface: WorkerTask
      Waits until this task has been finished.
      Specified by:
      join in interface WorkerTask
      Throws:
      InterruptedException - if the join has been interrupted by another thread.
    • interrupt

      public void interrupt()
      Description copied from interface: WorkerTask
      Interrupts this task.
      Specified by:
      interrupt in interface WorkerTask
      See Also: