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
Connection implementation for the TCPNIOTransport- Author:
- Alexey Stashok
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceThis 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 -
Method Summary
Modifier and TypeMethodDescriptionbooleancanWrite()booleancanWrite(int length) Deprecated.protected final voidcheckConnectFailed(Throwable failure) Method will be called in order to check if failure happened beforeConnectionwas reported as connected.protected voidEnables OP_READ if it has never been enabled before.Returns the local address of this Connection, or null if it is unconnected.Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.intGet the default size ofBuffers, which will be allocated for reading data fromConnection.intGet the default size ofBuffers, which will be allocated for writing data toConnection.voidnotifyCanWrite(WriteHandler writeHandler) Instructs theOutputSinkto invoke the providedWriteHandlerwhen it is possible to write more bytes (or characters).voidnotifyCanWrite(WriteHandler handler, int length) Deprecated.protected booleanprotected final voidMethod will be called, when the connection gets connected.protected final voidMethod will be called, when some data was read on the connectionprotected final voidMethod will be called, when some data was written on the connectionprotected voidpreClose()protected voidprotected final voidsetConnectResultHandler(TCPNIOConnection.ConnectResultHandler connectHandler) voidsetReadBufferSize(int readBufferSize) Set the default size ofBuffers, which will be allocated for reading data fromConnection.protected voidsetSelectionKey(SelectionKey selectionKey) protected voidsetSelectorRunner(SelectorRunner selectorRunner) voidsetWriteBufferSize(int writeBufferSize) Set the default size ofBuffers, which will be allocated for writing data toConnection.protected voidterminate0(CompletionHandler<Closeable> completionHandler, CloseReason closeReason) 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 Details
-
TCPNIOConnection
-
-
Method Details
-
setSelectionKey
- Overrides:
setSelectionKeyin classNIOConnection
-
setSelectorRunner
- Overrides:
setSelectorRunnerin classNIOConnection
-
preClose
protected void preClose()- Overrides:
preClosein classNIOConnection
-
notifyReady
protected boolean notifyReady() -
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
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 ofBuffers, which will be allocated for reading data fromConnection. The value less or equal to zero will be ignored.- Returns:
- the default size of
Buffers, which will be allocated for reading data fromConnection.
-
setReadBufferSize
public void setReadBufferSize(int readBufferSize) Set the default size ofBuffers, which will be allocated for reading data fromConnection. The value less or equal to zero will be ignored.- Parameters:
readBufferSize- the default size ofBuffers, which will be allocated for reading data fromConnection.
-
getWriteBufferSize
public int getWriteBufferSize()Get the default size ofBuffers, which will be allocated for writing data toConnection.- Returns:
- the default size of
Buffers, which will be allocated for writing data toConnection.
-
setWriteBufferSize
public void setWriteBufferSize(int writeBufferSize) Set the default size ofBuffers, which will be allocated for writing data toConnection.- Parameters:
writeBufferSize- the default size ofBuffers, which will be allocated for writing data toConnection.
-
setConnectResultHandler
-
onConnect
Method will be called, when the connection gets connected.- Throws:
IOException
-
checkConnectFailed
Method will be called in order to check if failure happened beforeConnectionwas reported as connected. -
terminate0
- Overrides:
terminate0in classNIOConnection
-
onRead
Method will be called, when some data was read on the connection -
enableInitialOpRead
Description copied from class:NIOConnectionEnables OP_READ if it has never been enabled before.- Overrides:
enableInitialOpReadin classNIOConnection- Throws:
IOException
-
onWrite
Method will be called, when some data was written on the connection -
canWrite
public boolean canWrite()- Returns:
trueif a write to thisOutputSinkwill succeed, otherwise returnsfalse.
-
canWrite
Deprecated.- Parameters:
length- specifies the number of bytes (or characters) that require writing- Returns:
trueif a write to thisOutputSinkwill succeed, otherwise returnsfalse.
-
notifyCanWrite
Instructs theOutputSinkto invoke the providedWriteHandlerwhen it is possible to write more bytes (or characters). Note that once theWriteHandlerhas been notified, it will not be considered for notification again at a later point in time.- Parameters:
writeHandler- theWriteHandlerthat should be notified when it's possible to write more data.
-
notifyCanWrite
Deprecated.Instructs theOutputSinkto invoke the providedWriteHandlerwhen it is possible to writelengthbytes (or characters). Note that once theWriteHandlerhas been notified, it will not be considered for notification again at a later point in time.- Parameters:
handler- theWriteHandlerthat should be notified when it's possible to writelengthbytes.length- the number of bytes or characters that require writing.
-
toString
-