Class SelectorUDT

All Implemented Interfaces:
Closeable, AutoCloseable

public class SelectorUDT extends AbstractSelector
selector

design guidelines:

1) follow general contracts of jdk 6 nio; see barchart-udt-reference-jdk6

2) adapt to how netty is doing select; see NioEventLoop

note: you must use SelectorProviderUDT.openSelector() to obtain instance of this class; do not use JDK Selector.open()

  • Field Details

    • log

      protected static final org.slf4j.Logger log
    • epollUDT

      private final EpollUDT epollUDT
    • maximimSelectorSize

      public final int maximimSelectorSize
    • readBuffer

      private final IntBuffer readBuffer
      list of epoll sockets with read interest
    • registeredKeyMap

      private final ConcurrentMap<Integer,SelectionKeyUDT> registeredKeyMap
      [ socket-id : selection-key ]
    • registeredKeySet

      private final Set<? extends SelectionKey> registeredKeySet
      public view : immutable
    • resultIndex

      private volatile int resultIndex
      tracks correlation read with write for the same key
    • selectedKeyMap

      private final ConcurrentMap<SelectionKeyUDT,SelectionKeyUDT> selectedKeyMap
      set of keys with data ready for an operation
    • selectedKeySet

      private final Set<? extends SelectionKey> selectedKeySet
      public view : removal allowed, but not addition
    • selectLock

      private final Lock selectLock
      select is exclusive
    • sizeBuffer

      private final IntBuffer sizeBuffer
      reported epoll socket list sizes
    • terminatedKeyMap

      private final ConcurrentMap<SelectionKeyUDT,SelectionKeyUDT> terminatedKeyMap
      Canceled keys.
    • wakeupBaseCount

      private volatile int wakeupBaseCount
      guarded by
      invalid reference
      #doSelectLocked
    • wakeupStepCount

      private volatile int wakeupStepCount
    • writeBuffer

      private final IntBuffer writeBuffer
      list of epoll sockets with write interest
  • Constructor Details

  • Method Details

    • open

      protected static Selector open(TypeUDT type) throws IOException
      use this call to instantiate a selector for UDT
      Throws:
      IOException
    • cancel

      protected void cancel(SelectionKeyUDT keyUDT)
      Enqueue cancel request.
    • doCancel

      protected void doCancel()
      Process pending cancel requests.
    • doEpollEnter

      protected int doEpollEnter(long millisTimeout) throws IOException
      Parameters:
      millisTimeout - invalid input: '<'0 : invinite; =0 : immediate; >0 : finite;
      Throws:
      IOException
    • doEpollExclusive

      protected int doEpollExclusive(long millisTimeout) throws IOException
      Parameters:
      millisTimeout - invalid input: '<'0 : invinite; =0 : immediate; >0 : finite;
      Returns:
      invalid input: '<'0 : should not happen =0 : means nothing was selected/timeout >0 : number of selected keys
      Throws:
      IOException
    • doEpollSelect

      protected int doEpollSelect(long millisTimeout) throws ExceptionUDT
      Parameters:
      millisTimeout - invalid input: '<'0 : infinite =0 : immediate >0 : finite
      Throws:
      ExceptionUDT
    • doEpollSelectUDT

      protected int doEpollSelectUDT(long timeout) throws ExceptionUDT
      Throws:
      ExceptionUDT
    • doResults

      protected void doResults()
    • doResultsRead

      protected void doResultsRead(int resultIndex)
    • doResultsWrite

      protected void doResultsWrite(int resultIndex)
    • epollUDT

      protected EpollUDT epollUDT()
    • implCloseSelector

      protected void implCloseSelector() throws IOException
      Specified by:
      implCloseSelector in class AbstractSelector
      Throws:
      IOException
    • keys

      public Set<SelectionKey> keys()
      Specified by:
      keys in class Selector
    • logSocketId

      protected void logSocketId(String title, int socketId)
    • register

      protected SelectionKey register(AbstractSelectableChannel channel, int interestOps, Object attachment)
      Specified by:
      register in class AbstractSelector
    • select

      public int select() throws IOException
      Specified by:
      select in class Selector
      Throws:
      IOException
    • select

      public int select(long timeout) throws IOException
      Specified by:
      select in class Selector
      Throws:
      IOException
    • selectedKeys

      public Set<SelectionKey> selectedKeys()
      Specified by:
      selectedKeys in class Selector
    • selectNow

      public int selectNow() throws IOException
      Specified by:
      selectNow in class Selector
      Throws:
      IOException
    • wakeup

      public Selector wakeup()
      Specified by:
      wakeup in class Selector
    • wakeupIsPending

      protected boolean wakeupIsPending()
    • wakeupMarkBase

      protected void wakeupMarkBase()