Interface IOSession

All Superinterfaces:
AutoCloseable, ByteChannel, Channel, Closeable, Identifiable, ModalCloseable, ReadableByteChannel, SocketModalCloseable, WritableByteChannel
All Known Subinterfaces:
ProtocolIOSession
All Known Implementing Classes:
InternalDataChannel, IOSessionImpl, LoggingIOSession, SSLIOSession

@Internal public interface IOSession extends ByteChannel, SocketModalCloseable, Identifiable
IOSession interface represents a sequence of logically related data exchanges between two end points.

The channel associated with implementations of this interface can be used to read data from and write data to the session.

I/O sessions are not bound to an execution thread, therefore one cannot use the context of the thread to store a session's state. All details about a particular session must be stored within the session itself, usually using execution context associated with it.

Implementations of this interface are expected to be threading safe.

Since:
4.0
  • Method Details

    • getHandler

      IOEventHandler getHandler()
      Returns event handler associated with the session.
      Since:
      5.0
    • upgrade

      void upgrade(IOEventHandler handler)
      Upgrades event handler associated with the session.
      Since:
      5.0
    • getLock

      Lock getLock()
      Returns session lock that should be used by I/O event handlers to synchronize access to the session.
      Since:
      5.0
    • enqueue

      void enqueue(Command command, Command.Priority priority)
      Inserts Command at the end of the command queue.
      Since:
      5.0
    • hasCommands

      boolean hasCommands()
      Tests if there enqueued commands pending execution.
      Since:
      5.0
    • poll

      Command poll()
      Removes first Command from the command queue if available.
      Since:
      5.0
    • channel

      ByteChannel channel()
      Returns the underlying I/O channel associated with this session.
      Returns:
      the I/O channel.
    • getRemoteAddress

      SocketAddress getRemoteAddress()
      Returns address of the remote peer.
      Returns:
      socket address.
    • getLocalAddress

      SocketAddress getLocalAddress()
      Returns local address.
      Returns:
      socket address.
    • getEventMask

      int getEventMask()
      Returns mask of I/O evens this session declared interest in.
      Returns:
      I/O event mask.
    • setEventMask

      void setEventMask(int ops)
      Declares interest in I/O event notifications by setting the event mask associated with the session
      Parameters:
      ops - new I/O event mask.
    • setEvent

      void setEvent(int op)
      Declares interest in a particular I/O event type by updating the event mask associated with the session.
      Parameters:
      op - I/O event type.
    • clearEvent

      void clearEvent(int op)
      Clears interest in a particular I/O event type by updating the event mask associated with the session.
      Parameters:
      op - I/O event type.
    • close

      void close()
      Terminates the session gracefully and closes the underlying I/O channel. This method ensures that session termination handshake, such as the one used by the SSL/TLS protocol, is correctly carried out.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
    • getStatus

      IOSession.Status getStatus()
      Returns status of the session:

      IOSession.Status.ACTIVE: session is active.

      IOSession.Status.CLOSING: session is being closed.

      IOSession.Status.CLOSED: session has been terminated.

      Returns:
      session status.
    • getSocketTimeout

      Timeout getSocketTimeout()
      Returns value of the socket timeout in milliseconds. The value of 0 signifies the session cannot time out.
      Specified by:
      getSocketTimeout in interface SocketModalCloseable
      Returns:
      socket timeout.
    • setSocketTimeout

      void setSocketTimeout(Timeout timeout)
      Sets value of the socket timeout in milliseconds. The value of 0 signifies the session cannot time out.

      Please note this operation may affect the last event time.

      Specified by:
      setSocketTimeout in interface SocketModalCloseable
      Parameters:
      timeout - socket timeout.
      See Also:
    • getLastReadTime

      long getLastReadTime()
      Returns timestamp of the last read event.
      Returns:
      timestamp.
    • getLastWriteTime

      long getLastWriteTime()
      Returns timestamp of the last write event.
      Returns:
      timestamp.
    • getLastEventTime

      long getLastEventTime()
      Returns timestamp of the last I/O event including socket timeout reset.
      Returns:
      timestamp.
      See Also:
    • updateReadTime

      void updateReadTime()
      Updates the timestamp of the last read event
    • updateWriteTime

      void updateWriteTime()
      Updates the timestamp of the last write event