Package org.apache.tomcat.util.net
Class NioSelectorPool
- java.lang.Object
-
- org.apache.tomcat.util.net.NioSelectorPool
-
public class NioSelectorPool extends java.lang.ObjectThread safe non blocking selector pool
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicIntegeractiveprotected NioBlockingSelectorblockingSelectorprotected booleanenabledprotected intmaxSelectorsprotected intmaxSpareSelectorsprotected java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector>selectorsprotected booleansharedprotected java.nio.channels.SelectorsharedSelectorprotected longsharedSelectorTimeoutprotected java.util.concurrent.atomic.AtomicIntegerspare
-
Constructor Summary
Constructors Constructor Description NioSelectorPool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.nio.channels.Selectorget()intgetMaxSelectors()intgetMaxSpareSelectors()java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector>getSelectors()protected java.nio.channels.SelectorgetSharedSelector()longgetSharedSelectorTimeout()java.util.concurrent.atomic.AtomicIntegergetSpare()booleanisEnabled()booleanisShared()voidopen(java.lang.String name)voidput(java.nio.channels.Selector s)intread(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.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(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.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 Detail
-
blockingSelector
protected NioBlockingSelector blockingSelector
-
sharedSelector
protected volatile java.nio.channels.Selector sharedSelector
-
shared
protected boolean shared
-
maxSelectors
protected int maxSelectors
-
sharedSelectorTimeout
protected long sharedSelectorTimeout
-
maxSpareSelectors
protected int maxSpareSelectors
-
enabled
protected boolean enabled
-
active
protected java.util.concurrent.atomic.AtomicInteger active
-
spare
protected java.util.concurrent.atomic.AtomicInteger spare
-
selectors
protected java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector> selectors
-
-
Method Detail
-
getSharedSelector
protected java.nio.channels.Selector getSharedSelector() throws java.io.IOException- Throws:
java.io.IOException
-
get
public java.nio.channels.Selector get() throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.nio.channels.Selector s) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
open
public void open(java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.Selector selector, long writeTimeout) throws java.io.IOExceptionPerforms 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:
java.io.EOFException- if write returns -1java.net.SocketTimeoutException- if the write times outjava.io.IOException- if an IO Exception occurs in the underlying socket logic
-
read
public int read(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.Selector selector, long readTimeout) throws java.io.IOExceptionPerforms 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:
java.io.EOFException- if read returns -1java.net.SocketTimeoutException- if the read times outjava.io.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 java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector> getSelectors()
-
getSpare
public java.util.concurrent.atomic.AtomicInteger getSpare()
-
isShared
public boolean isShared()
-
setShared
public void setShared(boolean shared)
-
-