Package org.glassfish.grizzly.nio
Class NIOConnection
- java.lang.Object
-
- org.glassfish.grizzly.nio.NIOConnection
-
- All Implemented Interfaces:
AttributeStorage,Closeable,Connection<SocketAddress>,MonitoringAware<ConnectionProbe>,OutputSink,Readable<SocketAddress>,Writeable<SocketAddress>
- Direct Known Subclasses:
TCPNIOConnection,UDPNIOConnection
public abstract class NIOConnection extends Object implements Connection<SocketAddress>
CommonConnectionimplementation for Java NIO Connections.- Author:
- Alexey Stashok
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Connection
Connection.CloseListener, Connection.CloseType
-
-
Field Summary
Fields Modifier and Type Field Description protected AttributeHolderattributesprotected SelectableChannelchannelprotected static AtomicReferenceFieldUpdater<NIOConnection,Object>connectCloseSemaphoreUpdaterSemaphore responsible for connect/close notificationprotected booleanisBlockingprotected booleanisStandaloneprotected intmaxAsyncWriteQueueSizeprotected DefaultMonitoringConfig<ConnectionProbe>monitoringConfigConnection probesprotected static ObjectNOTIFICATION_CLOSED_COMPLETEprotected static ObjectNOTIFICATION_INITIALIZEDprotected Processorprocessorprotected ProcessorSelectorprocessorSelectorprotected longreadTimeoutMillisprotected SelectionKeyselectionKeyprotected SelectorRunnerselectorRunnerprotected NIOTransporttransportprotected longwriteTimeoutMillisprotected shortzeroByteReadCount
-
Constructor Summary
Constructors Constructor Description NIOConnection(NIOTransport transport)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCloseListener(CloseListener closeListener)Add theConnection.CloseListener, which will be notified once Connection will be closed.voidaddCloseListener(Connection.CloseListener closeListener)Add theConnection.CloseListener, which will be notified once Connection will be closed.voidassertOpen()Checks if this Connection is open and ready to be used.voidattachToSelectorRunner(SelectorRunner selectorRunner)protected voidcheckEmptyRead(int size)GrizzlyFuture<Closeable>close()Gracefully close theConnectionvoidclose(CompletionHandler<Closeable> completionHandler)Deprecated.please useclose()with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler)callGrizzlyFuture<CloseReason>closeFuture()protected voidcloseGracefully0(CompletionHandler<Closeable> completionHandler, CloseReason closeReason)voidcloseSilently()Gracefully close theConnectionsilently, no notification required on completion or failure.voidcloseWithReason(IOException reason)Gracefully closes the Connection and provides the reason description.voidconfigureBlocking(boolean isBlocking)Sets theConnectionmode.voidconfigureStandalone(boolean isStandalone)voiddetachSelectorRunner()voiddisableIOEvent(IOEvent ioEvent)protected voiddoClose()Do the actual connection close.protected voidenableInitialOpRead()Enables OP_READ if it has never been enabled before.voidenableIOEvent(IOEvent ioEvent)voidexecuteInEventThread(IOEvent event, Runnable runnable)Executes theRunnablein the thread, responsible for running the given type of event on this Connection.TaskQueue<AsyncReadQueueRecord>getAsyncReadQueue()TaskQueue<AsyncWriteQueueRecord>getAsyncWriteQueue()AttributeHoldergetAttributes()Get associatedAttributeHolder.SelectableChannelgetChannel()CloseReasongetCloseReason()ReturnsCloseReasonif this Connection has been closed, or null otherwise.longgetId()Returns id of this instance, unique in the context of the JVM and the implementation class.intgetMaxAsyncWriteQueueSize()Get the max size (in bytes) of asynchronous write queue associated with connection.MemoryManager<?>getMemoryManager()MonitoringConfig<ConnectionProbe>getMonitoringConfig()Return the object associatedMonitoringConfig.ProcessorgetProcessor()Gets the defaultProcessor, which will processConnectionI/O events.ProcessorSelectorgetProcessorSelector()Gets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.longgetReadTimeout(TimeUnit timeUnit)Returns the current value for the blocking read timeout converted to the providedTimeUnitspecification.SelectionKeygetSelectionKey()SelectorRunnergetSelectorRunner()TransportgetTransport()Get theTransport, to which thisConnectionbelongs to.longgetWriteTimeout(TimeUnit timeUnit)Returns the current value for the blocking write timeout converted to the providedTimeUnitspecification.booleanisBlocking()booleanisClosed()booleanisOpen()IsConnectionopen and ready.booleanisStandalone()voidnotifyConnectionError(Throwable error)Method gets invoked, when error occur during the Connection lifecycle.protected static voidnotifyIOEventDisabled(NIOConnection connection, IOEvent ioEvent)Notify registeredConnectionProbes about the IO Event disabled event.protected static voidnotifyIOEventEnabled(NIOConnection connection, IOEvent ioEvent)Notify registeredConnectionProbes about the IO Event enabled event.protected static voidnotifyIOEventReady(NIOConnection connection, IOEvent ioEvent)Notify registeredConnectionProbes about the IO Event ready event.protected static voidnotifyProbesAccept(NIOConnection serverConnection, NIOConnection clientConnection)Notify registeredConnectionProbes about the accept event.protected static voidnotifyProbesBind(NIOConnection connection)Notify registeredConnectionProbes about the bind event.protected static voidnotifyProbesClose(NIOConnection connection)Notify registeredConnectionProbes about the close event.protected static voidnotifyProbesConnect(NIOConnection connection)Notify registeredConnectionProbes about the connect event.protected static voidnotifyProbesError(NIOConnection connection, Throwable error)Notify registeredConnectionProbes about the error.protected static voidnotifyProbesRead(NIOConnection connection, Buffer data, int size)Notify registeredConnectionProbes about the read event.protected static voidnotifyProbesWrite(NIOConnection connection, Buffer data, long size)Notify registeredConnectionProbes about the write event.ProcessorobtainProcessor(IOEvent ioEvent)Gets theProcessor, which will processConnectionI/O event.<E> EobtainProcessorState(Processor processor, NullaryFunction<E> factory)Returns theProcessorstate associated with this Connection.protected voidpreClose()<M> GrizzlyFuture<ReadResult<M,SocketAddress>>read()Method reads data.<M> voidread(CompletionHandler<ReadResult<M,SocketAddress>> completionHandler)booleanremoveCloseListener(CloseListener closeListener)Remove theConnection.CloseListener.booleanremoveCloseListener(Connection.CloseListener closeListener)Remove theConnection.CloseListener.protected voidsetChannel(SelectableChannel channel)voidsetMaxAsyncWriteQueueSize(int maxAsyncWriteQueueSize)Set the max size (in bytes) of asynchronous write queue associated with connection.voidsetProcessor(Processor preferableProcessor)Sets the defaultProcessor, which will processConnectionI/O events.voidsetProcessorSelector(ProcessorSelector preferableProcessorSelector)Sets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.voidsetReadTimeout(long timeout, TimeUnit timeUnit)Specifies the timeout for the blocking reads.protected voidsetSelectionKey(SelectionKey selectionKey)protected voidsetSelectorRunner(SelectorRunner selectorRunner)voidsetWriteTimeout(long timeout, TimeUnit timeUnit)Specifies the timeout for the blocking writes.voidsimulateIOEvent(IOEvent ioEvent)GrizzlyFuture<Closeable>terminate()Close theConnectionprotected voidterminate0(CompletionHandler<Closeable> completionHandler, CloseReason reason)voidterminateSilently()Close theConnectionsilently, no notification required on completion or failure.voidterminateWithReason(IOException reason)Closes the Connection and provides the reason description.<M> voidwrite(SocketAddress dstAddress, M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler)Method writes the buffer to the specific address.<M> voidwrite(SocketAddress dstAddress, M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler, PushBackHandler pushbackHandler)Deprecated.<M> GrizzlyFuture<WriteResult<M,SocketAddress>>write(M message)Method writes the buffer.<M> voidwrite(M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler)Method writes the buffer.<M> voidwrite(M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler, PushBackHandler pushbackHandler)Deprecated.-
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, getReadBufferSize, getWriteBufferSize, setReadBufferSize, setWriteBufferSize
-
Methods inherited from interface org.glassfish.grizzly.OutputSink
canWrite, canWrite, notifyCanWrite, notifyCanWrite
-
-
-
-
Field Detail
-
NOTIFICATION_INITIALIZED
protected static final Object NOTIFICATION_INITIALIZED
-
NOTIFICATION_CLOSED_COMPLETE
protected static final Object NOTIFICATION_CLOSED_COMPLETE
-
transport
protected final NIOTransport transport
-
maxAsyncWriteQueueSize
protected volatile int maxAsyncWriteQueueSize
-
readTimeoutMillis
protected volatile long readTimeoutMillis
-
writeTimeoutMillis
protected volatile long writeTimeoutMillis
-
channel
protected volatile SelectableChannel channel
-
selectionKey
protected volatile SelectionKey selectionKey
-
selectorRunner
protected volatile SelectorRunner selectorRunner
-
processor
protected volatile Processor processor
-
processorSelector
protected volatile ProcessorSelector processorSelector
-
attributes
protected final AttributeHolder attributes
-
connectCloseSemaphoreUpdater
protected static final AtomicReferenceFieldUpdater<NIOConnection,Object> connectCloseSemaphoreUpdater
Semaphore responsible for connect/close notification
-
isBlocking
protected volatile boolean isBlocking
-
isStandalone
protected volatile boolean isStandalone
-
zeroByteReadCount
protected short zeroByteReadCount
-
monitoringConfig
protected final DefaultMonitoringConfig<ConnectionProbe> monitoringConfig
Connection probes
-
-
Constructor Detail
-
NIOConnection
public NIOConnection(NIOTransport transport)
-
-
Method Detail
-
getId
public long getId()
Description copied from interface:ConnectionReturns id of this instance, unique in the context of the JVM and the implementation class.- Specified by:
getIdin interfaceConnection<SocketAddress>- Returns:
- id of this instance, never null.
-
configureBlocking
public void configureBlocking(boolean isBlocking)
Description copied from interface:ConnectionSets theConnectionmode.- Specified by:
configureBlockingin interfaceConnection<SocketAddress>- Parameters:
isBlocking- theConnectionmode. true, ifConnectionshould operate in blocking mode, or false otherwise.
-
isBlocking
public boolean isBlocking()
- Specified by:
isBlockingin interfaceConnection<SocketAddress>- Returns:
- the
Connectionmode. true, ifConnectionis operating in blocking mode, or false otherwise.
-
getMemoryManager
public MemoryManager<?> getMemoryManager()
- Specified by:
getMemoryManagerin interfaceConnection<SocketAddress>- Returns:
- an associated
MemoryManager. It's a shortcut forConnection.getTransport().getMemoryManager()
-
configureStandalone
public void configureStandalone(boolean isStandalone)
- Specified by:
configureStandalonein interfaceConnection<SocketAddress>
-
isStandalone
public boolean isStandalone()
- Specified by:
isStandalonein interfaceConnection<SocketAddress>
-
getTransport
public Transport getTransport()
Description copied from interface:ConnectionGet theTransport, to which thisConnectionbelongs to.- Specified by:
getTransportin interfaceConnection<SocketAddress>- Returns:
- the
Transport, to which thisConnectionbelongs to.
-
getMaxAsyncWriteQueueSize
public int getMaxAsyncWriteQueueSize()
Get the max size (in bytes) of asynchronous write queue associated with connection.- Specified by:
getMaxAsyncWriteQueueSizein interfaceConnection<SocketAddress>- Returns:
- the max size (in bytes) of asynchronous write queue associated with connection.
-
setMaxAsyncWriteQueueSize
public void setMaxAsyncWriteQueueSize(int maxAsyncWriteQueueSize)
Set the max size (in bytes) of asynchronous write queue associated with connection.- Specified by:
setMaxAsyncWriteQueueSizein interfaceConnection<SocketAddress>- Parameters:
maxAsyncWriteQueueSize- the max size (in bytes) of asynchronous write queue associated with connection.
-
getReadTimeout
public long getReadTimeout(TimeUnit timeUnit)
Description copied from interface:ConnectionReturns the current value for the blocking read timeout converted to the providedTimeUnitspecification. If this value hasn't been explicitly set, it will default to 30 seconds.- Specified by:
getReadTimeoutin interfaceConnection<SocketAddress>- Parameters:
timeUnit- theTimeUnitto convert the returned result to.- Returns:
- the read timeout value
-
setReadTimeout
public void setReadTimeout(long timeout, TimeUnit timeUnit)Description copied from interface:ConnectionSpecifies the timeout for the blocking reads. This may be overridden on a per-connection basis. A value of zero or less effectively disables the timeout.- Specified by:
setReadTimeoutin interfaceConnection<SocketAddress>- Parameters:
timeout- the new timeout valuetimeUnit- theTimeUnitspecification of the provided value.- See Also:
Connection.setReadTimeout(long, java.util.concurrent.TimeUnit)
-
getWriteTimeout
public long getWriteTimeout(TimeUnit timeUnit)
Description copied from interface:ConnectionReturns the current value for the blocking write timeout converted to the providedTimeUnitspecification. If this value hasn't been explicitly set, it will default to 30 seconds.- Specified by:
getWriteTimeoutin interfaceConnection<SocketAddress>- Parameters:
timeUnit- theTimeUnitto convert the returned result to.- Returns:
- the write timeout value
-
setWriteTimeout
public void setWriteTimeout(long timeout, TimeUnit timeUnit)Description copied from interface:ConnectionSpecifies the timeout for the blocking writes. This may be overridden on a per-connection basis. A value of zero or less effectively disables the timeout.- Specified by:
setWriteTimeoutin interfaceConnection<SocketAddress>- Parameters:
timeout- the new timeout valuetimeUnit- theTimeUnitspecification of the provided value.- See Also:
Connection.setWriteTimeout(long, java.util.concurrent.TimeUnit)
-
getSelectorRunner
public SelectorRunner getSelectorRunner()
-
setSelectorRunner
protected void setSelectorRunner(SelectorRunner selectorRunner)
-
attachToSelectorRunner
public void attachToSelectorRunner(SelectorRunner selectorRunner) throws IOException
- Throws:
IOException
-
detachSelectorRunner
public void detachSelectorRunner() throws IOException- Throws:
IOException
-
getChannel
public SelectableChannel getChannel()
-
setChannel
protected void setChannel(SelectableChannel channel)
-
getSelectionKey
public SelectionKey getSelectionKey()
-
setSelectionKey
protected void setSelectionKey(SelectionKey selectionKey)
-
obtainProcessor
public Processor obtainProcessor(IOEvent ioEvent)
Description copied from interface:ConnectionGets theProcessor, which will processConnectionI/O event. IfProcessoris null, - thenTransportwill try to getProcessorusingConnection'sProcessorSelector.select(IOEvent, Connection). IfProcessorSelector, associated withtheConnectionis also null - will askTransportfor aProcessor.- Specified by:
obtainProcessorin interfaceConnection<SocketAddress>- Parameters:
ioEvent- event to obtain the processor for- Returns:
- the default
Processor, which will processConnectionI/O events.
-
getProcessor
public Processor getProcessor()
Description copied from interface:ConnectionGets the defaultProcessor, which will processConnectionI/O events. IfProcessoris null, - thenTransportwill try to getProcessorusingConnection'sProcessorSelector.select(IOEvent, Connection). IfProcessorSelector, associated withtheConnectionis also null -Transportwill try to getProcessorusing own settings.- Specified by:
getProcessorin interfaceConnection<SocketAddress>- Returns:
- the default
Processor, which will processConnectionI/O events.
-
setProcessor
public void setProcessor(Processor preferableProcessor)
Description copied from interface:ConnectionSets the defaultProcessor, which will processConnectionI/O events. IfProcessoris null, - thenTransportwill try to getProcessorusingConnection'sProcessorSelector.select(IOEvent, Connection). IfProcessorSelector, associated withtheConnectionis also null -Transportwill try to getProcessorusing own settings.- Specified by:
setProcessorin interfaceConnection<SocketAddress>- Parameters:
preferableProcessor- the defaultProcessor, which will processConnectionI/O events.
-
getProcessorSelector
public ProcessorSelector getProcessorSelector()
Description copied from interface:ConnectionGets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.- Specified by:
getProcessorSelectorin interfaceConnection<SocketAddress>- Returns:
- the default
ProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.
-
setProcessorSelector
public void setProcessorSelector(ProcessorSelector preferableProcessorSelector)
Description copied from interface:ConnectionSets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.- Specified by:
setProcessorSelectorin interfaceConnection<SocketAddress>- Parameters:
preferableProcessorSelector- the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.
-
obtainProcessorState
public <E> E obtainProcessorState(Processor processor, NullaryFunction<E> factory)
Description copied from interface:ConnectionReturns theProcessorstate associated with this Connection.- Specified by:
obtainProcessorStatein interfaceConnection<SocketAddress>- Type Parameters:
E- state of theProcessor- Parameters:
processor-Processorfactory- factory that is used to initialise the state- Returns:
- the
Processorstate associated with this Connection.
-
executeInEventThread
public void executeInEventThread(IOEvent event, Runnable runnable)
Description copied from interface:ConnectionExecutes theRunnablein the thread, responsible for running the given type of event on this Connection. The thread will be chosen based onTransportsettings, especially current I/O strategy.- Specified by:
executeInEventThreadin interfaceConnection<SocketAddress>- Parameters:
event- event to get the thread pool fromrunnable- Runnable to run in the thread
-
getAsyncReadQueue
public TaskQueue<AsyncReadQueueRecord> getAsyncReadQueue()
-
getAsyncWriteQueue
public TaskQueue<AsyncWriteQueueRecord> getAsyncWriteQueue()
-
getAttributes
public AttributeHolder getAttributes()
Description copied from interface:AttributeStorageGet associatedAttributeHolder. Implementation may return null ifAttributeHolderwasn't initialized yet.- Specified by:
getAttributesin interfaceAttributeStorage- Returns:
- associated
AttributeHolder. Implementation may return null ifAttributeHolderwasn't initialized yet.
-
read
public <M> GrizzlyFuture<ReadResult<M,SocketAddress>> read()
Description copied from interface:ReadableMethod reads data.- Specified by:
readin interfaceReadable<SocketAddress>- Type Parameters:
M- type of data to read- Returns:
Future, using which it's possible to check the result
-
read
public <M> void read(CompletionHandler<ReadResult<M,SocketAddress>> completionHandler)
- Specified by:
readin interfaceReadable<SocketAddress>
-
write
public <M> GrizzlyFuture<WriteResult<M,SocketAddress>> write(M message)
Description copied from interface:WriteableMethod writes the buffer.- Specified by:
writein interfaceWriteable<SocketAddress>- Type Parameters:
M- type of data to be written- Parameters:
message- the buffer, from which the data will be written- Returns:
Future, using which it's possible to check the result
-
write
public <M> void write(M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler)Description copied from interface:WriteableMethod writes the buffer.- Specified by:
writein interfaceWriteable<SocketAddress>- Type Parameters:
M- type of data to be written- Parameters:
message- the buffer, from which the data will be writtencompletionHandler-CompletionHandler, which will get notified, when write will be completed
-
write
@Deprecated public <M> void write(M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler, PushBackHandler pushbackHandler)
Deprecated.Description copied from interface:WriteableMethod writes the buffer.- Specified by:
writein interfaceWriteable<SocketAddress>- Type Parameters:
M- type of data to be written- Parameters:
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
-
write
public <M> void write(SocketAddress dstAddress, M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler)
Description copied from interface:WriteableMethod writes the buffer to the specific address.- Specified by:
writein interfaceWriteable<SocketAddress>- Type Parameters:
M- type of data to be written- Parameters:
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 completed
-
write
@Deprecated public <M> void write(SocketAddress dstAddress, M message, CompletionHandler<WriteResult<M,SocketAddress>> completionHandler, PushBackHandler pushbackHandler)
Deprecated.Description copied from interface:WriteableMethod writes the buffer to the specific address.- Specified by:
writein interfaceWriteable<SocketAddress>- Type Parameters:
M- type of data to be written- Parameters:
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 refused
-
isOpen
public boolean isOpen()
Description copied from interface:ConnectionIsConnectionopen and ready. Returns true, if connection is open and ready, or false otherwise.- Specified by:
isOpenin interfaceCloseable- Specified by:
isOpenin interfaceConnection<SocketAddress>- Returns:
- true, if connection is open and ready, or false otherwise.
-
assertOpen
public void assertOpen() throws IOExceptionDescription copied from interface:ConnectionChecks if this Connection is open and ready to be used. If this Connection is closed - this method throwsIOExceptiongiving the reason why this Connection was closed.- Specified by:
assertOpenin interfaceCloseable- Specified by:
assertOpenin interfaceConnection<SocketAddress>- Throws:
IOException- giving the reason why this Closeable was closed.
-
isClosed
public boolean isClosed()
-
getCloseReason
public CloseReason getCloseReason()
Description copied from interface:ConnectionReturnsCloseReasonif this Connection has been closed, or null otherwise.- Specified by:
getCloseReasonin interfaceConnection<SocketAddress>- Returns:
CloseReasonif this Connection has been closed, or null otherwise
-
terminateSilently
public void terminateSilently()
Description copied from interface:ConnectionClose theConnectionsilently, no notification required on completion or failure.- Specified by:
terminateSilentlyin interfaceCloseable- Specified by:
terminateSilentlyin interfaceConnection<SocketAddress>
-
terminate
public GrizzlyFuture<Closeable> terminate()
Description copied from interface:ConnectionClose theConnection- Specified by:
terminatein interfaceCloseable- Specified by:
terminatein interfaceConnection<SocketAddress>- Returns:
Future, which could be checked in case, if close operation will be run asynchronously
-
terminateWithReason
public void terminateWithReason(IOException reason)
Description copied from interface:ConnectionCloses the Connection and provides the reason description. This method is similar toConnection.terminateSilently(), but additionally provides the reason why the Connection will be closed.- Specified by:
terminateWithReasonin interfaceCloseable- Specified by:
terminateWithReasonin interfaceConnection<SocketAddress>- Parameters:
reason- reason why terminated. This will be thrown isCloseable.isOpen()is called subsequently
-
close
public GrizzlyFuture<Closeable> close()
Description copied from interface:ConnectionGracefully close theConnection- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnection<SocketAddress>- Returns:
Future, which could be checked in case, if close operation will be run asynchronously- See Also:
which is not asynchronous
-
close
@Deprecated public void close(CompletionHandler<Closeable> completionHandler)
Deprecated.please useclose()with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler)callGracefully close theConnection- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnection<SocketAddress>- Parameters:
completionHandler-CompletionHandlerto be called, when the connection is closed.
-
closeSilently
public final void closeSilently()
Description copied from interface:ConnectionGracefully close theConnectionsilently, no notification required on completion or failure.- Specified by:
closeSilentlyin interfaceCloseable- Specified by:
closeSilentlyin interfaceConnection<SocketAddress>
-
closeWithReason
public void closeWithReason(IOException reason)
Description copied from interface:ConnectionGracefully closes the Connection and provides the reason description. This method is similar toConnection.closeSilently(), but additionally provides the reason why the Connection will be closed.- Specified by:
closeWithReasonin interfaceCloseable- Specified by:
closeWithReasonin interfaceConnection<SocketAddress>- Parameters:
reason- reason why closed, this will be thrown byCloseable.isOpen()if called subsequently
-
closeFuture
public GrizzlyFuture<CloseReason> closeFuture()
- Specified by:
closeFuturein interfaceCloseable- Returns:
- the
Future, that will be notified once this Closeable is closed
-
closeGracefully0
protected void closeGracefully0(CompletionHandler<Closeable> completionHandler, CloseReason closeReason)
-
terminate0
protected void terminate0(CompletionHandler<Closeable> completionHandler, CloseReason reason)
-
doClose
protected void doClose() throws IOExceptionDo the actual connection close.- Throws:
IOException
-
addCloseListener
public void addCloseListener(CloseListener closeListener)
Add theConnection.CloseListener, which will be notified once Connection will be closed.- Specified by:
addCloseListenerin interfaceCloseable- Specified by:
addCloseListenerin interfaceConnection<SocketAddress>- Parameters:
closeListener-Connection.CloseListener.
-
removeCloseListener
public boolean removeCloseListener(CloseListener closeListener)
Remove theConnection.CloseListener.- Specified by:
removeCloseListenerin interfaceCloseable- Specified by:
removeCloseListenerin interfaceConnection<SocketAddress>- Parameters:
closeListener-Connection.CloseListener.- Returns:
- true if the listener was successfully removed, or false otherwise.
-
addCloseListener
public void addCloseListener(Connection.CloseListener closeListener)
Description copied from interface:ConnectionAdd theConnection.CloseListener, which will be notified once Connection will be closed.- Specified by:
addCloseListenerin interfaceConnection<SocketAddress>- Parameters:
closeListener-Connection.CloseListener
-
removeCloseListener
public boolean removeCloseListener(Connection.CloseListener closeListener)
Description copied from interface:ConnectionRemove theConnection.CloseListener.- Specified by:
removeCloseListenerin interfaceConnection<SocketAddress>- Parameters:
closeListener-Connection.CloseListener.- Returns:
- true if listener successfully removed
-
notifyConnectionError
public void notifyConnectionError(Throwable error)
Method gets invoked, when error occur during the Connection lifecycle.- Specified by:
notifyConnectionErrorin interfaceConnection<SocketAddress>- Parameters:
error-Throwable.
-
getMonitoringConfig
public final MonitoringConfig<ConnectionProbe> getMonitoringConfig()
Return the object associatedMonitoringConfig.- Specified by:
getMonitoringConfigin interfaceConnection<SocketAddress>- Specified by:
getMonitoringConfigin interfaceMonitoringAware<ConnectionProbe>- Returns:
- the Connection monitoring configuration
MonitoringConfig.
-
notifyProbesBind
protected static void notifyProbesBind(NIOConnection connection)
Notify registeredConnectionProbes about the bind event.- Parameters:
connection- the Connection event occurred on.
-
notifyProbesAccept
protected static void notifyProbesAccept(NIOConnection serverConnection, NIOConnection clientConnection)
Notify registeredConnectionProbes about the accept event.- Parameters:
serverConnection- the server Connection, which accepted the client connection.clientConnection- the client Connection.
-
notifyProbesConnect
protected static void notifyProbesConnect(NIOConnection connection)
Notify registeredConnectionProbes about the connect event.- Parameters:
connection- the Connection event occurred on.
-
notifyProbesRead
protected static void notifyProbesRead(NIOConnection connection, Buffer data, int size)
Notify registeredConnectionProbes about the read event.
-
notifyProbesWrite
protected static void notifyProbesWrite(NIOConnection connection, Buffer data, long size)
Notify registeredConnectionProbes about the write event.
-
notifyIOEventReady
protected static void notifyIOEventReady(NIOConnection connection, IOEvent ioEvent)
Notify registeredConnectionProbes about the IO Event ready event.- Parameters:
connection- the Connection event occurred on.ioEvent- theIOEvent.
-
notifyIOEventEnabled
protected static void notifyIOEventEnabled(NIOConnection connection, IOEvent ioEvent)
Notify registeredConnectionProbes about the IO Event enabled event.- Parameters:
connection- the Connection event occurred on.ioEvent- theIOEvent.
-
notifyIOEventDisabled
protected static void notifyIOEventDisabled(NIOConnection connection, IOEvent ioEvent)
Notify registeredConnectionProbes about the IO Event disabled event.- Parameters:
connection- the Connection event occurred on.ioEvent- theIOEvent.
-
notifyProbesClose
protected static void notifyProbesClose(NIOConnection connection)
Notify registeredConnectionProbes about the close event.- Parameters:
connection- the Connection event occurred on.
-
notifyProbesError
protected static void notifyProbesError(NIOConnection connection, Throwable error)
Notify registeredConnectionProbes about the error.- Parameters:
connection- the Connection event occurred on.
-
preClose
protected void preClose()
-
enableInitialOpRead
protected void enableInitialOpRead() throws IOExceptionEnables OP_READ if it has never been enabled before.- Throws:
IOException
-
simulateIOEvent
public void simulateIOEvent(IOEvent ioEvent) throws IOException
- Specified by:
simulateIOEventin interfaceConnection<SocketAddress>- Throws:
IOException
-
enableIOEvent
public final void enableIOEvent(IOEvent ioEvent) throws IOException
- Specified by:
enableIOEventin interfaceConnection<SocketAddress>- Throws:
IOException
-
disableIOEvent
public final void disableIOEvent(IOEvent ioEvent) throws IOException
- Specified by:
disableIOEventin interfaceConnection<SocketAddress>- Throws:
IOException
-
checkEmptyRead
protected final void checkEmptyRead(int size)
-
-