- 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 intThe default read buffer size.static final intDefault read timeout in seconds.static final intThe default write buffer size.static final intDefault write timeout in seconds. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddShutdownListener(GracefulShutdownListener shutdownListener) Adds aGracefulShutdownListenerwhich will be called whenshutdown()is called to enable graceful shutdown of transports.voidconfigureBlocking(boolean isBlocking) Sets theTransportmode.voidconfigureStandalone(boolean isStandalone) voidfireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener) Fires specificIOEventon theConnectionGetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.Get the monitoring configuration for TransportConnections.Get theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.Get the Transport monitoring configurationMonitoringConfig.getName()Gets theTransportname.Gets the defaultProcessor, which will processConnectionI/O events in case, ifConnectiondoesn't have ownProcessorpreferences.Gets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.intGet the default size ofBuffers, which will be allocated for reading data fromTransport'sConnections.getReader(boolean isBlocking) Get theReaderimplementation, depending on the requested mode.getReader(Connection connection) Get theReaderto read data from theConnection.longgetReadTimeout(TimeUnit timeUnit) Returns the current value for the blocking read timeout converted to the providedTimeUnitspecification.getState()Return theTransportstate 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.intGet the default size ofBuffers, which will be allocated for writing data toTransport'sConnections.getWriter(boolean isBlocking) Get theWriterimplementation, depending on the requested mode.getWriter(Connection connection) Get theWriterto write data to theConnection.longgetWriteTimeout(TimeUnit timeUnit) Returns the current value for the blocking write timeout converted to the providedTimeUnitspecification.booleanReturns theTransportmode.booleanisPaused()booleanbooleanReturns true, if this Transport is in stopped state, false otherwise.voidnotifyTransportError(Throwable error) Method gets invoked, when error occur during the Transport lifecycle.obtainProcessor(IOEvent ioEvent, Connection connection) Gets the defaultProcessor, which will process TransportConnections I/O events in case, ifConnectiondoesn't have ownProcessorpreferences.voidpause()Pauses the transportvoidresume()Resumes the transport after a pausevoidsetAttributeBuilder(AttributeBuilder attributeBuilder) SetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.voidsetIOStrategy(IOStrategy IOStrategy) voidsetKernelThreadPool(ExecutorService threadPool) Set a thread pool which will run Transport internal tasks.voidsetKernelThreadPoolConfig(ThreadPoolConfig kernelConfig) Set theThreadPoolConfigto be used by the Transport internal thread pool.voidsetMemoryManager(MemoryManager memoryManager) Set theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.voidSets theTransportname.voidsetProcessor(Processor processor) Sets the defaultProcessor, which will processConnectionI/O events in case, ifConnectiondoesn't have ownProcessorpreferences.voidsetProcessorSelector(ProcessorSelector selector) Sets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.voidsetReadBufferSize(int readBufferSize) Set the default size ofBuffers, which will be allocated for reading data fromTransport'sConnections.voidsetReadTimeout(long timeout, TimeUnit timeUnit) Specifies the timeout for the blocking reads.voidsetWorkerThreadPool(ExecutorService threadPool) Set a thread pool, which will run IOEvent processing (depending on TransportIOStrategy) to let kernel threads continue their job.voidsetWorkerThreadPoolConfig(ThreadPoolConfig workerConfig) Set theThreadPoolConfigto be used by the worker thread pool.voidsetWriteBufferSize(int writeBufferSize) Set the default size ofBuffers, which will be allocated for writing data toTransport'sConnections.voidsetWriteTimeout(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.voidForcibly stops the transport and closes all connections.voidstart()Starts the transportvoidstop()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 theTransportname.- Returns:
- the
Transportname.
-
setName
Sets theTransportname.- Parameters:
name- theTransportname.
-
getState
StateHolder<Transport.State> getState()Return theTransportstate controller. Using the state controller, it is possible to get/set theTransportstate in thread-safe manner.- Returns:
StateHolderstate controller.
-
isBlocking
boolean isBlocking()Returns theTransportmode. true, ifTransportis operating in blocking mode, or false otherwise. SpecificTransportConnections may override this setting byConnection.isBlocking(). -
configureBlocking
void configureBlocking(boolean isBlocking) Sets theTransportmode. SpecificTransportConnections may override this setting byConnection.configureBlocking(boolean). -
configureStandalone
void configureStandalone(boolean isStandalone) -
isStandalone
boolean isStandalone() -
obtainProcessor
Gets the defaultProcessor, which will process TransportConnections I/O events in case, ifConnectiondoesn't have ownProcessorpreferences. IfTransportassociatedProcessoris null, andConnectiondoesn't have any preferredProcessor- thenTransportwill try to getProcessorusingProcessorSelector.select(IOEvent, Connection).- Parameters:
ioEvent- the type of events the Processor should handleconnection- connection to obtain Processor for- Returns:
- the default
Processor, which will processConnectionI/O events, if one doesn't have ownProcessorpreferences.
-
getProcessor
Processor getProcessor()Gets the defaultProcessor, which will processConnectionI/O events in case, ifConnectiondoesn't have ownProcessorpreferences. IfTransportassociatedProcessoris null, andConnectiondoesn't have any preferredProcessor- thenTransportwill try to getProcessorusingProcessorSelector.select(IOEvent, Connection).- Returns:
- the default
Processor, which will processConnectionI/O events, if one doesn't have ownProcessorpreferences.
-
setProcessor
Sets the defaultProcessor, which will processConnectionI/O events in case, ifConnectiondoesn't have ownProcessorpreferences.- Parameters:
processor- the defaultProcessor, which will processConnectionI/O events, if one doesn't have ownProcessorpreferences.
-
getProcessorSelector
ProcessorSelector getProcessorSelector()Gets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.Transport'sProcessorSelectoris the last place, whereTransportwill try to getProcessorto processConnectionI/O event. IfProcessorSelectoris not set -IllegalStateExceptionwill be thrown.- Returns:
- the default
ProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.
-
setProcessorSelector
Sets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.Transport'sProcessorSelectoris the last place, whereTransportwill try to getProcessorto processConnectionI/O event. IfProcessorSelectoris not set -IllegalStateExceptionwill be thrown.- Parameters:
selector- the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.
-
getMemoryManager
MemoryManager getMemoryManager()Get theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.- Returns:
- the
TransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.
-
setMemoryManager
Set theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.- Parameters:
memoryManager- theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.
-
getIOStrategy
IOStrategy getIOStrategy()Get theIOStrategyimplementation, which will be used byTransportto processIOEvent.IOStrategyis responsible for choosing the way, how I/O event will be processed: using currentThread, workerThread; or make any other decisions.- Returns:
- the
IOStrategyimplementation, which will be used byTransportto processIOEvent.
-
setIOStrategy
Set theIOStrategyimplementation, which will be used byTransportto processIOEvent.IOStrategyis responsible for choosing the way, how I/O event will be processed: using currentThread, workerThread; or make any other decisions.- Parameters:
IOStrategy- theIOStrategyimplementation, which will be used byTransportto processIOEvent.
-
getReadBufferSize
int getReadBufferSize()Get the default size ofBuffers, which will be allocated for reading data fromTransport'sConnections. For particularConnection, this setting could be overridden byConnection.getReadBufferSize().- Returns:
- the default size of
Buffers, which will be allocated for reading data fromTransport'sConnections.
-
setReadBufferSize
void setReadBufferSize(int readBufferSize) Set the default size ofBuffers, which will be allocated for reading data fromTransport'sConnections. 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 ofBuffers, which will be allocated for reading data fromTransport'sConnections.
-
getWriteBufferSize
int getWriteBufferSize()Get the default size ofBuffers, which will be allocated for writing data toTransport'sConnections. For particularConnection, this setting could be overridden byConnection.getWriteBufferSize().- Returns:
- the default size of
Buffers, which will be allocated for writing data toTransport'sConnections.
-
setWriteBufferSize
void setWriteBufferSize(int writeBufferSize) Set the default size ofBuffers, which will be allocated for writing data toTransport'sConnections. For particularConnection, this setting could be overridden byConnection.setWriteBufferSize(int).- Parameters:
writeBufferSize- the default size ofBuffers, which will be allocated for writing data toTransport'sConnections.
-
getWorkerThreadPool
ExecutorService getWorkerThreadPool()Get a thread pool, which will run IOEvent processing (depending on TransportIOStrategy) to let kernel threads continue their job.- Returns:
ExecutorServicetransport worker thread pool.
-
getKernelThreadPool
ExecutorService getKernelThreadPool()- Returns:
ExecutorServiceresponsible for running Transport internal tasks. For exampleSelectorRunnerthreads for NIO.
-
setWorkerThreadPool
Set a thread pool, which will run IOEvent processing (depending on TransportIOStrategy) to let kernel threads continue their job.- Parameters:
threadPool-ExecutorServicetransport worker thread pool.
-
setKernelThreadPool
Set a thread pool which will run Transport internal tasks. For exampleSelectorRunnerthreads for NIO.- Parameters:
threadPool-ExecutorServiceforSelectorRunners
-
setKernelThreadPoolConfig
Set theThreadPoolConfigto be used by the Transport internal thread pool.- Parameters:
kernelConfig- kernel thread pool configuration.
-
setWorkerThreadPoolConfig
Set theThreadPoolConfigto be used by the worker thread pool.- Parameters:
workerConfig- worker thread pool configuration.
-
getKernelThreadPoolConfig
ThreadPoolConfig getKernelThreadPoolConfig()- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theTransport's internal tasks. For exampleSelectorRunners for NIO.
-
getWorkerThreadPoolConfig
ThreadPoolConfig getWorkerThreadPoolConfig()- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threads. Depending on theIOStrategybeing used, this may returnnull.
-
getAttributeBuilder
AttributeBuilder getAttributeBuilder()GetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.- Returns:
TransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.
-
setAttributeBuilder
SetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.- Parameters:
attributeBuilder-TransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.
-
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
GrizzlyFuturewhich 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- theTimeUnitof the specified grace period.- Returns:
- a
GrizzlyFuturewhich 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 aGracefulShutdownListenerwhich 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:
trueif the listener was successfully registered, otherwisefalse. When this method returnsfalseit 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 specificIOEventon 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 theReaderto read data from theConnection. The Transport may decide to return blocking or non-blockingReaderdepending on theConnectionsettings.- Parameters:
connection-Connection.- Returns:
Reader.
-
getReader
Get theReaderimplementation, depending on the requested mode.- Parameters:
isBlocking- blocking mode.- Returns:
Reader.
-
getWriter
Get theWriterto write data to theConnection. The Transport may decide to return blocking or non-blockingWriterdepending on theConnectionsettings.- Parameters:
connection-Connection.- Returns:
Writer.
-
getWriter
Get theWriterimplementation, depending on the requested mode.- Parameters:
isBlocking- blocking mode.- Returns:
Writer.
-
getConnectionMonitoringConfig
MonitoringConfig<ConnectionProbe> getConnectionMonitoringConfig()Get the monitoring configuration for TransportConnections.- 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:
getMonitoringConfigin 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 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 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- 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 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- theTimeUnitspecification of the provided value.- Since:
- 2.3
- See Also:
-
shutdownNow().