Package org.apache.tomcat.util.net
Class NioSelectorPool
java.lang.Object
org.apache.tomcat.util.net.NioSelectorPool
Thread safe non blocking selector pool
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AtomicIntegerprotected NioBlockingSelectorprotected booleanprotected intprotected intprotected ConcurrentLinkedQueue<Selector>protected booleanprotected Selectorprotected longprotected AtomicInteger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()get()intintprotected SelectorlonggetSpare()booleanbooleanisShared()voidvoidintread(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.voidsetEnabled(boolean enabled) voidsetMaxSelectors(int maxSelectors) voidsetMaxSpareSelectors(int maxSpareSelectors) voidsetShared(boolean shared) voidsetSharedSelectorTimeout(long sharedSelectorTimeout) intwrite(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).
-
Field Details
-
blockingSelector
-
maxSelectors
protected int maxSelectors -
maxSpareSelectors
protected int maxSpareSelectors -
enabled
protected boolean enabled -
active
-
spare
-
selectors
-
-
Constructor Details
-
NioSelectorPool
public NioSelectorPool()
-
-
Method Details
-
get
- Throws:
IOException
-
put
- Throws:
IOException
-
close
- Throws:
IOException
-
open
- 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 theselectorparameter 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 toselector- The selector to use for blocking, if null then a busy write will be initiatedwriteTimeout- The timeout for this write operation in milliseconds, -1 means no timeout- Returns:
- the number of bytes written
- Throws:
EOFException- if write returns -1SocketTimeoutException- if the write times outIOException- 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 theselectorparameter 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 outsocket- SocketChannel - the socket to write data toselector- Selector - the selector to use for blocking, if null then a busy read will be initiatedreadTimeout- long - the timeout for this read operation in milliseconds, -1 means no timeout- Returns:
- the number of bytes read
- Throws:
EOFException- if read returns -1SocketTimeoutException- if the read times outIOException- 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) -
getMaxSelectors
public int getMaxSelectors() -
getMaxSpareSelectors
public int getMaxSpareSelectors() -
isEnabled
public boolean isEnabled() -
getSelectors
-
getSpare