public class NioSelectorPool
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.atomic.AtomicInteger |
active |
protected NioBlockingSelector |
blockingSelector |
protected boolean |
enabled |
protected int |
maxSelectors |
protected int |
maxSpareSelectors |
protected java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector> |
selectors |
protected static boolean |
SHARED |
protected java.nio.channels.Selector |
SHARED_SELECTOR |
protected long |
sharedSelectorTimeout |
protected java.util.concurrent.atomic.AtomicInteger |
spare |
Constructor and Description |
---|
NioSelectorPool() |
Modifier and Type | Method and Description |
---|---|
void |
close() |
java.nio.channels.Selector |
get() |
int |
getMaxSelectors() |
int |
getMaxSpareSelectors() |
java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector> |
getSelectors() |
protected java.nio.channels.Selector |
getSharedSelector() |
long |
getSharedSelectorTimeout() |
java.util.concurrent.atomic.AtomicInteger |
getSpare() |
boolean |
isEnabled() |
void |
open() |
void |
put(java.nio.channels.Selector s) |
int |
read(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.
|
int |
read(java.nio.ByteBuffer buf,
NioChannel socket,
java.nio.channels.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(java.nio.ByteBuffer buf,
NioChannel socket,
java.nio.channels.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 java.nio.channels.Selector SHARED_SELECTOR
protected int maxSelectors
protected long sharedSelectorTimeout
protected int maxSpareSelectors
protected boolean enabled
protected java.util.concurrent.atomic.AtomicInteger active
protected java.util.concurrent.atomic.AtomicInteger spare
protected java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector> selectors
protected java.nio.channels.Selector getSharedSelector() throws java.io.IOException
java.io.IOException
public java.nio.channels.Selector get() throws java.io.IOException
java.io.IOException
public void put(java.nio.channels.Selector s) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
public void open() throws java.io.IOException
java.io.IOException
public int write(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.Selector selector, long writeTimeout, boolean block) throws java.io.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 performedjava.io.EOFException
- if write returns -1java.net.SocketTimeoutException
- if the write times outjava.io.IOException
- if an IO Exception occurs in the underlying socket logicpublic int read(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.Selector selector, long readTimeout) throws java.io.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 timeoutjava.io.EOFException
- if read returns -1java.net.SocketTimeoutException
- if the read times outjava.io.IOException
- if an IO Exception occurs in the underlying socket logicpublic int read(java.nio.ByteBuffer buf, NioChannel socket, java.nio.channels.Selector selector, long readTimeout, boolean block) throws java.io.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 reachedjava.io.EOFException
- if read returns -1java.net.SocketTimeoutException
- if the read times outjava.io.IOException
- 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 java.util.concurrent.ConcurrentLinkedQueue<java.nio.channels.Selector> getSelectors()
public java.util.concurrent.atomic.AtomicInteger getSpare()
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.