NioSelectorPool (Apache Tomcat 9.0.37 API Documentation)

org.apache.tomcat.util.net

## Class NioSelectorPool

- java.lang.Object
- - org.apache.tomcat.util.net.NioSelectorPool

-     public class NioSelectorPool
      extends Object

  Thread safe non blocking selector pool

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AtomicInteger` | `active`
    `protected NioBlockingSelector` | `blockingSelector`
    `protected boolean` | `enabled`
    `protected int` | `maxSelectors`
    `protected int` | `maxSpareSelectors`
    `protected ConcurrentLinkedQueue<Selector>` | `selectors`
    `protected boolean` | `shared`
    `protected Selector` | `sharedSelector`
    `protected long` | `sharedSelectorTimeout`
    `protected AtomicInteger` | `spare`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NioSelectorPool()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `Selector` | `get()`
    `int` | `getMaxSelectors()`
    `int` | `getMaxSpareSelectors()`
    `ConcurrentLinkedQueue<Selector>` | `getSelectors()`
    `protected Selector` | `getSharedSelector()`
    `long` | `getSharedSelectorTimeout()`
    `AtomicInteger` | `getSpare()`
    `boolean` | `isEnabled()`
    `boolean` | `isShared()`
    `void` | `open(String name)`
    `void` | `put(Selector s)`
    `int` | `read(ByteBuffer buf, NioChannel socket, Selector selector, long readTimeout)` Performs a blocking read using the bytebuffer for data to be read and a selector to block.
    `void` | `setEnabled(boolean enabled)`
    `void` | `setMaxSelectors(int maxSelectors)`
    `void` | `setMaxSpareSelectors(int maxSpareSelectors)`
    `void` | `setShared(boolean shared)`
    `void` | `setSharedSelectorTimeout(long sharedSelectorTimeout)`
    `int` | `write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout)` Performs a write using the bytebuffer for data to be written and a selector to block (if blocking is requested).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### blockingSelector

          protected NioBlockingSelector blockingSelector

    - #### sharedSelector

          protected volatile Selector sharedSelector

    - #### shared

          protected boolean shared

    - #### maxSelectors

          protected int maxSelectors

    - #### sharedSelectorTimeout

          protected long sharedSelectorTimeout

    - #### maxSpareSelectors

          protected int maxSpareSelectors

    - #### enabled

          protected boolean enabled

    - #### active

          protected AtomicInteger active

    - #### spare

          protected AtomicInteger spare

    - #### selectors

          protected ConcurrentLinkedQueue<Selector> selectors

  - ### Constructor Detail

    - #### NioSelectorPool

          public NioSelectorPool()

  - ### Method Detail

    - #### getSharedSelector

          protected Selector getSharedSelector()
                                        throws IOException

      Throws:
        `IOException`

    - #### get

          public Selector get()
                       throws IOException

      Throws:
        `IOException`

    - #### put

          public void put(Selector s)
                   throws IOException

      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Throws:
        `IOException`

    - #### open

          public void open(String name)
                    throws IOException

      Throws:
        `IOException`

    - #### write

          public int write(ByteBuffer buf,
                           NioChannel socket,
                           Selector selector,
                           long writeTimeout)
                    throws IOException

      Performs a write using the bytebuffer for data to be written and a selector to block (if blocking is requested). If the `selector` parameter is null, and blocking is requested then it will perform a busy write that could take up a lot of CPU cycles.
      Parameters:
        `buf` - The buffer containing the data, we will write as long as `(buf.hasRemaining()==true)`
        `socket` - The socket to write data to
        `selector` - The selector to use for blocking, if null then a busy write will be initiated
        `writeTimeout` - The timeout for this write operation in milliseconds, -1 means no timeout
      Returns:
        the number of bytes written
      Throws:
        `EOFException` - if write returns -1
        `SocketTimeoutException` - if the write times out
        `IOException` - if an IO Exception occurs in the underlying socket logic

    - #### read

          public int read(ByteBuffer buf,
                          NioChannel socket,
                          Selector selector,
                          long readTimeout)
                   throws IOException

      Performs a blocking read using the bytebuffer for data to be read and a selector to block. If the `selector` parameter is null, then it will perform a busy read that could take up a lot of CPU cycles.
      Parameters:
        `buf` - ByteBuffer - the buffer containing the data, we will read as until we have read at least one byte or we timed out
        `socket` - SocketChannel - the socket to write data to
        `selector` - Selector - the selector to use for blocking, if null then a busy read will be initiated
        `readTimeout` - long - the timeout for this read operation in milliseconds, -1 means no timeout
      Returns:
        the number of bytes read
      Throws:
        `EOFException` - if read returns -1
        `SocketTimeoutException` - if the read times out
        `IOException` - if an IO Exception occurs in the underlying socket logic

    - #### setMaxSelectors

          public void setMaxSelectors(int maxSelectors)

    - #### setMaxSpareSelectors

          public void setMaxSpareSelectors(int maxSpareSelectors)

    - #### setEnabled

          public void setEnabled(boolean enabled)

    - #### setSharedSelectorTimeout

          public void setSharedSelectorTimeout(long sharedSelectorTimeout)

    - #### getMaxSelectors

          public int getMaxSelectors()

    - #### getMaxSpareSelectors

          public int getMaxSpareSelectors()

    - #### isEnabled

          public boolean isEnabled()

    - #### getSharedSelectorTimeout

          public long getSharedSelectorTimeout()

    - #### getSelectors

          public ConcurrentLinkedQueue<Selector> getSelectors()

    - #### getSpare

          public AtomicInteger getSpare()

    - #### isShared

          public boolean isShared()

    - #### setShared

          public void setShared(boolean shared)

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.