Class SelectionKeyUDT

java.lang.Object
java.nio.channels.SelectionKey
com.barchart.udt.nio.SelectionKeyUDT
All Implemented Interfaces:
Comparable<SelectionKeyUDT>

public class SelectionKeyUDT extends SelectionKey implements Comparable<SelectionKeyUDT>
UDT selection key implementation.
  • Field Details

    • HAS_READ

      protected static final int HAS_READ
      JDK interest to Epoll READ mapping.
      See Also:
    • HAS_WRITE

      protected static final int HAS_WRITE
      JDK interest to Epoll WRITE mapping.
      See Also:
    • log

      protected static final org.slf4j.Logger log
    • channelUDT

      private final ChannelUDT channelUDT
      Channel bound to the key.
    • epollOpt

      private volatile EpollUDT.Opt epollOpt
      Requested interest in epoll format.
    • interestOps

      private volatile int interestOps
      Requested interest in JDK format.
    • isValid

      private volatile boolean isValid
      Key validity state. Key is valid when created, and invalid when canceled.
    • readyOps

      private volatile int readyOps
      Reported ready interest.
    • resultIndex

      private volatile int resultIndex
      Correlation index for doRead(int) vs doWrite(int)
    • selectorUDT

      private final SelectorUDT selectorUDT
      Selector bound to the key.
  • Constructor Details

  • Method Details

    • from

      protected static EpollUDT.Opt from(int interestOps)
      Convert select options : from jdk into epoll.
    • toStringOps

      public static final String toStringOps(int selectOps)
      Render select options.
    • assertValidKey

      protected void assertValidKey() throws CancelledKeyException
      Ensure key is NOT canceled.
      Throws:
      CancelledKeyException
    • assertValidOps

      protected void assertValidOps(int interestOps)
      Ensure only permitted interest mask bits are present.
    • cancel

      public void cancel()
      Specified by:
      cancel in class SelectionKey
    • channel

      public SelectableChannel channel()
      Specified by:
      channel in class SelectionKey
    • channelUDT

      protected ChannelUDT channelUDT()
      Underlying UDT channel.
    • compareTo

      public int compareTo(SelectionKeyUDT that)
      Specified by:
      compareTo in interface Comparable<SelectionKeyUDT>
    • doRead

      protected boolean doRead(int resultIndex)
      Apply READ readiness according to KindUDT channel role.

      Note: doRead(int) is invoked before doWrite(int)

      Sockets with exceptions are returned to both read and write sets.

      Returns:
      Should report ready-state change?
    • doWrite

      protected boolean doWrite(int resultIndex)
      Apply WRITE readiness according to KindUDT channel role.

      Note: doRead(int) is invoked before doWrite(int)

      Sockets with exceptions are returned to both read and write sets.

      Returns:
      Should report ready-state change?
    • epollOpt

      protected EpollUDT.Opt epollOpt()
      Requested interest in epoll format.
    • epollUDT

      protected EpollUDT epollUDT()
      Epoll bound to this key.
    • equals

      public boolean equals(Object otherKey)
      Key equality based on socket-id.
      Overrides:
      equals in class Object
    • hasError

      boolean hasError() throws ExceptionUDT
      Check socket error condition.
      Throws:
      ExceptionUDT
    • hashCode

      public int hashCode()
      Key hach code based on socket-id.
      Overrides:
      hashCode in class Object
    • interestOps

      public int interestOps()
      Specified by:
      interestOps in class SelectionKey
    • interestOps

      public SelectionKey interestOps(int interestOps)
      Specified by:
      interestOps in class SelectionKey
    • isSocketBroken

      protected boolean isSocketBroken()
      Check socket termination status.
      Returns:
      true if status is StatusUDT.BROKEN or worse
    • isValid

      public boolean isValid()
      Specified by:
      isValid in class SelectionKey
    • kindUDT

      protected KindUDT kindUDT()
      Channel role.
    • logError

      protected void logError(String comment)
      Key processing logic error logger.
    • makeValid

      protected void makeValid(boolean isValid)
      Change socket registration with epoll, and change key validity status.
    • readyOps

      public int readyOps()
      Specified by:
      readyOps in class SelectionKey
    • readyOps

      protected void readyOps(int ops)
    • selector

      public SelectorUDT selector()
      Specified by:
      selector in class SelectionKey
    • socketId

      protected int socketId()
      Id of a socket bound to this key.
    • socketUDT

      protected SocketUDT socketUDT()
      Socket bound to this key.
    • toString

      public String toString()
      Overrides:
      toString in class Object