Package org.jppf.nio

Class AbstractNioContext

java.lang.Object
org.jppf.nio.AbstractNioContext
All Implemented Interfaces:
CloseableContext, NioChannelHandler, NioContext
Direct Known Subclasses:
AcceptorContext

public abstract class AbstractNioContext extends Object implements NioContext
Context associated with an open communication channel.
Author:
Laurent Cohen
  • Field Details

    • uuid

      protected String uuid
      Uuid of the remote client or node.
    • readMessage

      protected NioMessage readMessage
      Container for the current message data.
    • writeMessage

      protected NioMessage writeMessage
      The message to write, if any.
    • connectionUuid

      protected String connectionUuid
      Unique ID for the corresponding connection on the remote peer.
    • sslHandler

      protected SSLHandler sslHandler
      The SSL engine associated with the channel.
    • peer

      protected boolean peer
      Determines whether the associated channel is connected to a peer server.
    • ssl

      protected boolean ssl
      Determines whether the connection was opened on an SSL port.
    • enabled

      protected boolean enabled
      Whether this context is enabled.
    • closed

      protected final AtomicBoolean closed
      Whether this context has been closed.
    • onCloseAction

      protected Runnable onCloseAction
      An optional action to perform upon closing this context or its associated channel.
    • readByteCount

      public long readByteCount
      The number of bytes read by this channel.
    • writeByteCount

      public long writeByteCount
      The number of bytes written by this channel.
    • socketChannel

      protected SocketChannel socketChannel
      The associated socket channel.
    • inSnapshot

      protected JPPFSnapshot inSnapshot
      Inbound traffic statistics snapshot.
    • outSnapshot

      protected JPPFSnapshot outSnapshot
      Outbound traffic statistics snapshot.
    • local

      protected boolean local
      Whether this is a local channel.
  • Constructor Details

    • AbstractNioContext

      public AbstractNioContext()
  • Method Details

    • getUuid

      public String getUuid()
      Description copied from interface: NioContext
      Get the uuid of the node or client for this context.
      Specified by:
      getUuid in interface NioContext
      Returns:
      the uuid as a string.
    • setUuid

      public void setUuid(String uuid)
      Description copied from interface: NioContext
      Set the uuid of the node or client for this context.
      Specified by:
      setUuid in interface NioContext
      Parameters:
      uuid - the uuid as a string.
    • getReadMessage

      public NioMessage getReadMessage()
      Get the container for the current message data.
      Returns:
      an NioMessage instance.
    • setReadMessage

      public void setReadMessage(NioMessage message)
      Set the container for the current message data.
      Parameters:
      message - an NioMessage instance.
    • getWriteMessage

      public NioMessage getWriteMessage()
      Returns:
      the message to write, if any.
    • setWriteMessage

      public void setWriteMessage(NioMessage writeMessage)
      Parameters:
      writeMessage - the message to write, if any.
    • nextMessageToSend

      protected NioMessage nextMessageToSend()
      Get the next messge to send, if any.
      Returns:
      the next message in the send queue, or null if the queue is empty.
    • getConnectionUuid

      public String getConnectionUuid()
      Get the unique ID for the corresponding connection on the remote peer.
      Returns:
      the id as a string.
    • setConnectionUuid

      public void setConnectionUuid(String connectionUuid)
      Set the unique ID for the corresponding connection on the remote peer.
      Parameters:
      connectionUuid - the id as a string.
    • getSSLHandler

      public SSLHandler getSSLHandler()
      Description copied from interface: NioContext
      Get the SSL engine manager associated with the channel.
      Specified by:
      getSSLHandler in interface NioContext
      Returns:
      an instance of SSLHandlerImpl.
    • setSSLHandler

      public void setSSLHandler(SSLHandler sslHandler)
      Description copied from interface: NioContext
      Get the SSL engine associated with the channel.
      Specified by:
      setSSLHandler in interface NioContext
      Parameters:
      sslHandler - an instance of SSLHandlerImpl.
    • isPeer

      public boolean isPeer()
      Description copied from interface: NioContext
      Determine whether the associated channel is connected to a peer server.
      Specified by:
      isPeer in interface NioContext
      Returns:
      true if the channel is connected to a peer server, false otherwise.
    • setPeer

      public void setPeer(boolean peer)
      Description copied from interface: NioContext
      Specify whether the associated channel is connected to a peer server.
      Specified by:
      setPeer in interface NioContext
      Parameters:
      peer - true if the channel is connected to a peer server, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isSecure

      public boolean isSecure()
      Determine whether the associated channel is secured via SSL/TLS.
      Returns:
      true if the channel is secure, false otherwise.
    • isSsl

      public boolean isSsl()
      Determines whether the connection was opened on an SSL port.
      Specified by:
      isSsl in interface NioContext
      Returns:
      true for an SSL connection, false otherwise.
    • setSsl

      public void setSsl(boolean ssl)
      Specifies whether the connection was opened on an SSL port.
      Specified by:
      setSsl in interface NioContext
      Parameters:
      ssl - true for an SSL connection, false otherwise.
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: NioContext
      Whether this context is enabled.
      Specified by:
      isEnabled in interface NioContext
      Returns:
      true if this context is enabled, false otherwise.
    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from interface: NioContext
      Enable or disable this context.
      Specified by:
      setEnabled in interface NioContext
      Parameters:
      enabled - true to enable this context, false to disable it.
    • isClosed

      public boolean isClosed()
      Description copied from interface: CloseableContext
      Determine whether this channel has been closed.
      Specified by:
      isClosed in interface CloseableContext
      Returns:
      true if this channel has been closed, false otherwise.
    • setClosed

      public void setClosed(boolean closed)
      Description copied from interface: CloseableContext
      Specify whether this channel has been closed.
      Specified by:
      setClosed in interface CloseableContext
      Parameters:
      closed - true if this channel has been closed, false otherwise.
    • setOnCloseAction

      public void setOnCloseAction(Runnable onCloseAction)
      Set an optional action to perform upon closing this context or its associated channel.
      Parameters:
      onCloseAction - a Runnable instance.
    • onClose

      protected void onClose()
      Callback that can be invoked upon closing this context or its associated channel.
    • getSocketChannel

      public SocketChannel getSocketChannel()
      Description copied from interface: NioContext
      Get the associated socket chanel, if any.
      Specified by:
      getSocketChannel in interface NioContext
      Returns:
      the associated socket channel.
    • getInterestOps

      public int getInterestOps()
      Specified by:
      getInterestOps in interface NioChannelHandler
      Returns:
      the socket channel's interest ops.
    • setInterestOps

      public void setInterestOps(int interestOps)
      Description copied from interface: NioChannelHandler
      Set the socket channel's interest ops.
      Specified by:
      setInterestOps in interface NioChannelHandler
      Parameters:
      interestOps - the interest ops to set.
    • getSelectionKey

      public SelectionKey getSelectionKey()
      Specified by:
      getSelectionKey in interface NioChannelHandler
      Returns:
      the associated selection key.
    • setSelectionKey

      public void setSelectionKey(SelectionKey selectionKey)
      Description copied from interface: NioChannelHandler
      Set the associated selection key.
      Specified by:
      setSelectionKey in interface NioChannelHandler
      Parameters:
      selectionKey - the key to set.
    • isLocal

      public boolean isLocal()
      Returns:
      whether this is a local channel.
    • setLocal

      public void setLocal(boolean local)
      Parameters:
      local - whether this is a local channel.