Module org.snmp4j

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 Details

  • 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()
      Description copied from interface: WorkerTask
      Waits until this task has been finished.
      Specified by:
      join in interface WorkerTask
    • interrupt

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