java.lang.Object
org.glassfish.grizzly.AbstractTransport
- All Implemented Interfaces:
MonitoringAware<TransportProbe>,Transport
- Direct Known Subclasses:
NIOTransport
Abstract
Transport. Implements common transport functionality.- Author:
- Alexey Stashok
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AttributeBuilderTransport AttributeBuilder, which will be used to create Attributesprotected final DefaultMonitoringConfig<ConnectionProbe>Connection probesprotected booleanTransport modeprotected booleanDeprecated.protected ExecutorServiceKernel thread pool.protected ThreadPoolConfigprotected booleanprotected MemoryManagerTransport MemoryManagerprotected StringTransport nameprotected ProcessorTransport default Processorprotected ProcessorSelectorTransport default ProcessorSelectorprotected intTransport default buffer size for read operationsprotected longprotected final StateHolder<Transport.State>Transport state controllerprotected IOStrategyTransport strategyprotected final DefaultMonitoringConfig<ThreadPoolProbe>Thread pool probesprotected final DefaultMonitoringConfig<TransportProbe>Transport probesprotected ThreadPoolConfigprotected ExecutorServiceWorker thread poolprotected intTransport default buffer size for write operationsprotected longFields inherited from interface org.glassfish.grizzly.Transport
DEFAULT_READ_BUFFER_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, DEFAULT_WRITE_TIMEOUT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcloseConnection(Connection connection) Close the connection, managed by TransportvoidconfigureBlocking(boolean isBlocking) Sets theTransportmode.protected abstract ObjectCreate the Transport JMX management object.GetTransportassociatedAttributeBuilder, 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.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.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.protected static voidnotifyProbesBeforePause(AbstractTransport transport) Notify registeredTransportProbes about the before-pause event.protected static voidnotifyProbesBeforeResume(AbstractTransport transport) Notify registeredTransportProbes about the before-resume event.protected static voidnotifyProbesBeforeStart(AbstractTransport transport) Notify registeredTransportProbes about the before-start event.protected static voidnotifyProbesBeforeStop(AbstractTransport transport) Notify registeredTransportProbes about the before-stop event.protected static voidnotifyProbesConfigChanged(AbstractTransport transport) Notify registeredTransportProbes about the config changed event.protected static voidnotifyProbesPause(AbstractTransport transport) Notify registeredTransportProbes about the pause event.protected static voidnotifyProbesStop(AbstractTransport transport) Notify registeredTransportProbes about the stop event.obtainProcessor(IOEvent ioEvent, Connection connection) Gets the defaultProcessor, which will process TransportConnections I/O events in case, ifConnectiondoesn't have ownProcessorpreferences.voidsetAttributeBuilder(AttributeBuilder attributeBuilder) SetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.voidsetIOStrategy(IOStrategy IOStrategy) protected voidsetKernelPool0(ExecutorService kernelPool) voidsetKernelThreadPool(ExecutorService kernelPool) Set a thread pool which will run Transport internal tasks.voidsetKernelThreadPoolConfig(ThreadPoolConfig kernelPoolConfig) 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.protected voidsetWorkerThreadPool0(ExecutorService threadPool) voidsetWorkerThreadPoolConfig(ThreadPoolConfig workerPoolConfig) 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.voidstop()Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.glassfish.grizzly.Transport
addShutdownListener, configureStandalone, fireIOEvent, getReader, getReader, getWriter, getWriter, notifyTransportError, pause, resume, shutdown, shutdown, shutdownNow, start
-
Field Details
-
name
Transport name -
isBlocking
protected volatile boolean isBlockingTransport mode -
isStandalone
Deprecated. -
state
Transport state controller -
processor
Transport default Processor -
processorSelector
Transport default ProcessorSelector -
strategy
Transport strategy -
memoryManager
Transport MemoryManager -
workerThreadPool
Worker thread pool -
kernelPool
Kernel thread pool. -
attributeBuilder
Transport AttributeBuilder, which will be used to create Attributes -
readBufferSize
protected int readBufferSizeTransport default buffer size for read operations -
writeBufferSize
protected int writeBufferSizeTransport default buffer size for write operations -
workerPoolConfig
-
kernelPoolConfig
-
managedWorkerPool
protected boolean managedWorkerPool -
writeTimeout
protected long writeTimeout -
readTimeout
protected long readTimeout -
transportMonitoringConfig
Transport probes -
connectionMonitoringConfig
Connection probes -
threadPoolMonitoringConfig
Thread pool probes
-
-
Constructor Details
-
AbstractTransport
-
-
Method Details
-
getName
Gets theTransportname. -
setName
Sets theTransportname. -
isBlocking
public boolean isBlocking()Returns theTransportmode. true, ifTransportis operating in blocking mode, or false otherwise. SpecificTransportConnections may override this setting byConnection.isBlocking().- Specified by:
isBlockingin interfaceTransport- Returns:
- the
Transportmode. true, ifTransportis operating in blocking mode, or false otherwise.
-
configureBlocking
public void configureBlocking(boolean isBlocking) Sets theTransportmode. SpecificTransportConnections may override this setting byConnection.configureBlocking(boolean).- Specified by:
configureBlockingin interfaceTransport- Parameters:
isBlocking- theTransportmode. true, ifTransportshould operate in blocking mode, or false otherwise.
-
isStandalone
public boolean isStandalone()- Specified by:
isStandalonein interfaceTransport
-
getState
Return theTransportstate controller. Using the state controller, it is possible to get/set theTransportstate in thread-safe manner.- Specified by:
getStatein interfaceTransport- Returns:
StateHolderstate controller.
-
getReadBufferSize
public 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().- Specified by:
getReadBufferSizein interfaceTransport- Returns:
- the default size of
Buffers, which will be allocated for reading data fromTransport'sConnections.
-
setReadBufferSize
public 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 toTransport.DEFAULT_READ_BUFFER_SIZE.- Specified by:
setReadBufferSizein interfaceTransport- Parameters:
readBufferSize- the default size ofBuffers, which will be allocated for reading data fromTransport'sConnections.
-
getWriteBufferSize
public 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().- Specified by:
getWriteBufferSizein interfaceTransport- Returns:
- the default size of
Buffers, which will be allocated for writing data toTransport'sConnections.
-
setWriteBufferSize
public 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).- Specified by:
setWriteBufferSizein interfaceTransport- Parameters:
writeBufferSize- the default size ofBuffers, which will be allocated for writing data toTransport'sConnections.
-
isStopped
public boolean isStopped()Returns true, if this Transport is in stopped state, false otherwise. -
isPaused
public boolean isPaused() -
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).- Specified by:
obtainProcessorin interfaceTransport- 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
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).- Specified by:
getProcessorin interfaceTransport- 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.- Specified by:
setProcessorin interfaceTransport- Parameters:
processor- the defaultProcessor, which will processConnectionI/O events, if one doesn't have ownProcessorpreferences.
-
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.- Specified by:
getProcessorSelectorin interfaceTransport- 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.- Specified by:
setProcessorSelectorin interfaceTransport- Parameters:
selector- the defaultProcessorSelector, which will be used to getProcessorto processConnectionI/O events, in case if thisTransport'sProcessoris null andConnectiondoesn't have neither preferredProcessornorProcessorSelector.
-
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.- Specified by:
getIOStrategyin interfaceTransport- 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.- Specified by:
setIOStrategyin interfaceTransport- Parameters:
IOStrategy- theIOStrategyimplementation, which will be used byTransportto processIOEvent.
-
getMemoryManager
Get theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.- Specified by:
getMemoryManagerin interfaceTransport- 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.- Specified by:
setMemoryManagerin interfaceTransport- Parameters:
memoryManager- theTransportassociatedMemoryManager, which will be used by theTransport, itsConnections and by during processing I/O events, occurred onConnections.
-
getWorkerThreadPool
Get a thread pool, which will run IOEvent processing (depending on TransportIOStrategy) to let kernel threads continue their job.- Specified by:
getWorkerThreadPoolin interfaceTransport- Returns:
ExecutorServicetransport worker thread pool.
-
getKernelThreadPool
- Specified by:
getKernelThreadPoolin interfaceTransport- Returns:
ExecutorServiceresponsible for running Transport internal tasks. For exampleSelectorRunnerthreads for NIO.
-
setKernelThreadPool
Set a thread pool which will run Transport internal tasks. For exampleSelectorRunnerthreads for NIO.- Specified by:
setKernelThreadPoolin interfaceTransport- Parameters:
kernelPool-ExecutorServiceforSelectorRunners
-
setKernelThreadPoolConfig
Set theThreadPoolConfigto be used by the Transport internal thread pool.- Specified by:
setKernelThreadPoolConfigin interfaceTransport- Parameters:
kernelPoolConfig- kernel thread pool configuration.
-
setWorkerThreadPoolConfig
Set theThreadPoolConfigto be used by the worker thread pool.- Specified by:
setWorkerThreadPoolConfigin interfaceTransport- Parameters:
workerPoolConfig- worker thread pool configuration.
-
getKernelThreadPoolConfig
- Specified by:
getKernelThreadPoolConfigin interfaceTransport- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theTransport's internal tasks. For exampleSelectorRunners for NIO.
-
getWorkerThreadPoolConfig
- Specified by:
getWorkerThreadPoolConfigin interfaceTransport- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threads. Depending on theIOStrategybeing used, this may returnnull.
-
setWorkerThreadPool
Set a thread pool, which will run IOEvent processing (depending on TransportIOStrategy) to let kernel threads continue their job.- Specified by:
setWorkerThreadPoolin interfaceTransport- Parameters:
threadPool-ExecutorServicetransport worker thread pool.
-
setWorkerThreadPool0
-
setKernelPool0
-
getAttributeBuilder
GetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.- Specified by:
getAttributeBuilderin interfaceTransport- Returns:
TransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.
-
setAttributeBuilder
SetTransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.- Specified by:
setAttributeBuilderin interfaceTransport- Parameters:
attributeBuilder-TransportassociatedAttributeBuilder, which will be used byTransportand itsConnections to store customAttributes.
-
closeConnection
Close the connection, managed by Transport- Parameters:
connection-NIOConnectionto close- Throws:
IOException- not used
-
getConnectionMonitoringConfig
Get the monitoring configuration for TransportConnections.- Specified by:
getConnectionMonitoringConfigin interfaceTransport- Returns:
- the configuration
-
getMonitoringConfig
Get the Transport monitoring configurationMonitoringConfig.- Specified by:
getMonitoringConfigin interfaceMonitoringAware<TransportProbe>- Specified by:
getMonitoringConfigin interfaceTransport- Returns:
- the object associated
MonitoringConfig.
-
getThreadPoolMonitoringConfig
Get the monitoring configuration for Transport thread pool.- Specified by:
getThreadPoolMonitoringConfigin interfaceTransport- Returns:
- the configuration
-
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.- Specified by:
getReadTimeoutin interfaceTransport- Parameters:
timeUnit- theTimeUnitto convert the returned result to.- Returns:
- the value of the read timeout
-
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.- Specified by:
setReadTimeoutin interfaceTransport- Parameters:
timeout- the new timeout valuetimeUnit- theTimeUnitspecification of the provided value.- 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.- Specified by:
getWriteTimeoutin interfaceTransport- Parameters:
timeUnit- theTimeUnitto convert the returned result to.- Returns:
- the value of the write timeout
-
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.- Specified by:
setWriteTimeoutin interfaceTransport- Parameters:
timeout- the new timeout valuetimeUnit- theTimeUnitspecification of the provided value.- See Also:
-
notifyProbesBeforeStart
Notify registeredTransportProbes about the before-start event.- Parameters:
transport- the Transport event occurred on.- Since:
- 3.0
-
notifyProbesBeforeStop
Notify registeredTransportProbes about the before-stop event.- Parameters:
transport- the Transport event occurred on.- Since:
- 3.0
-
notifyProbesStop
Notify registeredTransportProbes about the stop event.- Parameters:
transport- the Transport event occurred on.
-
notifyProbesBeforePause
Notify registeredTransportProbes about the before-pause event.- Parameters:
transport- the Transport event occurred on.- Since:
- 3.0
-
notifyProbesPause
Notify registeredTransportProbes about the pause event.- Parameters:
transport- the Transport event occurred on.
-
notifyProbesBeforeResume
Notify registeredTransportProbes about the before-resume event.- Parameters:
transport- the Transport event occurred on.- Since:
- 3.0
-
notifyProbesConfigChanged
Notify registeredTransportProbes about the config changed event.- Parameters:
transport- the Transport event occurred on.
-
stop
Deprecated.Stops the transport and closes all the connections- Specified by:
stopin interfaceTransport- Throws:
IOException- if there was an error shutting down
-
createJmxManagementObject
Create the Transport JMX management object.- Returns:
- the Transport JMX management object.
-