Class SocketConnection

java.lang.Object
com.sshtools.synergy.nio.SocketConnection
All Implemented Interfaces:
SelectionKeyAware, SelectorRegistrationListener, SocketHandler
Direct Known Subclasses:
SSLContextConnection, SSLSocketConnection

public class SocketConnection extends Object implements SocketHandler
This class implements a SocketHandler using a standard socket.
  • Field Details

  • Constructor Details

    • SocketConnection

      public SocketConnection()
      Construct the socket.
  • Method Details

    • initialize

      public void initialize(ProtocolEngine protocolEngine, SshEngine daemon, SelectableChannel channel) throws IOException
      Initialize the socket with the protocol engine and the daemon process.
      Specified by:
      initialize in interface SocketHandler
      Parameters:
      protocolEngine - ProtocolEngine
      daemon - Daemon
      Throws:
      IOException
    • registrationCompleted

      public void registrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) throws IOException
      The sockets channel has completed registration.
      Specified by:
      registrationCompleted in interface SelectorRegistrationListener
      Parameters:
      channel - SelectableChannel
      key - SelectionKey
      selectorThread - SelectorThread
      Throws:
      IOException
    • setSelectionKey

      public void setSelectionKey(SelectionKey key)
      Specified by:
      setSelectionKey in interface SelectionKeyAware
    • setProtocolEngine

      public void setProtocolEngine(ProtocolEngine protocolEngine)
      Set a new ProtocolEngine to handle this sockets data.
      Parameters:
      protocolEngine -
    • closeConnection

      public void closeConnection()
      Close this socket connection.
    • closeConnection

      public void closeConnection(boolean closeProtocol)
    • getProtocolEngine

      public ProtocolEngine getProtocolEngine()
      Get the protocol engine for this socket.
      Returns:
      ProtocolEngine
    • getDaemonContext

      public SshEngineContext getDaemonContext()
      Get the daemon process for this socket.
      Returns:
      DaemonContext
    • getLocalAddress

      public SocketAddress getLocalAddress()
      Returns the local address to which the remote socket is connected.
      Returns:
    • getLocalPort

      public int getLocalPort()
      Returns the local port to which the remote socket is connected.
      Returns:
    • getPort

      public int getPort()
      Returns the local port to which the remote socket is connected.
      Returns:
    • getRemoteAddress

      public SocketAddress getRemoteAddress()
      Returns the address of the remote socket.
      Returns:
    • getSocketChannel

      public SocketChannel getSocketChannel()
      Get the SocketChannel for this socket.
      Returns:
      SocketChannel
    • getIdleStates

      public IdleStateManager getIdleStates()
      Get the idle state manager.
      Returns:
      IdleStateManager
    • isSelectorThread

      public boolean isSelectorThread()
      Is the current thread this sockets SelectorThread?
      Returns:
      boolean
    • isConnected

      protected boolean isConnected()
      Is the socket still connected?
      Returns:
      boolean
    • getThread

      public SelectorThread getThread()
      Get the selector thread for this connection
      Returns:
      SelectorThread
    • getInitialOps

      public int getInitialOps()
      Get the initial interested ops for this socket.
      Specified by:
      getInitialOps in interface SocketHandler
      Returns:
      int
    • processReadEvent

      public boolean processReadEvent()
      The selector is ready to be read.
      Specified by:
      processReadEvent in interface SocketHandler
      Returns:
      boolean
    • processWriteEvent

      public boolean processWriteEvent()
      The selector is ready to be written to.
      Specified by:
      processWriteEvent in interface SocketHandler
      Returns:
      boolean
    • setThread

      public void setThread(SelectorThread thread)
      Set the selector thread for this connection
      Specified by:
      setThread in interface SocketHandler
      Parameters:
      thread - SelectorThread
    • addTask

      public void addTask(ConnectionAwareTask task)
      Description copied from interface: SocketHandler
      Add a task to the executor
      Specified by:
      addTask in interface SocketHandler
    • wantsWrite

      public boolean wantsWrite()
      Description copied from interface: SocketHandler
      Tell the selector that the handler wants to write.
      Specified by:
      wantsWrite in interface SocketHandler
      Returns:
    • getSelectorThread

      public SelectorThread getSelectorThread()
      Description copied from interface: SocketHandler
      Get the selector thread this handler is connected to.
      Specified by:
      getSelectorThread in interface SocketHandler
      Returns:
    • flagWrite

      public void flagWrite()
    • getName

      public String getName()
      Description copied from interface: SocketHandler
      A name for this Socket
      Specified by:
      getName in interface SocketHandler
      Returns:
    • getContext

      public SshContext getContext()
      Description copied from interface: SocketHandler
      Get the current context
      Specified by:
      getContext in interface SocketHandler
      Returns:
    • getConnection

      public Connection<? extends SshContext> getConnection()
      Description copied from interface: SocketHandler
      Get the Connection for this handler
      Specified by:
      getConnection in interface SocketHandler
      Returns:
    • wantsRead

      public boolean wantsRead()
      Description copied from interface: SocketHandler
      Tell the selector that the handler wants to read.
      Specified by:
      wantsRead in interface SocketHandler
      Returns: