- Type Parameters:
L- the Connection address type
- All Superinterfaces:
AttributeStorage,Closeable,MonitoringAware<ConnectionProbe>,OutputSink,Readable<L>,Writeable<L>
- All Known Implementing Classes:
NIOConnection,TCPNIOConnection,TCPNIOServerConnection,UDPNIOConnection,UDPNIOServerConnection
public interface Connection<L>
extends Readable<L>, Writeable<L>, Closeable, AttributeStorage, MonitoringAware<ConnectionProbe>
Common interface, which represents any kind of connection.
- Author:
- Alexey Stashok
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceDeprecated.static enumDeprecated.useCloseType -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCloseListener(CloseListener closeListener) Add theConnection.CloseListener, which will be notified once Connection will be closed.voidaddCloseListener(Connection.CloseListener closeListener) Deprecated.voidChecks if this Connection is open and ready to be used.close()Gracefully close theConnectionvoidclose(CompletionHandler<Closeable> completionHandler) Deprecated.useclose()with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler).voidGracefully 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) Deprecated.voiddisableIOEvent(IOEvent ioEvent) voidenableIOEvent(IOEvent ioEvent) voidexecuteInEventThread(IOEvent event, Runnable runnable) Executes theRunnablein the thread, responsible for running the given type of event on this Connection.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.Get the connection local addressintGet the max size (in bytes) of asynchronous write queue associated with connection.Return the object associatedMonitoringConfig.Get the connection peer addressGets the defaultProcessor, which will processConnectionI/O events.Gets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.intGet the default size ofBuffers, which will be allocated for reading data fromConnection.longgetReadTimeout(TimeUnit timeUnit) Returns the current value for the blocking read timeout converted to the providedTimeUnitspecification.Get theTransport, to which thisConnectionbelongs to.intGet the default size ofBuffers, which will be allocated for writing data toConnection.longgetWriteTimeout(TimeUnit timeUnit) Returns the current value for the blocking write timeout converted to the providedTimeUnitspecification.booleanbooleanisOpen()IsConnectionopen and ready.booleanDeprecated.voidnotifyConnectionError(Throwable error) Method gets invoked, when error occur during the Connection lifecycle.obtainProcessor(IOEvent ioEvent) Gets theProcessor, which will processConnectionI/O event.<E> EobtainProcessorState(Processor processor, Supplier<E> factory) Returns theProcessorstate associated with this Connection.booleanremoveCloseListener(CloseListener closeListener) Remove theConnection.CloseListener.booleanremoveCloseListener(Connection.CloseListener closeListener) Deprecated.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.voidsetReadBufferSize(int readBufferSize) Set the default size ofBuffers, which will be allocated for reading data fromConnection.voidsetReadTimeout(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking reads.voidsetWriteBufferSize(int writeBufferSize) Set the default size ofBuffers, which will be allocated for writing data toConnection.voidsetWriteTimeout(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking writes.voidsimulateIOEvent(IOEvent ioEvent) Close theConnectionvoidClose theConnectionsilently, no notification required on completion or failure.voidterminateWithReason(IOException reason) Closes the Connection and provides the reason description.Methods inherited from interface org.glassfish.grizzly.attributes.AttributeStorage
getAttributesMethods inherited from interface org.glassfish.grizzly.Closeable
closeFutureMethods inherited from interface org.glassfish.grizzly.OutputSink
canWrite, canWrite, notifyCanWrite, notifyCanWrite
-
Method Details
-
getId
long getId()Returns id of this instance, unique in the context of the JVM and the implementation class.- Returns:
- id of this instance, never null.
-
getTransport
Transport getTransport()Get theTransport, to which thisConnectionbelongs to.- Returns:
- the
Transport, to which thisConnectionbelongs to.
-
isOpen
boolean isOpen()IsConnectionopen and ready. Returns true, if connection is open and ready, or false otherwise. -
assertOpen
Checks 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- Throws:
IOException- giving the reason why this Closeable was closed.
-
getCloseReason
CloseReason getCloseReason()ReturnsCloseReasonif this Connection has been closed, or null otherwise.- Returns:
CloseReasonif this Connection has been closed, or null otherwise
-
configureBlocking
void configureBlocking(boolean isBlocking) Sets theConnectionmode.- Parameters:
isBlocking- theConnectionmode. true, ifConnectionshould operate in blocking mode, or false otherwise.
-
isBlocking
boolean isBlocking()- Returns:
- the
Connectionmode. true, ifConnectionis operating in blocking mode, or false otherwise.
-
configureStandalone
Deprecated. -
isStandalone
Deprecated. -
obtainProcessor
Gets theProcessor, which will processConnectionI/O event. IfProcessoris null, - thenTransportwill try to getProcessorusingConnection'sProcessorSelector.select(IOEvent, Connection). IfProcessorSelector, associated withtheConnectionis also null - will askTransportfor aProcessor.- Parameters:
ioEvent- event to obtain the processor for- Returns:
- the default
Processor, which will processConnectionI/O events.
-
getProcessor
Processor getProcessor()Gets 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.- Returns:
- the default
Processor, which will processConnectionI/O events.
-
setProcessor
Sets 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.- Parameters:
preferableProcessor- the defaultProcessor, which will processConnectionI/O events.
-
getProcessorSelector
ProcessorSelector getProcessorSelector()Gets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.- Returns:
- the default
ProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.
-
setProcessorSelector
Sets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.- Parameters:
preferableProcessorSelector- the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisConnection'sProcessoris null.
-
obtainProcessorState
Returns theProcessorstate associated with this Connection. -
executeInEventThread
Executes 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.- Parameters:
event- event to get the thread pool fromrunnable- Runnable to run in the thread
-
getMemoryManager
MemoryManager<?> getMemoryManager()- Returns:
- an associated
MemoryManager. It's a shortcut forgetTransport().getMemoryManager() - Since:
- 2.3.18
-
getPeerAddress
L getPeerAddress()Get the connection peer address- Returns:
- the connection peer address
-
getLocalAddress
L getLocalAddress()Get the connection local address- Returns:
- the connection local address
-
getReadBufferSize
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
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
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
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.
-
getMaxAsyncWriteQueueSize
int getMaxAsyncWriteQueueSize()Get the max size (in bytes) of asynchronous write queue associated with connection.- Returns:
- the max size (in bytes) of asynchronous write queue associated with connection.
- Since:
- 2.2
-
setMaxAsyncWriteQueueSize
void setMaxAsyncWriteQueueSize(int maxAsyncWriteQueueSize) Set the max size (in bytes) of asynchronous write queue associated with connection.- Parameters:
maxAsyncWriteQueueSize- the max size (in bytes) of asynchronous write queue associated with connection.- Since:
- 2.2
-
getReadTimeout
Returns 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.- Parameters:
timeUnit- theTimeUnitto convert the returned result to.- Returns:
- the read timeout value
- Since:
- 2.3
-
setReadTimeout
Specifies 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.- Parameters:
timeout- the new timeout valuetimeUnit- theTimeUnitspecification of the provided value.- Since:
- 2.3
- See Also:
-
getWriteTimeout
Returns 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.- Parameters:
timeUnit- theTimeUnitto convert the returned result to.- Returns:
- the write timeout value
- Since:
- 2.3
-
setWriteTimeout
Specifies 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.- Parameters:
timeout- the new timeout valuetimeUnit- theTimeUnitspecification of the provided value.- Since:
- 2.3
- See Also:
-
simulateIOEvent
- Throws:
IOException
-
enableIOEvent
- Throws:
IOException
-
disableIOEvent
- Throws:
IOException
-
getMonitoringConfig
MonitoringConfig<ConnectionProbe> getMonitoringConfig()Description copied from interface:MonitoringAwareReturn the object associatedMonitoringConfig.- Specified by:
getMonitoringConfigin interfaceMonitoringAware<L>- Returns:
- the Connection monitoring configuration
MonitoringConfig.
-
terminateSilently
void terminateSilently()Close theConnectionsilently, no notification required on completion or failure.- Specified by:
terminateSilentlyin interfaceCloseable
-
terminate
GrizzlyFuture<Closeable> terminate()Close theConnection -
terminateWithReason
Closes the Connection and provides the reason description. This method is similar toterminateSilently(), but additionally provides the reason why the Connection will be closed.- Specified by:
terminateWithReasonin interfaceCloseable- Parameters:
reason- reason why terminated. This will be thrown isCloseable.isOpen()is called subsequently
-
close
GrizzlyFuture<Closeable> close()Gracefully close theConnection -
close
Deprecated.useclose()with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler).Gracefully close theConnection- Specified by:
closein interfaceCloseable- Parameters:
completionHandler-CompletionHandlerto be called, when the connection is closed.
-
closeSilently
void closeSilently()Gracefully close theConnectionsilently, no notification required on completion or failure.- Specified by:
closeSilentlyin interfaceCloseable
-
closeWithReason
Gracefully closes the Connection and provides the reason description. This method is similar tocloseSilently(), but additionally provides the reason why the Connection will be closed.- Specified by:
closeWithReasonin interfaceCloseable- Parameters:
reason- reason why closed, this will be thrown byCloseable.isOpen()if called subsequently
-
addCloseListener
Add theConnection.CloseListener, which will be notified once Connection will be closed.- Specified by:
addCloseListenerin interfaceCloseable- Parameters:
closeListener-Connection.CloseListener.- Since:
- 2.3
-
removeCloseListener
Remove theConnection.CloseListener.- Specified by:
removeCloseListenerin interfaceCloseable- Parameters:
closeListener-Connection.CloseListener.- Returns:
- true if the listener was successfully removed, or false otherwise.
- Since:
- 2.3
-
addCloseListener
Deprecated.Add theConnection.CloseListener, which will be notified once Connection will be closed.- Parameters:
closeListener-Connection.CloseListener
-
removeCloseListener
Deprecated.Remove theConnection.CloseListener.- Parameters:
closeListener-Connection.CloseListener.- Returns:
- true if listener successfully removed
-
notifyConnectionError
Method gets invoked, when error occur during the Connection lifecycle.- Parameters:
error-Throwable.
-
CloseListener