|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.glassfish.grizzly.nio.NIOConnection
public abstract class NIOConnection
Common Connection implementation for Java NIO Connections.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.glassfish.grizzly.Connection |
|---|
Connection.CloseListener, Connection.CloseType |
| Field Summary | |
|---|---|
protected TaskQueue<AsyncReadQueueRecord> |
asyncReadQueue
|
protected TaskQueue<AsyncWriteQueueRecord> |
asyncWriteQueue
|
protected AttributeHolder |
attributes
|
protected java.nio.channels.SelectableChannel |
channel
|
protected java.util.concurrent.atomic.AtomicReference<Connection.CloseType> |
closeFlag
|
protected boolean |
isBlocking
|
protected boolean |
isStandalone
|
protected int |
maxAsyncWriteQueueSize
|
protected MonitoringConfigImpl<ConnectionProbe> |
monitoringConfig
Connection probes |
protected Processor |
processor
|
protected ProcessorSelector |
processorSelector
|
protected int |
readBufferSize
|
protected long |
readTimeoutMillis
|
protected java.nio.channels.SelectionKey |
selectionKey
|
protected SelectorRunner |
selectorRunner
|
protected NIOTransport |
transport
|
protected int |
writeBufferSize
|
protected long |
writeTimeoutMillis
|
protected short |
zeroByteReadCount
|
| Constructor Summary | |
|---|---|
NIOConnection(NIOTransport transport)
|
|
| Method Summary | ||
|---|---|---|
void |
addCloseListener(Connection.CloseListener closeListener)
Add the Connection.CloseListener, which will be notified once Connection
will be closed. |
|
void |
attachToSelectorRunner(SelectorRunner selectorRunner)
|
|
protected void |
checkEmptyRead(int size)
|
|
GrizzlyFuture<Connection> |
close()
Close the Connection |
|
void |
close(CompletionHandler<Connection> completionHandler)
Close the Connection |
|
protected void |
close0(CompletionHandler<Connection> completionHandler,
boolean isClosedLocally)
|
|
void |
closeSilently()
Close the Connection silently, no notification required on
completion or failure. |
|
void |
configureBlocking(boolean isBlocking)
Sets the Connection mode. |
|
void |
configureStandalone(boolean isStandalone)
|
|
void |
detachSelectorRunner()
|
|
void |
disableIOEvent(IOEvent ioEvent)
|
|
void |
enableIOEvent(IOEvent ioEvent)
|
|
TaskQueue<AsyncReadQueueRecord> |
getAsyncReadQueue()
|
|
TaskQueue<AsyncWriteQueueRecord> |
getAsyncWriteQueue()
|
|
AttributeHolder |
getAttributes()
Get associated AttributeHolder. |
|
java.nio.channels.SelectableChannel |
getChannel()
|
|
int |
getMaxAsyncWriteQueueSize()
Get the max size (in bytes) of asynchronous write queue associated with connection. |
|
MonitoringConfig<ConnectionProbe> |
getMonitoringConfig()
Return the object associated MonitoringConfig. |
|
Processor |
getProcessor()
Gets the default Processor, which will process Connection
I/O events. |
|
ProcessorSelector |
getProcessorSelector()
Gets the default ProcessorSelector, which will be used to get
Processor to process Connection I/O events, in case if
this Connection's Processor is null. |
|
int |
getReadBufferSize()
Get the default size of Buffers, which will be allocated for
reading data from Connection. |
|
long |
getReadTimeout(java.util.concurrent.TimeUnit timeUnit)
|
|
java.nio.channels.SelectionKey |
getSelectionKey()
|
|
SelectorRunner |
getSelectorRunner()
|
|
Transport |
getTransport()
Get the Transport, to which this Connection belongs to. |
|
int |
getWriteBufferSize()
Get the default size of Buffers, which will be allocated for
writing data to Connection. |
|
long |
getWriteTimeout(java.util.concurrent.TimeUnit timeUnit)
|
|
boolean |
isBlocking()
|
|
boolean |
isOpen()
Is Connection open and ready. |
|
boolean |
isStandalone()
|
|
void |
notifyConnectionError(java.lang.Throwable error)
Method gets invoked, when error occur during the Connection lifecycle. |
|
protected static void |
notifyIOEventDisabled(NIOConnection connection,
IOEvent ioEvent)
Notify registered ConnectionProbes about the IO Event disabled event. |
|
protected static void |
notifyIOEventEnabled(NIOConnection connection,
IOEvent ioEvent)
Notify registered ConnectionProbes about the IO Event enabled event. |
|
protected static void |
notifyIOEventReady(NIOConnection connection,
IOEvent ioEvent)
Notify registered ConnectionProbes about the IO Event ready event. |
|
protected static void |
notifyProbesAccept(NIOConnection serverConnection,
NIOConnection clientConnection)
Notify registered ConnectionProbes about the accept event. |
|
protected static void |
notifyProbesBind(NIOConnection connection)
Notify registered ConnectionProbes about the bind event. |
|
protected static void |
notifyProbesClose(NIOConnection connection)
Notify registered ConnectionProbes about the close event. |
|
protected static void |
notifyProbesConnect(NIOConnection connection)
Notify registered ConnectionProbes about the connect event. |
|
protected static void |
notifyProbesError(NIOConnection connection,
java.lang.Throwable error)
Notify registered ConnectionProbes about the error. |
|
protected static void |
notifyProbesRead(NIOConnection connection,
Buffer data,
int size)
Notify registered ConnectionProbes about the read event. |
|
protected static void |
notifyProbesWrite(NIOConnection connection,
Buffer data,
long size)
Notify registered ConnectionProbes about the write event. |
|
Processor |
obtainProcessor(IOEvent ioEvent)
Gets the Processor, which will process Connection
I/O event. |
|
|
obtainProcessorState(Processor processor,
NullaryFunction<E> factory)
Returns the Processor state associated with this Connection. |
|
protected abstract void |
preClose()
|
|
|
read()
Method reads data. |
|
|
read(CompletionHandler<ReadResult<M,java.net.SocketAddress>> completionHandler)
|
|
boolean |
removeCloseListener(Connection.CloseListener closeListener)
Remove the Connection.CloseListener. |
|
protected void |
setChannel(java.nio.channels.SelectableChannel channel)
|
|
void |
setMaxAsyncWriteQueueSize(int maxAsyncWriteQueueSize)
Set the max size (in bytes) of asynchronous write queue associated with connection. |
|
void |
setProcessor(Processor preferableProcessor)
Sets the default Processor, which will process Connection
I/O events. |
|
void |
setProcessorSelector(ProcessorSelector preferableProcessorSelector)
Sets the default ProcessorSelector, which will be used to get
Processor to process Connection I/O events, in case if
this Connection's Processor is null. |
|
void |
setReadBufferSize(int readBufferSize)
Set the default size of Buffers, which will be allocated for
reading data from Connection. |
|
void |
setReadTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
|
|
protected void |
setSelectionKey(java.nio.channels.SelectionKey selectionKey)
|
|
protected void |
setSelectorRunner(SelectorRunner selectorRunner)
|
|
void |
setWriteBufferSize(int writeBufferSize)
Set the default size of Buffers, which will be allocated for
writing data to Connection. |
|
void |
setWriteTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
|
|
void |
simulateIOEvent(IOEvent ioEvent)
|
|
|
write(M message)
Method writes the buffer. |
|
|
write(M message,
CompletionHandler<WriteResult<M,java.net.SocketAddress>> completionHandler)
Method writes the buffer. |
|
|
write(M message,
CompletionHandler<WriteResult<M,java.net.SocketAddress>> completionHandler,
PushBackHandler pushbackHandler)
Method writes the buffer. |
|
|
write(java.net.SocketAddress dstAddress,
M message,
CompletionHandler<WriteResult<M,java.net.SocketAddress>> completionHandler,
PushBackHandler pushbackHandler)
Method writes the buffer to the specific address. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.glassfish.grizzly.Connection |
|---|
getLocalAddress, getPeerAddress |
| Field Detail |
|---|
protected final NIOTransport transport
protected volatile int readBufferSize
protected volatile int writeBufferSize
protected volatile int maxAsyncWriteQueueSize
protected volatile long readTimeoutMillis
protected volatile long writeTimeoutMillis
protected volatile java.nio.channels.SelectableChannel channel
protected volatile java.nio.channels.SelectionKey selectionKey
protected volatile SelectorRunner selectorRunner
protected volatile Processor processor
protected volatile ProcessorSelector processorSelector
protected final AttributeHolder attributes
protected final TaskQueue<AsyncReadQueueRecord> asyncReadQueue
protected final TaskQueue<AsyncWriteQueueRecord> asyncWriteQueue
protected final java.util.concurrent.atomic.AtomicReference<Connection.CloseType> closeFlag
protected volatile boolean isBlocking
protected volatile boolean isStandalone
protected short zeroByteReadCount
protected final MonitoringConfigImpl<ConnectionProbe> monitoringConfig
| Constructor Detail |
|---|
public NIOConnection(NIOTransport transport)
| Method Detail |
|---|
public void configureBlocking(boolean isBlocking)
ConnectionConnection mode.
configureBlocking in interface Connection<java.net.SocketAddress>isBlocking - the Connection mode. true,
if Connection should operate in blocking mode, or
false otherwise.public boolean isBlocking()
isBlocking in interface Connection<java.net.SocketAddress>Connection mode.
true, if Connection is operating in blocking mode, or
false otherwise.public void configureStandalone(boolean isStandalone)
configureStandalone in interface Connection<java.net.SocketAddress>public boolean isStandalone()
isStandalone in interface Connection<java.net.SocketAddress>public Transport getTransport()
ConnectionTransport, to which this Connection belongs to.
getTransport in interface Connection<java.net.SocketAddress>Transport, to which this Connection belongs to.public int getReadBufferSize()
ConnectionBuffers, which will be allocated for
reading data from Connection.
getReadBufferSize in interface Connection<java.net.SocketAddress>Buffers, which will be allocated for
reading data from Connection.public void setReadBufferSize(int readBufferSize)
ConnectionBuffers, which will be allocated for
reading data from Connection.
setReadBufferSize in interface Connection<java.net.SocketAddress>readBufferSize - the default size of Buffers, which will
be allocated for reading data from Connection.public int getWriteBufferSize()
ConnectionBuffers, which will be allocated for
writing data to Connection.
getWriteBufferSize in interface Connection<java.net.SocketAddress>Buffers, which will be allocated for
writing data to Connection.public void setWriteBufferSize(int writeBufferSize)
ConnectionBuffers, which will be allocated for
writing data to Connection.
setWriteBufferSize in interface Connection<java.net.SocketAddress>writeBufferSize - the default size of Buffers, which will
be allocated for writing data to Connection.public int getMaxAsyncWriteQueueSize()
getMaxAsyncWriteQueueSize in interface Connection<java.net.SocketAddress>public void setMaxAsyncWriteQueueSize(int maxAsyncWriteQueueSize)
setMaxAsyncWriteQueueSize in interface Connection<java.net.SocketAddress>maxAsyncWriteQueueSize - the max size (in bytes) of asynchronous
write queue associated with connection.public long getReadTimeout(java.util.concurrent.TimeUnit timeUnit)
getReadTimeout in interface Connection<java.net.SocketAddress>
public void setReadTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
setReadTimeout in interface Connection<java.net.SocketAddress>public long getWriteTimeout(java.util.concurrent.TimeUnit timeUnit)
getWriteTimeout in interface Connection<java.net.SocketAddress>
public void setWriteTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
setWriteTimeout in interface Connection<java.net.SocketAddress>public SelectorRunner getSelectorRunner()
protected void setSelectorRunner(SelectorRunner selectorRunner)
public void attachToSelectorRunner(SelectorRunner selectorRunner)
throws java.io.IOException
java.io.IOException
public void detachSelectorRunner()
throws java.io.IOException
java.io.IOExceptionpublic java.nio.channels.SelectableChannel getChannel()
protected void setChannel(java.nio.channels.SelectableChannel channel)
public java.nio.channels.SelectionKey getSelectionKey()
protected void setSelectionKey(java.nio.channels.SelectionKey selectionKey)
public Processor obtainProcessor(IOEvent ioEvent)
ConnectionProcessor, which will process Connection
I/O event.
If Processor is null, - then Transport will try
to get Processor using Connection's
ProcessorSelector.select(IOEvent, Connection). If
ProcessorSelector, associated withthe Connection is also
null - will ask Transport for a Processor.
obtainProcessor in interface Connection<java.net.SocketAddress>Processor, which will process
Connection I/O events.public Processor getProcessor()
ConnectionProcessor, which will process Connection
I/O events.
If Processor is null, - then Transport will try
to get Processor using Connection's
ProcessorSelector.select(IOEvent, Connection). If
ProcessorSelector, associated withthe Connection is also
null - Transport will try to get Processor
using own settings.
getProcessor in interface Connection<java.net.SocketAddress>Processor, which will process
Connection I/O events.public void setProcessor(Processor preferableProcessor)
ConnectionProcessor, which will process Connection
I/O events.
If Processor is null, - then Transport will try
to get Processor using Connection's
ProcessorSelector.select(IOEvent, Connection). If
ProcessorSelector, associated withthe Connection is also
null - Transport will try to get Processor
using own settings.
setProcessor in interface Connection<java.net.SocketAddress>preferableProcessor - the default Processor, which will
process Connection I/O events.public ProcessorSelector getProcessorSelector()
ConnectionProcessorSelector, which will be used to get
Processor to process Connection I/O events, in case if
this Connection's Processor is null.
getProcessorSelector in interface Connection<java.net.SocketAddress>ProcessorSelector, which will be used to get
Processor to process Connection I/O events, in case if
this Connection's Processor is null.public void setProcessorSelector(ProcessorSelector preferableProcessorSelector)
ConnectionProcessorSelector, which will be used to get
Processor to process Connection I/O events, in case if
this Connection's Processor is null.
setProcessorSelector in interface Connection<java.net.SocketAddress>preferableProcessorSelector - the default ProcessorSelector,
which will be used to get Processor to process Connection
I/O events, in case if this Connection's Processor
is null.
public <E> E obtainProcessorState(Processor processor,
NullaryFunction<E> factory)
ConnectionProcessor state associated with this Connection.
obtainProcessorState in interface Connection<java.net.SocketAddress>processor - Processor
Processor state associated with this Connection.public TaskQueue<AsyncReadQueueRecord> getAsyncReadQueue()
public TaskQueue<AsyncWriteQueueRecord> getAsyncWriteQueue()
public AttributeHolder getAttributes()
AttributeStorageAttributeHolder.
Implementation may return null if AttributeHolder wasn't
initialized yet.
getAttributes in interface AttributeStorageAttributeHolder.
Implementation may return null if AttributeHolder wasn't
initialized yet.public <M> GrizzlyFuture<ReadResult<M,java.net.SocketAddress>> read()
Readable
read in interface Readable<java.net.SocketAddress>Future, using which it's possible to check the resultpublic <M> void read(CompletionHandler<ReadResult<M,java.net.SocketAddress>> completionHandler)
read in interface Readable<java.net.SocketAddress>public <M> GrizzlyFuture<WriteResult<M,java.net.SocketAddress>> write(M message)
Writable
write in interface Writable<java.net.SocketAddress>message - the buffer, from which the data will be written
Future, using which it's possible to check the
result
public <M> void write(M message,
CompletionHandler<WriteResult<M,java.net.SocketAddress>> completionHandler)
Writable
write in interface Writable<java.net.SocketAddress>message - the buffer, from which the data will be writtencompletionHandler - CompletionHandler,
which will get notified, when write will be completed
public <M> void write(M message,
CompletionHandler<WriteResult<M,java.net.SocketAddress>> completionHandler,
PushBackHandler pushbackHandler)
Writable
write in interface Writable<java.net.SocketAddress>message - the buffer, from which the data will be writtencompletionHandler - CompletionHandler,
which will get notified, when write will be completedpushbackHandler - PushBackHandler, which will be notified
if message was accepted by transport write queue or refused
public <M> void write(java.net.SocketAddress dstAddress,
M message,
CompletionHandler<WriteResult<M,java.net.SocketAddress>> completionHandler,
PushBackHandler pushbackHandler)
Writable
write in interface Writable<java.net.SocketAddress>dstAddress - the destination address the buffer will be
sent tomessage - the buffer, from which the data will be writtencompletionHandler - CompletionHandler,
which will get notified, when write will be completedpushbackHandler - PushBackHandler, which will be notified
if message was accepted by transport write queue or refusedpublic boolean isOpen()
ConnectionConnection open and ready.
Returns true, if connection is open and ready, or false
otherwise.
isOpen in interface Connection<java.net.SocketAddress>public GrizzlyFuture<Connection> close()
ConnectionConnection
close in interface Closeable<Connection>close in interface Connection<java.net.SocketAddress>Future, which could be checked in case, if close operation
will be run asynchronouslypublic void close(CompletionHandler<Connection> completionHandler)
ConnectionConnection
close in interface Closeable<Connection>close in interface Connection<java.net.SocketAddress>completionHandler - CompletionHandler to be called, when
the connection is closed.public final void closeSilently()
ConnectionConnection silently, no notification required on
completion or failure.
closeSilently in interface Connection<java.net.SocketAddress>
protected void close0(CompletionHandler<Connection> completionHandler,
boolean isClosedLocally)
public void addCloseListener(Connection.CloseListener closeListener)
Connection.CloseListener, which will be notified once Connection
will be closed.
addCloseListener in interface Connection<java.net.SocketAddress>closeListener - Connection.CloseListener.public boolean removeCloseListener(Connection.CloseListener closeListener)
Connection.CloseListener.
removeCloseListener in interface Connection<java.net.SocketAddress>closeListener - Connection.CloseListener.public void notifyConnectionError(java.lang.Throwable error)
notifyConnectionError in interface Connection<java.net.SocketAddress>error - Throwable.public final MonitoringConfig<ConnectionProbe> getMonitoringConfig()
MonitoringConfig.
getMonitoringConfig in interface Connection<java.net.SocketAddress>getMonitoringConfig in interface MonitoringAware<ConnectionProbe>MonitoringConfig.protected static void notifyProbesBind(NIOConnection connection)
ConnectionProbes about the bind event.
connection - the Connection event occurred on.
protected static void notifyProbesAccept(NIOConnection serverConnection,
NIOConnection clientConnection)
ConnectionProbes about the accept event.
serverConnection - the server Connection, which accepted the client connection.clientConnection - the client Connection.protected static void notifyProbesConnect(NIOConnection connection)
ConnectionProbes about the connect event.
connection - the Connection event occurred on.
protected static void notifyProbesRead(NIOConnection connection,
Buffer data,
int size)
ConnectionProbes about the read event.
protected static void notifyProbesWrite(NIOConnection connection,
Buffer data,
long size)
ConnectionProbes about the write event.
protected static void notifyIOEventReady(NIOConnection connection,
IOEvent ioEvent)
ConnectionProbes about the IO Event ready event.
connection - the Connection event occurred on.ioEvent - the IOEvent.
protected static void notifyIOEventEnabled(NIOConnection connection,
IOEvent ioEvent)
ConnectionProbes about the IO Event enabled event.
connection - the Connection event occurred on.ioEvent - the IOEvent.
protected static void notifyIOEventDisabled(NIOConnection connection,
IOEvent ioEvent)
ConnectionProbes about the IO Event disabled event.
connection - the Connection event occurred on.ioEvent - the IOEvent.protected static void notifyProbesClose(NIOConnection connection)
ConnectionProbes about the close event.
connection - the Connection event occurred on.
protected static void notifyProbesError(NIOConnection connection,
java.lang.Throwable error)
ConnectionProbes about the error.
connection - the Connection event occurred on.protected abstract void preClose()
public void simulateIOEvent(IOEvent ioEvent)
throws java.io.IOException
simulateIOEvent in interface Connection<java.net.SocketAddress>java.io.IOException
public final void enableIOEvent(IOEvent ioEvent)
throws java.io.IOException
enableIOEvent in interface Connection<java.net.SocketAddress>java.io.IOException
public final void disableIOEvent(IOEvent ioEvent)
throws java.io.IOException
disableIOEvent in interface Connection<java.net.SocketAddress>java.io.IOExceptionprotected final void checkEmptyRead(int size)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||