- All Superinterfaces:
MonitoringAware<TransportProbe>
- All Known Implementing Classes:
AbstractTransport
,NIOTransport
,TCPNIOTransport
,UDPNIOTransport
Transport interface describes the transport unit used in Grizzly.
Transport implementation could operate over TCP, UDP or other custom protocol, using blocking, NIO or NIO.2 Java API.
- Author:
- Alexey Stashok
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default read buffer size.static final int
Default read timeout in seconds.static final int
The default write buffer size.static final int
Default write timeout in seconds. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addShutdownListener
(GracefulShutdownListener shutdownListener) Adds aGracefulShutdownListener
which will be called whenshutdown()
is called to enable graceful shutdown of transports.void
configureBlocking
(boolean isBlocking) Sets theTransport
mode.void
configureStandalone
(boolean isStandalone) void
fireIOEvent
(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener) Fires specificIOEvent
on theConnection
GetTransport
associatedAttributeBuilder
, which will be used byTransport
and itsConnection
s to store customAttribute
s.Get the monitoring configuration for TransportConnection
s.Get theTransport
associatedMemoryManager
, which will be used by theTransport
, itsConnection
s and by during processing I/O events, occurred onConnection
s.Get the Transport monitoring configurationMonitoringConfig
.getName()
Gets theTransport
name.Gets the defaultProcessor
, which will processConnection
I/O events in case, ifConnection
doesn't have ownProcessor
preferences.Gets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisTransport
'sProcessor
is null andConnection
doesn't have neither preferredProcessor
norProcessorSelector
.int
Get the default size ofBuffer
s, which will be allocated for reading data fromTransport
'sConnection
s.getReader
(boolean isBlocking) Get theReader
implementation, depending on the requested mode.getReader
(Connection connection) Get theReader
to read data from theConnection
.long
getReadTimeout
(TimeUnit timeUnit) Returns the current value for the blocking read timeout converted to the providedTimeUnit
specification.getState()
Return theTransport
state controller.Get the monitoring configuration for Transport thread pool.Get a thread pool, which will run IOEvent processing (depending on TransportIOStrategy
) to let kernel threads continue their job.int
Get the default size ofBuffer
s, which will be allocated for writing data toTransport
'sConnection
s.getWriter
(boolean isBlocking) Get theWriter
implementation, depending on the requested mode.getWriter
(Connection connection) Get theWriter
to write data to theConnection
.long
getWriteTimeout
(TimeUnit timeUnit) Returns the current value for the blocking write timeout converted to the providedTimeUnit
specification.boolean
Returns theTransport
mode.boolean
isPaused()
boolean
boolean
Returns true, if this Transport is in stopped state, false otherwise.void
notifyTransportError
(Throwable error) Method gets invoked, when error occur during the Transport lifecycle.obtainProcessor
(IOEvent ioEvent, Connection connection) Gets the defaultProcessor
, which will process TransportConnection
s I/O events in case, ifConnection
doesn't have ownProcessor
preferences.void
pause()
Pauses the transportvoid
resume()
Resumes the transport after a pausevoid
setAttributeBuilder
(AttributeBuilder attributeBuilder) SetTransport
associatedAttributeBuilder
, which will be used byTransport
and itsConnection
s to store customAttribute
s.void
setIOStrategy
(IOStrategy IOStrategy) void
setKernelThreadPool
(ExecutorService threadPool) Set a thread pool which will run Transport internal tasks.void
setKernelThreadPoolConfig
(ThreadPoolConfig kernelConfig) Set theThreadPoolConfig
to be used by the Transport internal thread pool.void
setMemoryManager
(MemoryManager memoryManager) Set theTransport
associatedMemoryManager
, which will be used by theTransport
, itsConnection
s and by during processing I/O events, occurred onConnection
s.void
Sets theTransport
name.void
setProcessor
(Processor processor) Sets the defaultProcessor
, which will processConnection
I/O events in case, ifConnection
doesn't have ownProcessor
preferences.void
setProcessorSelector
(ProcessorSelector selector) Sets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisTransport
'sProcessor
is null andConnection
doesn't have neither preferredProcessor
norProcessorSelector
.void
setReadBufferSize
(int readBufferSize) Set the default size ofBuffer
s, which will be allocated for reading data fromTransport
'sConnection
s.void
setReadTimeout
(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking reads.void
setWorkerThreadPool
(ExecutorService threadPool) Set a thread pool, which will run IOEvent processing (depending on TransportIOStrategy
) to let kernel threads continue their job.void
setWorkerThreadPoolConfig
(ThreadPoolConfig workerConfig) Set theThreadPoolConfig
to be used by the worker thread pool.void
setWriteBufferSize
(int writeBufferSize) Set the default size ofBuffer
s, which will be allocated for writing data toTransport
'sConnection
s.void
setWriteTimeout
(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking writes.shutdown()
Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.void
Forcibly stops the transport and closes all connections.void
start()
Starts the transportvoid
stop()
Deprecated.
-
Field Details
-
DEFAULT_READ_BUFFER_SIZE
static final int DEFAULT_READ_BUFFER_SIZEThe default read buffer size.- See Also:
-
DEFAULT_WRITE_BUFFER_SIZE
static final int DEFAULT_WRITE_BUFFER_SIZEThe default write buffer size.- See Also:
-
DEFAULT_READ_TIMEOUT
static final int DEFAULT_READ_TIMEOUTDefault read timeout in seconds.- See Also:
-
DEFAULT_WRITE_TIMEOUT
static final int DEFAULT_WRITE_TIMEOUTDefault write timeout in seconds.- See Also:
-
-
Method Details
-
getName
String getName()Gets theTransport
name.- Returns:
- the
Transport
name.
-
setName
Sets theTransport
name.- Parameters:
name
- theTransport
name.
-
getState
StateHolder<Transport.State> getState()Return theTransport
state controller. Using the state controller, it is possible to get/set theTransport
state in thread-safe manner.- Returns:
StateHolder
state controller.
-
isBlocking
boolean isBlocking()Returns theTransport
mode. true, ifTransport
is operating in blocking mode, or false otherwise. SpecificTransport
Connection
s may override this setting byConnection.isBlocking()
. -
configureBlocking
void configureBlocking(boolean isBlocking) Sets theTransport
mode. SpecificTransport
Connection
s may override this setting byConnection.configureBlocking(boolean)
. -
configureStandalone
void configureStandalone(boolean isStandalone) -
isStandalone
boolean isStandalone() -
obtainProcessor
Gets the defaultProcessor
, which will process TransportConnection
s I/O events in case, ifConnection
doesn't have ownProcessor
preferences. IfTransport
associatedProcessor
is null, andConnection
doesn't have any preferredProcessor
- thenTransport
will try to getProcessor
usingProcessorSelector.select(IOEvent, Connection)
.- Parameters:
ioEvent
- the type of events the Processor should handleconnection
- connection to obtain Processor for- Returns:
- the default
Processor
, which will processConnection
I/O events, if one doesn't have ownProcessor
preferences.
-
getProcessor
Processor getProcessor()Gets the defaultProcessor
, which will processConnection
I/O events in case, ifConnection
doesn't have ownProcessor
preferences. IfTransport
associatedProcessor
is null, andConnection
doesn't have any preferredProcessor
- thenTransport
will try to getProcessor
usingProcessorSelector.select(IOEvent, Connection)
.- Returns:
- the default
Processor
, which will processConnection
I/O events, if one doesn't have ownProcessor
preferences.
-
setProcessor
Sets the defaultProcessor
, which will processConnection
I/O events in case, ifConnection
doesn't have ownProcessor
preferences.- Parameters:
processor
- the defaultProcessor
, which will processConnection
I/O events, if one doesn't have ownProcessor
preferences.
-
getProcessorSelector
ProcessorSelector getProcessorSelector()Gets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisTransport
'sProcessor
is null andConnection
doesn't have neither preferredProcessor
norProcessorSelector
.Transport
'sProcessorSelector
is the last place, whereTransport
will try to getProcessor
to processConnection
I/O event. IfProcessorSelector
is not set -IllegalStateException
will be thrown.- Returns:
- the default
ProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisTransport
'sProcessor
is null andConnection
doesn't have neither preferredProcessor
norProcessorSelector
.
-
setProcessorSelector
Sets the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisTransport
'sProcessor
is null andConnection
doesn't have neither preferredProcessor
norProcessorSelector
.Transport
'sProcessorSelector
is the last place, whereTransport
will try to getProcessor
to processConnection
I/O event. IfProcessorSelector
is not set -IllegalStateException
will be thrown.- Parameters:
selector
- the defaultProcessorSelector
, which will be used to getProcessor
to processConnection
I/O events, in case if thisTransport
'sProcessor
is null andConnection
doesn't have neither preferredProcessor
norProcessorSelector
.
-
getMemoryManager
MemoryManager getMemoryManager()Get theTransport
associatedMemoryManager
, which will be used by theTransport
, itsConnection
s and by during processing I/O events, occurred onConnection
s.- Returns:
- the
Transport
associatedMemoryManager
, which will be used by theTransport
, itsConnection
s and by during processing I/O events, occurred onConnection
s.
-
setMemoryManager
Set theTransport
associatedMemoryManager
, which will be used by theTransport
, itsConnection
s and by during processing I/O events, occurred onConnection
s.- Parameters:
memoryManager
- theTransport
associatedMemoryManager
, which will be used by theTransport
, itsConnection
s and by during processing I/O events, occurred onConnection
s.
-
getIOStrategy
IOStrategy getIOStrategy()Get theIOStrategy
implementation, which will be used byTransport
to processIOEvent
.IOStrategy
is responsible for choosing the way, how I/O event will be processed: using currentThread
, workerThread
; or make any other decisions.- Returns:
- the
IOStrategy
implementation, which will be used byTransport
to processIOEvent
.
-
setIOStrategy
Set theIOStrategy
implementation, which will be used byTransport
to processIOEvent
.IOStrategy
is responsible for choosing the way, how I/O event will be processed: using currentThread
, workerThread
; or make any other decisions.- Parameters:
IOStrategy
- theIOStrategy
implementation, which will be used byTransport
to processIOEvent
.
-
getReadBufferSize
int getReadBufferSize()Get the default size ofBuffer
s, which will be allocated for reading data fromTransport
'sConnection
s. For particularConnection
, this setting could be overridden byConnection.getReadBufferSize()
.- Returns:
- the default size of
Buffer
s, which will be allocated for reading data fromTransport
'sConnection
s.
-
setReadBufferSize
void setReadBufferSize(int readBufferSize) Set the default size ofBuffer
s, which will be allocated for reading data fromTransport
'sConnection
s. For particularConnection
, this setting could be overridden byConnection.setReadBufferSize(int)
. If not explicitly configured, this value will be set toDEFAULT_READ_BUFFER_SIZE
.- Parameters:
readBufferSize
- the default size ofBuffer
s, which will be allocated for reading data fromTransport
'sConnection
s.
-
getWriteBufferSize
int getWriteBufferSize()Get the default size ofBuffer
s, which will be allocated for writing data toTransport
'sConnection
s. For particularConnection
, this setting could be overridden byConnection.getWriteBufferSize()
.- Returns:
- the default size of
Buffer
s, which will be allocated for writing data toTransport
'sConnection
s.
-
setWriteBufferSize
void setWriteBufferSize(int writeBufferSize) Set the default size ofBuffer
s, which will be allocated for writing data toTransport
'sConnection
s. For particularConnection
, this setting could be overridden byConnection.setWriteBufferSize(int)
.- Parameters:
writeBufferSize
- the default size ofBuffer
s, which will be allocated for writing data toTransport
'sConnection
s.
-
getWorkerThreadPool
ExecutorService getWorkerThreadPool()Get a thread pool, which will run IOEvent processing (depending on TransportIOStrategy
) to let kernel threads continue their job.- Returns:
ExecutorService
transport worker thread pool.
-
getKernelThreadPool
ExecutorService getKernelThreadPool()- Returns:
ExecutorService
responsible for running Transport internal tasks. For exampleSelectorRunner
threads for NIO.
-
setWorkerThreadPool
Set a thread pool, which will run IOEvent processing (depending on TransportIOStrategy
) to let kernel threads continue their job.- Parameters:
threadPool
-ExecutorService
transport worker thread pool.
-
setKernelThreadPool
Set a thread pool which will run Transport internal tasks. For exampleSelectorRunner
threads for NIO.- Parameters:
threadPool
-ExecutorService
forSelectorRunner
s
-
setKernelThreadPoolConfig
Set theThreadPoolConfig
to be used by the Transport internal thread pool.- Parameters:
kernelConfig
- kernel thread pool configuration.
-
setWorkerThreadPoolConfig
Set theThreadPoolConfig
to be used by the worker thread pool.- Parameters:
workerConfig
- worker thread pool configuration.
-
getKernelThreadPoolConfig
ThreadPoolConfig getKernelThreadPoolConfig()- Returns:
- the
ThreadPoolConfig
that will be used to construct theExecutorService
which will run theTransport
's internal tasks. For exampleSelectorRunner
s for NIO.
-
getWorkerThreadPoolConfig
ThreadPoolConfig getWorkerThreadPoolConfig()- Returns:
- the
ThreadPoolConfig
that will be used to construct theExecutorService
forIOStrategies
that require worker threads. Depending on theIOStrategy
being used, this may returnnull
.
-
getAttributeBuilder
AttributeBuilder getAttributeBuilder()GetTransport
associatedAttributeBuilder
, which will be used byTransport
and itsConnection
s to store customAttribute
s.- Returns:
Transport
associatedAttributeBuilder
, which will be used byTransport
and itsConnection
s to store customAttribute
s.
-
setAttributeBuilder
SetTransport
associatedAttributeBuilder
, which will be used byTransport
and itsConnection
s to store customAttribute
s.- Parameters:
attributeBuilder
-Transport
associatedAttributeBuilder
, which will be used byTransport
and itsConnection
s to store customAttribute
s.
-
start
Starts the transport- Throws:
IOException
- if transport fails to start. This may not occur if Transport was not inTransport.State.STOPPED
.
-
stop
Deprecated.UseshutdownNow()
.Stops the transport and closes all the connections- Throws:
IOException
- if there was an error shutting down
-
shutdown
GrizzlyFuture<Transport> shutdown()Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown. This method will wait indefinitely for all interested parties to signal it is safe to terminate the transport. InvokeshutdownNow()
to terminate the transport if the graceful shutdown is taking too long.- Returns:
- a
GrizzlyFuture
which will return the stopped transport. - Since:
- 2.3.5
- See Also:
-
shutdown
Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown. This method will wait for the specified time for all interested parties to signal it is safe to terminate the transport. If the timeout is exceeded, the transport will be terminated forcefully.- Parameters:
gracePeriod
- the grace period for a graceful shutdown before the transport is forcibly terminated. If gracePeriod is zero or less, then there is no time limit for the shutdown.timeUnit
- theTimeUnit
of the specified grace period.- Returns:
- a
GrizzlyFuture
which will return the stopped transport. - Since:
- 2.3.5
-
shutdownNow
Forcibly stops the transport and closes all connections.- Throws:
IOException
- if there was an error shutting down- Since:
- 2.3.5
- See Also:
-
addShutdownListener
Adds aGracefulShutdownListener
which will be called whenshutdown()
is called to enable graceful shutdown of transports. This allows the owner of the listener to signal that all shutdown tasks are complete and that it's safe to finalize the termination of the transport- Parameters:
shutdownListener
- theGracefulShutdownListener
- Returns:
true
if the listener was successfully registered, otherwisefalse
. When this method returnsfalse
it means one of two things: the transport is stopping or is stopped, or the listener has already been registered.- Since:
- 2.3.5
-
pause
void pause()Pauses the transport -
resume
void resume()Resumes the transport after a pause -
fireIOEvent
Fires specificIOEvent
on theConnection
- Parameters:
ioEvent
- I/O eventconnection
-Connection
, on which we fire the event.listener
- I/O event life-cycle listener.
-
isStopped
boolean isStopped()Returns true, if this Transport is in stopped state, false otherwise.- Returns:
- true, if this Transport is in stopped state, false otherwise.
-
isPaused
boolean isPaused() -
getReader
Get theReader
to read data from theConnection
. The Transport may decide to return blocking or non-blockingReader
depending on theConnection
settings.- Parameters:
connection
-Connection
.- Returns:
Reader
.
-
getReader
Get theReader
implementation, depending on the requested mode.- Parameters:
isBlocking
- blocking mode.- Returns:
Reader
.
-
getWriter
Get theWriter
to write data to theConnection
. The Transport may decide to return blocking or non-blockingWriter
depending on theConnection
settings.- Parameters:
connection
-Connection
.- Returns:
Writer
.
-
getWriter
Get theWriter
implementation, depending on the requested mode.- Parameters:
isBlocking
- blocking mode.- Returns:
Writer
.
-
getConnectionMonitoringConfig
MonitoringConfig<ConnectionProbe> getConnectionMonitoringConfig()Get the monitoring configuration for TransportConnection
s.- Returns:
- the configuration
-
getThreadPoolMonitoringConfig
MonitoringConfig<ThreadPoolProbe> getThreadPoolMonitoringConfig()Get the monitoring configuration for Transport thread pool.- Returns:
- the configuration
-
getMonitoringConfig
MonitoringConfig<TransportProbe> getMonitoringConfig()Get the Transport monitoring configurationMonitoringConfig
.- Specified by:
getMonitoringConfig
in interfaceMonitoringAware<TransportProbe>
- Returns:
- the object associated
MonitoringConfig
.
-
notifyTransportError
Method gets invoked, when error occur during the Transport lifecycle.- Parameters:
error
-Throwable
.
-
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 value of the read timeout
- 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 value of the write timeout
- 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:
-
shutdownNow()
.