public class NioSelectorPool extends Object
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 static boolean |
SHARED |
protected Selector |
SHARED_SELECTOR |
protected long |
sharedSelectorTimeout |
protected AtomicInteger |
spare |
Constructor and Description |
---|
NioSelectorPool() |
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() |
void |
open() |
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.
|
int |
read(ByteBuffer buf,
NioChannel socket,
Selector selector,
long readTimeout,
boolean block)
Performs a read using the bytebuffer for data to be read and a selector to register for events should
you have the block=true.
|
void |
setEnabled(boolean enabled) |
void |
setMaxSelectors(int maxSelectors) |
void |
setMaxSpareSelectors(int maxSpareSelectors) |
void |
setSharedSelectorTimeout(long sharedSelectorTimeout) |
int |
write(ByteBuffer buf,
NioChannel socket,
Selector selector,
long writeTimeout,
boolean block)
Performs a write using the bytebuffer for data to be written and a
selector to block (if blocking is requested).
|
protected static final boolean SHARED
protected NioBlockingSelector blockingSelector
protected volatile Selector SHARED_SELECTOR
protected int maxSelectors
protected long sharedSelectorTimeout
protected int maxSpareSelectors
protected boolean enabled
protected AtomicInteger active
protected AtomicInteger spare
protected ConcurrentLinkedQueue<Selector> selectors
protected Selector getSharedSelector() throws IOException
IOException
public Selector get() throws IOException
IOException
public void put(Selector s) throws IOException
IOException
public void close() throws IOException
IOException
public void open() throws IOException
IOException
public int write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout, boolean block) throws IOException
selector
parameter is null, and blocking is requested then
it will perform a busy write that could take up a lot of CPU cycles.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 timeoutblock
- true
to perform a blocking write
otherwise a non-blocking write will be performedEOFException
- if write returns -1SocketTimeoutException
- if the write times outIOException
- if an IO Exception occurs in the underlying socket logicpublic int read(ByteBuffer buf, NioChannel socket, Selector selector, long readTimeout) throws IOException
selector
parameter is null, then it will perform a busy read that could
take up a lot of CPU cycles.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 timeoutEOFException
- if read returns -1SocketTimeoutException
- if the read times outIOException
- if an IO Exception occurs in the underlying socket logicpublic int read(ByteBuffer buf, NioChannel socket, Selector selector, long readTimeout, boolean block) throws IOException
selector
parameter is null, then it will perform a busy read that could
take up a lot of CPU cycles.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 timeoutblock
- - true if you want to block until data becomes available or timeout time has been reachedEOFException
- if read returns -1SocketTimeoutException
- if the read times outIOException
- if an IO Exception occurs in the underlying socket logicpublic void setMaxSelectors(int maxSelectors)
public void setMaxSpareSelectors(int maxSpareSelectors)
public void setEnabled(boolean enabled)
public void setSharedSelectorTimeout(long sharedSelectorTimeout)
public int getMaxSelectors()
public int getMaxSpareSelectors()
public boolean isEnabled()
public long getSharedSelectorTimeout()
public ConcurrentLinkedQueue<Selector> getSelectors()
public AtomicInteger getSpare()
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.