Class TCPNIOConnection
- java.lang.Object
-
- org.glassfish.grizzly.nio.NIOConnection
-
- org.glassfish.grizzly.nio.transport.TCPNIOConnection
-
- All Implemented Interfaces:
AttributeStorage
,Closeable
,Connection<SocketAddress>
,MonitoringAware<ConnectionProbe>
,OutputSink
,Readable<SocketAddress>
,Writeable<SocketAddress>
- Direct Known Subclasses:
TCPNIOServerConnection
public class TCPNIOConnection extends NIOConnection
Connection
implementation for theTCPNIOTransport
- Author:
- Alexey Stashok
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
TCPNIOConnection.ConnectResultHandler
This interface implementations can be used to be notified about the TCPNIOConnection connect state.-
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Connection
Connection.CloseListener, Connection.CloseType
-
-
Field Summary
-
Fields inherited from class org.glassfish.grizzly.nio.NIOConnection
attributes, channel, connectCloseSemaphoreUpdater, isBlocking, isStandalone, maxAsyncWriteQueueSize, monitoringConfig, NOTIFICATION_CLOSED_COMPLETE, NOTIFICATION_INITIALIZED, processor, processorSelector, readTimeoutMillis, selectionKey, selectorRunner, transport, writeTimeoutMillis, zeroByteReadCount
-
-
Constructor Summary
Constructors Constructor Description TCPNIOConnection(TCPNIOTransport transport, SelectableChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
canWrite()
boolean
canWrite(int length)
Deprecated.protected void
checkConnectFailed(Throwable failure)
Method will be called in order to check if failure happened beforeConnection
was reported as connected.protected void
enableInitialOpRead()
Enables OP_READ if it has never been enabled before.SocketAddress
getLocalAddress()
Returns the local address of this Connection, or null if it is unconnected.SocketAddress
getPeerAddress()
Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.int
getReadBufferSize()
Get the default size ofBuffer
s, which will be allocated for reading data fromConnection
.int
getWriteBufferSize()
Get the default size ofBuffer
s, which will be allocated for writing data toConnection
.void
notifyCanWrite(WriteHandler writeHandler)
Instructs theOutputSink
to invoke the providedWriteHandler
when it is possible to write more bytes (or characters).void
notifyCanWrite(WriteHandler handler, int length)
Deprecated.protected boolean
notifyReady()
protected void
onConnect()
Method will be called, when the connection gets connected.protected void
onRead(Buffer data, int size)
Method will be called, when some data was read on the connectionprotected void
onWrite(Buffer data, long size)
Method will be called, when some data was written on the connectionprotected void
preClose()
protected void
resetProperties()
protected void
setConnectResultHandler(TCPNIOConnection.ConnectResultHandler connectHandler)
void
setReadBufferSize(int readBufferSize)
Set the default size ofBuffer
s, which will be allocated for reading data fromConnection
.protected void
setSelectionKey(SelectionKey selectionKey)
protected void
setSelectorRunner(SelectorRunner selectorRunner)
void
setWriteBufferSize(int writeBufferSize)
Set the default size ofBuffer
s, which will be allocated for writing data toConnection
.protected void
terminate0(CompletionHandler<Closeable> completionHandler, CloseReason closeReason)
String
toString()
-
Methods inherited from class org.glassfish.grizzly.nio.NIOConnection
addCloseListener, addCloseListener, assertOpen, attachToSelectorRunner, checkEmptyRead, close, close, closeFuture, closeGracefully0, closeSilently, closeWithReason, configureBlocking, configureStandalone, detachSelectorRunner, disableIOEvent, doClose, enableIOEvent, executeInEventThread, getAsyncReadQueue, getAsyncWriteQueue, getAttributes, getChannel, getCloseReason, getId, getMaxAsyncWriteQueueSize, getMemoryManager, getMonitoringConfig, getProcessor, getProcessorSelector, getReadTimeout, getSelectionKey, getSelectorRunner, getTransport, getWriteTimeout, isBlocking, isClosed, isOpen, isStandalone, notifyConnectionError, notifyIOEventDisabled, notifyIOEventEnabled, notifyIOEventReady, notifyProbesAccept, notifyProbesBind, notifyProbesClose, notifyProbesConnect, notifyProbesError, notifyProbesRead, notifyProbesWrite, obtainProcessor, obtainProcessorState, read, read, removeCloseListener, removeCloseListener, setChannel, setMaxAsyncWriteQueueSize, setProcessor, setProcessorSelector, setReadTimeout, setWriteTimeout, simulateIOEvent, terminate, terminateSilently, terminateWithReason, write, write, write, write, write
-
-
-
-
Constructor Detail
-
TCPNIOConnection
public TCPNIOConnection(TCPNIOTransport transport, SelectableChannel channel)
-
-
Method Detail
-
setSelectionKey
protected void setSelectionKey(SelectionKey selectionKey)
- Overrides:
setSelectionKey
in classNIOConnection
-
setSelectorRunner
protected void setSelectorRunner(SelectorRunner selectorRunner)
- Overrides:
setSelectorRunner
in classNIOConnection
-
preClose
protected void preClose()
- Overrides:
preClose
in classNIOConnection
-
notifyReady
protected boolean notifyReady()
-
getPeerAddress
public SocketAddress getPeerAddress()
Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.- Returns:
- the address of the endpoint this Connection is connected to, or null if it is unconnected.
-
getLocalAddress
public SocketAddress getLocalAddress()
Returns the local address of this Connection, or null if it is unconnected.- Returns:
- the local address of this Connection, or null if it is unconnected.
-
resetProperties
protected void resetProperties()
-
getReadBufferSize
public int getReadBufferSize()
Get the default size ofBuffer
s, which will be allocated for reading data fromConnection
. The value less or equal to zero will be ignored.- Returns:
- the default size of
Buffer
s, which will be allocated for reading data fromConnection
.
-
setReadBufferSize
public void setReadBufferSize(int readBufferSize)
Set the default size ofBuffer
s, which will be allocated for reading data fromConnection
. The value less or equal to zero will be ignored.- Parameters:
readBufferSize
- the default size ofBuffer
s, which will be allocated for reading data fromConnection
.
-
getWriteBufferSize
public int getWriteBufferSize()
Get the default size ofBuffer
s, which will be allocated for writing data toConnection
.- Returns:
- the default size of
Buffer
s, which will be allocated for writing data toConnection
.
-
setWriteBufferSize
public void setWriteBufferSize(int writeBufferSize)
Set the default size ofBuffer
s, which will be allocated for writing data toConnection
.- Parameters:
writeBufferSize
- the default size ofBuffer
s, which will be allocated for writing data toConnection
.
-
setConnectResultHandler
protected final void setConnectResultHandler(TCPNIOConnection.ConnectResultHandler connectHandler)
-
onConnect
protected final void onConnect() throws IOException
Method will be called, when the connection gets connected.- Throws:
IOException
-
checkConnectFailed
protected final void checkConnectFailed(Throwable failure)
Method will be called in order to check if failure happened beforeConnection
was reported as connected.
-
terminate0
protected void terminate0(CompletionHandler<Closeable> completionHandler, CloseReason closeReason)
- Overrides:
terminate0
in classNIOConnection
-
onRead
protected final void onRead(Buffer data, int size)
Method will be called, when some data was read on the connection
-
enableInitialOpRead
protected void enableInitialOpRead() throws IOException
Description copied from class:NIOConnection
Enables OP_READ if it has never been enabled before.- Overrides:
enableInitialOpRead
in classNIOConnection
- Throws:
IOException
-
onWrite
protected final void onWrite(Buffer data, long size)
Method will be called, when some data was written on the connection
-
canWrite
public boolean canWrite()
- Returns:
true
if a write to thisOutputSink
will succeed, otherwise returnsfalse
.
-
canWrite
@Deprecated public boolean canWrite(int length)
Deprecated.- Parameters:
length
- specifies the number of bytes (or characters) that require writing- Returns:
true
if a write to thisOutputSink
will succeed, otherwise returnsfalse
.
-
notifyCanWrite
public void notifyCanWrite(WriteHandler writeHandler)
Instructs theOutputSink
to invoke the providedWriteHandler
when it is possible to write more bytes (or characters). Note that once theWriteHandler
has been notified, it will not be considered for notification again at a later point in time.- Parameters:
writeHandler
- theWriteHandler
that should be notified when it's possible to write more data.
-
notifyCanWrite
@Deprecated public void notifyCanWrite(WriteHandler handler, int length)
Deprecated.Instructs theOutputSink
to invoke the providedWriteHandler
when it is possible to writelength
bytes (or characters). Note that once theWriteHandler
has been notified, it will not be considered for notification again at a later point in time.- Parameters:
handler
- theWriteHandler
that should be notified when it's possible to writelength
bytes.length
- the number of bytes or characters that require writing.
-
-