Package org.glassfish.grizzly
Interface Transport
-
- All Superinterfaces:
MonitoringAware<TransportProbe>
- All Known Implementing Classes:
AbstractTransport,NIOTransport,TCPNIOTransport,UDPNIOTransport
public interface Transport extends MonitoringAware<TransportProbe>
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 Modifier and Type Interface Description static classTransport.State
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_READ_BUFFER_SIZEThe default read buffer size.static intDEFAULT_READ_TIMEOUTDefault read timeout in seconds.static intDEFAULT_WRITE_BUFFER_SIZEThe default write buffer size.static intDEFAULT_WRITE_TIMEOUTDefault write timeout in seconds.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description booleanaddShutdownListener(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 theConnectionAttributeBuildergetAttributeBuilder()GetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.MonitoringConfig<ConnectionProbe>getConnectionMonitoringConfig()Get the monitoring configuration for TransportConnections.IOStrategygetIOStrategy()ExecutorServicegetKernelThreadPool()ThreadPoolConfiggetKernelThreadPoolConfig()MemoryManagergetMemoryManager()Get theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.MonitoringConfig<TransportProbe>getMonitoringConfig()Get the Transport monitoring configurationMonitoringConfig.StringgetName()Gets theTransportname.ProcessorgetProcessor()Gets the defaultProcessor, which will processConnectionI/O events in case, ifConnectiondoesn't have ownProcessorpreferences.ProcessorSelectorgetProcessorSelector()Gets the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.intgetReadBufferSize()Get the default size ofBuffers, which will be allocated for reading data fromTransport'sConnections.ReadergetReader(boolean isBlocking)Get theReaderimplementation, depending on the requested mode.ReadergetReader(Connection connection)Get theReaderto read data from theConnection.longgetReadTimeout(TimeUnit timeUnit)Returns the current value for the blocking read timeout converted to the providedTimeUnitspecification.StateHolder<Transport.State>getState()Return theTransportstate controller.MonitoringConfig<ThreadPoolProbe>getThreadPoolMonitoringConfig()Get the monitoring configuration for Transport thread pool.ExecutorServicegetWorkerThreadPool()Get a thread pool, which will run IOEvent processing (depending on TransportIOStrategy) to let kernel threads continue their job.ThreadPoolConfiggetWorkerThreadPoolConfig()intgetWriteBufferSize()Get the default size ofBuffers, which will be allocated for writing data toTransport'sConnections.WritergetWriter(boolean isBlocking)Get theWriterimplementation, depending on the requested mode.WritergetWriter(Connection connection)Get theWriterto write data to theConnection.longgetWriteTimeout(TimeUnit timeUnit)Returns the current value for the blocking write timeout converted to the providedTimeUnitspecification.booleanisBlocking()Returns theTransportmode.booleanisPaused()booleanisStandalone()booleanisStopped()Returns true, if this Transport is in stopped state, false otherwise.voidnotifyTransportError(Throwable error)Method gets invoked, when error occur during the Transport lifecycle.ProcessorobtainProcessor(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.voidsetName(String name)Sets 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.GrizzlyFuture<Transport>shutdown()Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.GrizzlyFuture<Transport>shutdown(long gracePeriod, TimeUnit timeUnit)Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.voidshutdownNow()Forcibly stops the transport and closes all connections.voidstart()Starts the transportvoidstop()Deprecated.UseshutdownNow().
-
-
-
Field Detail
-
DEFAULT_READ_BUFFER_SIZE
static final int DEFAULT_READ_BUFFER_SIZE
The default read buffer size.- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BUFFER_SIZE
static final int DEFAULT_WRITE_BUFFER_SIZE
The default write buffer size.- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT
static final int DEFAULT_READ_TIMEOUT
Default read timeout in seconds.- See Also:
- Constant Field Values
-
DEFAULT_WRITE_TIMEOUT
static final int DEFAULT_WRITE_TIMEOUT
Default write timeout in seconds.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
Processor obtainProcessor(IOEvent ioEvent, Connection connection)
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
void setProcessor(Processor processor)
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
void setProcessorSelector(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.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
void setMemoryManager(MemoryManager memoryManager)
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
void setIOStrategy(IOStrategy IOStrategy)
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
void setWorkerThreadPool(ExecutorService threadPool)
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
void setKernelThreadPool(ExecutorService threadPool)
Set a thread pool which will run Transport internal tasks. For exampleSelectorRunnerthreads for NIO.- Parameters:
threadPool-ExecutorServiceforSelectorRunners
-
setKernelThreadPoolConfig
void setKernelThreadPoolConfig(ThreadPoolConfig kernelConfig)
Set theThreadPoolConfigto be used by the Transport internal thread pool.- Parameters:
kernelConfig- kernel thread pool configuration.
-
setWorkerThreadPoolConfig
void setWorkerThreadPoolConfig(ThreadPoolConfig workerConfig)
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
void setAttributeBuilder(AttributeBuilder attributeBuilder)
SetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.- Parameters:
attributeBuilder-TransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.
-
start
void start() throws IOExceptionStarts the transport- Throws:
IOException- if transport fails to start. This may not occur if Transport was not inTransport.State.STOPPED.
-
stop
@Deprecated void stop() throws IOException
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:
GracefulShutdownListener
-
shutdown
GrizzlyFuture<Transport> shutdown(long gracePeriod, TimeUnit timeUnit)
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
void shutdownNow() throws IOExceptionForcibly stops the transport and closes all connections.- Throws:
IOException- if there was an error shutting down- Since:
- 2.3.5
- See Also:
to complete gracefully
-
addShutdownListener
boolean addShutdownListener(GracefulShutdownListener shutdownListener)
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
void fireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)
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
Reader getReader(Connection connection)
Get theReaderto read data from theConnection. The Transport may decide to return blocking or non-blockingReaderdepending on theConnectionsettings.- Parameters:
connection-Connection.- Returns:
Reader.
-
getReader
Reader getReader(boolean isBlocking)
Get theReaderimplementation, depending on the requested mode.- Parameters:
isBlocking- blocking mode.- Returns:
Reader.
-
getWriter
Writer getWriter(Connection connection)
Get theWriterto write data to theConnection. The Transport may decide to return blocking or non-blockingWriterdepending on theConnectionsettings.- Parameters:
connection-Connection.- Returns:
Writer.
-
getWriter
Writer getWriter(boolean isBlocking)
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
void notifyTransportError(Throwable error)
Method gets invoked, when error occur during the Transport lifecycle.- Parameters:
error-Throwable.
-
getReadTimeout
long getReadTimeout(TimeUnit timeUnit)
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
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- theTimeUnitspecification of the provided value.- Since:
- 2.3
- See Also:
Connection.setReadTimeout(long, java.util.concurrent.TimeUnit)
-
getWriteTimeout
long getWriteTimeout(TimeUnit timeUnit)
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
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- theTimeUnitspecification of the provided value.- Since:
- 2.3
- See Also:
Connection.setWriteTimeout(long, java.util.concurrent.TimeUnit)
-
-