- 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 interface
Deprecated.static enum
Deprecated.useCloseType
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCloseListener
(CloseListener closeListener) Add theConnection.CloseListener
, which will be notified once Connection will be closed.void
addCloseListener
(Connection.CloseListener closeListener) Deprecated.void
Checks if this Connection is open and ready to be used.close()
Gracefully close theConnection
void
close
(CompletionHandler<Closeable> completionHandler) Deprecated.useclose()
with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler)
.void
Gracefully close theConnection
silently, no notification required on completion or failure.void
closeWithReason
(IOException reason) Gracefully closes the Connection and provides the reason description.void
configureBlocking
(boolean isBlocking) Sets theConnection
mode.void
configureStandalone
(boolean isStandalone) Deprecated.void
disableIOEvent
(IOEvent ioEvent) void
enableIOEvent
(IOEvent ioEvent) void
executeInEventThread
(IOEvent event, Runnable runnable) Executes theRunnable
in the thread, responsible for running the given type of event on this Connection.ReturnsCloseReason
if this Connection has been closed, or null otherwise.long
getId()
Returns id of this instance, unique in the context of the JVM and the implementation class.Get the connection local addressint
Get 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 processConnection
I/O events.Gets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.int
Get the default size ofBuffer
s, which will be allocated for reading data fromConnection
.long
getReadTimeout
(TimeUnit timeUnit) Returns the current value for the blocking read timeout converted to the providedTimeUnit
specification.Get theTransport
, to which thisConnection
belongs to.int
Get the default size ofBuffer
s, which will be allocated for writing data toConnection
.long
getWriteTimeout
(TimeUnit timeUnit) Returns the current value for the blocking write timeout converted to the providedTimeUnit
specification.boolean
boolean
isOpen()
IsConnection
open and ready.boolean
Deprecated.void
notifyConnectionError
(Throwable error) Method gets invoked, when error occur during the Connection lifecycle.obtainProcessor
(IOEvent ioEvent) Gets theProcessor
, which will processConnection
I/O event.<E> E
obtainProcessorState
(Processor processor, Supplier<E> factory) Returns theProcessor
state associated with this Connection.boolean
removeCloseListener
(CloseListener closeListener) Remove theConnection.CloseListener
.boolean
removeCloseListener
(Connection.CloseListener closeListener) Deprecated.void
setMaxAsyncWriteQueueSize
(int maxAsyncWriteQueueSize) Set the max size (in bytes) of asynchronous write queue associated with connection.void
setProcessor
(Processor preferableProcessor) Sets the defaultProcessor
, which will processConnection
I/O events.void
setProcessorSelector
(ProcessorSelector preferableProcessorSelector) Sets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.void
setReadBufferSize
(int readBufferSize) Set the default size ofBuffer
s, which will be allocated for reading data fromConnection
.void
setReadTimeout
(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking reads.void
setWriteBufferSize
(int writeBufferSize) Set the default size ofBuffer
s, which will be allocated for writing data toConnection
.void
setWriteTimeout
(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking writes.void
simulateIOEvent
(IOEvent ioEvent) Close theConnection
void
Close theConnection
silently, no notification required on completion or failure.void
terminateWithReason
(IOException reason) Closes the Connection and provides the reason description.Methods inherited from interface org.glassfish.grizzly.attributes.AttributeStorage
getAttributes
Methods inherited from interface org.glassfish.grizzly.Closeable
closeFuture
Methods 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 thisConnection
belongs to.- Returns:
- the
Transport
, to which thisConnection
belongs to.
-
isOpen
boolean isOpen()IsConnection
open 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 throwsIOException
giving the reason why this Connection was closed.- Specified by:
assertOpen
in interfaceCloseable
- Throws:
IOException
- giving the reason why this Closeable was closed.
-
getCloseReason
CloseReason getCloseReason()ReturnsCloseReason
if this Connection has been closed, or null otherwise.- Returns:
CloseReason
if this Connection has been closed, or null otherwise
-
configureBlocking
void configureBlocking(boolean isBlocking) Sets theConnection
mode.- Parameters:
isBlocking
- theConnection
mode. true, ifConnection
should operate in blocking mode, or false otherwise.
-
isBlocking
boolean isBlocking()- Returns:
- the
Connection
mode. true, ifConnection
is operating in blocking mode, or false otherwise.
-
configureStandalone
Deprecated. -
isStandalone
Deprecated. -
obtainProcessor
Gets theProcessor
, which will processConnection
I/O event. IfProcessor
is null, - thenTransport
will try to getProcessor
usingConnection
'sProcessorSelector.select(IOEvent, Connection)
. IfProcessorSelector
, associated withtheConnection
is also null - will askTransport
for aProcessor
.- Parameters:
ioEvent
- event to obtain the processor for- Returns:
- the default
Processor
, which will processConnection
I/O events.
-
getProcessor
Processor getProcessor()Gets the defaultProcessor
, which will processConnection
I/O events. IfProcessor
is null, - thenTransport
will try to getProcessor
usingConnection
'sProcessorSelector.select(IOEvent, Connection)
. IfProcessorSelector
, associated withtheConnection
is also null -Transport
will try to getProcessor
using own settings.- Returns:
- the default
Processor
, which will processConnection
I/O events.
-
setProcessor
Sets the defaultProcessor
, which will processConnection
I/O events. IfProcessor
is null, - thenTransport
will try to getProcessor
usingConnection
'sProcessorSelector.select(IOEvent, Connection)
. IfProcessorSelector
, associated withtheConnection
is also null -Transport
will try to getProcessor
using own settings.- Parameters:
preferableProcessor
- the defaultProcessor
, which will processConnection
I/O events.
-
getProcessorSelector
ProcessorSelector getProcessorSelector()Gets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.- Returns:
- the default
ProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.
-
setProcessorSelector
Sets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.- Parameters:
preferableProcessorSelector
- the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.
-
obtainProcessorState
Returns theProcessor
state associated with this Connection. -
executeInEventThread
Executes theRunnable
in the thread, responsible for running the given type of event on this Connection. The thread will be chosen based onTransport
settings, 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 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
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
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
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
.
-
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 providedTimeUnit
specification. If this value hasn't been explicitly set, it will default to 30 seconds.- Parameters:
timeUnit
- theTimeUnit
to 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
- theTimeUnit
specification of the provided value.- Since:
- 2.3
- See Also:
-
getWriteTimeout
Returns the current value for the blocking write timeout converted to the providedTimeUnit
specification. If this value hasn't been explicitly set, it will default to 30 seconds.- Parameters:
timeUnit
- theTimeUnit
to 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
- theTimeUnit
specification 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:MonitoringAware
Return the object associatedMonitoringConfig
.- Specified by:
getMonitoringConfig
in interfaceMonitoringAware<L>
- Returns:
- the Connection monitoring configuration
MonitoringConfig
.
-
terminateSilently
void terminateSilently()Close theConnection
silently, no notification required on completion or failure.- Specified by:
terminateSilently
in 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:
terminateWithReason
in 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:
close
in interfaceCloseable
- Parameters:
completionHandler
-CompletionHandler
to be called, when the connection is closed.
-
closeSilently
void closeSilently()Gracefully close theConnection
silently, no notification required on completion or failure.- Specified by:
closeSilently
in 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:
closeWithReason
in 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:
addCloseListener
in interfaceCloseable
- Parameters:
closeListener
-Connection.CloseListener
.- Since:
- 2.3
-
removeCloseListener
Remove theConnection.CloseListener
.- Specified by:
removeCloseListener
in 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