Package org.glassfish.grizzly
Interface Connection<L>
-
- 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 Classes Modifier and Type Interface Description static interface
Connection.CloseListener
Deprecated.useCloseListener
static class
Connection.CloseType
Deprecated.useCloseType
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addCloseListener(CloseListener closeListener)
Add theConnection.CloseListener
, which will be notified once Connection will be closed.void
addCloseListener(Connection.CloseListener closeListener)
Deprecated.void
assertOpen()
Checks if this Connection is open and ready to be used.GrizzlyFuture<Closeable>
close()
Gracefully close theConnection
void
close(CompletionHandler<Closeable> completionHandler)
Deprecated.useclose()
with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler)
.void
closeSilently()
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.CloseReason
getCloseReason()
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.L
getLocalAddress()
Get the connection local addressint
getMaxAsyncWriteQueueSize()
Get the max size (in bytes) of asynchronous write queue associated with connection.MemoryManager<?>
getMemoryManager()
MonitoringConfig<ConnectionProbe>
getMonitoringConfig()
Return the object associatedMonitoringConfig
.L
getPeerAddress()
Get the connection peer addressProcessor
getProcessor()
Gets the defaultProcessor
, which will processConnection
I/O events.ProcessorSelector
getProcessorSelector()
Gets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.int
getReadBufferSize()
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.Transport
getTransport()
Get theTransport
, to which thisConnection
belongs to.int
getWriteBufferSize()
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
isBlocking()
boolean
isOpen()
IsConnection
open and ready.boolean
isStandalone()
Deprecated.void
notifyConnectionError(Throwable error)
Method gets invoked, when error occur during the Connection lifecycle.Processor
obtainProcessor(IOEvent ioEvent)
Gets theProcessor
, which will processConnection
I/O event.<E> E
obtainProcessorState(Processor processor, NullaryFunction<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)
GrizzlyFuture<Closeable>
terminate()
Close theConnection
void
terminateSilently()
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 Detail
-
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
void assertOpen() throws IOException
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 void configureStandalone(boolean isStandalone)
Deprecated.
-
isStandalone
@Deprecated boolean isStandalone()
Deprecated.
-
obtainProcessor
Processor obtainProcessor(IOEvent ioEvent)
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
void setProcessor(Processor preferableProcessor)
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
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.- Parameters:
preferableProcessorSelector
- the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisConnection
'sProcessor
is null.
-
obtainProcessorState
<E> E obtainProcessorState(Processor processor, NullaryFunction<E> factory)
Returns theProcessor
state associated with this Connection.
-
executeInEventThread
void executeInEventThread(IOEvent event, Runnable runnable)
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
long getReadTimeout(TimeUnit timeUnit)
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
void setReadTimeout(long timeout, TimeUnit timeUnit)
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:
setReadTimeout(long, java.util.concurrent.TimeUnit)
-
getWriteTimeout
long getWriteTimeout(TimeUnit timeUnit)
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
void setWriteTimeout(long timeout, TimeUnit timeUnit)
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:
setWriteTimeout(long, java.util.concurrent.TimeUnit)
-
simulateIOEvent
void simulateIOEvent(IOEvent ioEvent) throws IOException
- Throws:
IOException
-
enableIOEvent
void enableIOEvent(IOEvent ioEvent) throws IOException
- Throws:
IOException
-
disableIOEvent
void disableIOEvent(IOEvent ioEvent) throws IOException
- 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
void terminateWithReason(IOException reason)
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
- Specified by:
close
in interfaceCloseable
- Returns:
Future
, which could be checked in case, if close operation will be run asynchronously- See Also:
which is not asynchronous
-
close
@Deprecated void close(CompletionHandler<Closeable> completionHandler)
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
void closeWithReason(IOException reason)
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
void addCloseListener(CloseListener closeListener)
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
boolean removeCloseListener(CloseListener closeListener)
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 void addCloseListener(Connection.CloseListener closeListener)
Deprecated.Add theConnection.CloseListener
, which will be notified once Connection will be closed.- Parameters:
closeListener
-Connection.CloseListener
-
removeCloseListener
@Deprecated boolean removeCloseListener(Connection.CloseListener closeListener)
Deprecated.Remove theConnection.CloseListener
.- Parameters:
closeListener
-Connection.CloseListener
.- Returns:
- true if listener successfully removed
-
-