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 boolean |
shared |
protected Selector |
sharedSelector |
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() |
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).
|
protected NioBlockingSelector blockingSelector
protected volatile Selector sharedSelector
protected boolean shared
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(String name) throws IOException
IOException
public int write(ByteBuffer buf, NioChannel socket, Selector selector, long writeTimeout) 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 timeoutEOFException
- 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 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()
public boolean isShared()
public void setShared(boolean shared)
Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.