Module org.glassfish.grizzly
Package org.glassfish.grizzly
Class NIOTransportBuilder<T extends NIOTransportBuilder>
java.lang.Object
org.glassfish.grizzly.NIOTransportBuilder<T>
- Direct Known Subclasses:
TCPNIOTransportBuilder,UDPNIOTransportBuilder
This builder is responsible for creating
NIOTransport implementations as well as providing basic
configuration for IOStrategies and thread pools.- Since:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AttributeBuilderprotected intprotected intprotected IOStrategyprotected ThreadPoolConfigprotected intprotected MemoryManagerprotected Stringprotected NIOChannelDistributorprotected booleanprotected Processorprotected ProcessorSelectorprotected intprotected longprotected booleanprotected SelectionKeyHandlerprotected SelectorHandlerprotected SelectorProviderprotected intprotected final Class<? extends NIOTransport>protected ThreadPoolConfigprotected intprotected long -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNIOTransportBuilder(Class<? extends NIOTransport> transportClass) -
Method Summary
Modifier and TypeMethodDescriptionbuild()protected abstract NIOTransportintintintMax asynchronous write queue size in bytesgetName()intlonggetReadTimeout(TimeUnit timeUnit) intprotected abstract TgetThis()intlonggetWriteTimeout(TimeUnit timeUnit) booleanbooleanWhether address may be reused for multiple socketssetAttributeBuilder(AttributeBuilder attributeBuilder) Set theAttributeBuilderto be used by the createdNIOTransport.setClientSocketSoTimeout(int clientSocketSoTimeout) Sets the timeout on socket blocking operations for the clientsetConnectionTimeout(int connectionTimeout) setIOStrategy(IOStrategy ioStrategy) Changes theIOStrategythat will be used.setMaxAsyncWriteQueueSizeInBytes(int maxAsyncWriteQueueSizeInBytes) setMemoryManager(MemoryManager memoryManager) Set theMemoryManagerto be used by the createdNIOTransport.setNIOChannelDistributor(NIOChannelDistributor nioChannelDistributor) Set theNIOChannelDistributorto be used by the createdNIOTransport.setOptimizedForMultiplexing(boolean optimizedForMultiplexing) setProcessor(Processor processor) setProcessorSelector(ProcessorSelector processorSelector) setReadBufferSize(int readBufferSize) setReadTimeout(long timeout, TimeUnit timeUnit) Sets the value of the blocking read timeoutsetReuseAddress(boolean reuseAddress) Sets whether address may be reused for multiple socketssetSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler) Set theSelectionKeyHandlerto be used by the createdNIOTransport.setSelectorHandler(SelectorHandler selectorHandler) Set theSelectorHandlerto be used by the createdNIOTransport.setSelectorProvider(SelectorProvider selectorProvider) Set theSelectorProviderto be used by the createdNIOTransport.setSelectorRunnersCount(int selectorRunnersCount) Sets the number ofSelectors to be created to serve Transport connections.setSelectorThreadPoolConfig(ThreadPoolConfig kernelConfig) Sets theThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theNIOTransport'sSelectorRunners.setWorkerThreadPoolConfig(ThreadPoolConfig workerConfig) Sets theThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threadssetWriteBufferSize(int writeBufferSize) setWriteTimeout(long timeout, TimeUnit timeUnit)
-
Field Details
-
transportClass
-
workerConfig
-
kernelConfig
-
selectorProvider
-
selectorHandler
-
selectionKeyHandler
-
memoryManager
-
attributeBuilder
-
ioStrategy
-
selectorRunnerCount
protected int selectorRunnerCount -
nioChannelDistributor
-
name
-
processor
-
processorSelector
-
readBufferSize
protected int readBufferSize -
writeBufferSize
protected int writeBufferSize -
clientSocketSoTimeout
protected int clientSocketSoTimeout -
connectionTimeout
protected int connectionTimeout -
reuseAddress
protected boolean reuseAddress -
maxPendingBytesPerConnection
protected int maxPendingBytesPerConnection -
optimizedForMultiplexing
protected boolean optimizedForMultiplexing -
readTimeout
protected long readTimeout -
writeTimeout
protected long writeTimeout
-
-
Constructor Details
-
NIOTransportBuilder
Constructs a new
NIOTransportusing the giventransportClassandIOStrategy.The builder's worker thread pool configuration will be based on the return value of
WorkerThreadPoolConfigProducer.createDefaultWorkerPoolConfig(Transport). If worker thread configuration is non-null, the initial selector thread pool configuration will be cloned from it, otherwise a default configuration will be chosen.- Parameters:
transportClass- the class of theNIOTransportimplementation to be used.
-
-
Method Details
-
getSelectorRunnersCount
public int getSelectorRunnersCount()- Returns:
- the number of
Selectors to be created to serve Transport connections. -1 is the default value, which lets the Transport to pick the value, usually it's equal to the number of CPU coresRuntime.availableProcessors()
-
setSelectorRunnersCount
Sets the number ofSelectors to be created to serve Transport connections. -1 is the default value, which lets the Transport to pick the value, usually it's equal to the number of CPU coresRuntime.availableProcessors().- Parameters:
selectorRunnersCount- number of channels- Returns:
- the builder
-
getWorkerThreadPoolConfig
- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threads. This method will returnnullif aThreadPoolConfighad not been previously set.
-
setWorkerThreadPoolConfig
Sets theThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threads- Parameters:
workerConfig- the config- Returns:
- this builder
-
getSelectorThreadPoolConfig
- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theNIOTransport'sSelectorRunners.
-
setSelectorThreadPoolConfig
Sets theThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theNIOTransport'sSelectorRunners.- Parameters:
kernelConfig- the config- Returns:
- this builder
-
getIOStrategy
- Returns:
- the
IOStrategythat will be used by the createdNIOTransport.
-
setIOStrategy
Changes the
IOStrategythat will be used. Invoking this method may change the return value ofgetWorkerThreadPoolConfig()- Parameters:
ioStrategy- theIOStrategyto use.- Returns:
- this
NIOTransportBuilder
-
getMemoryManager
- Returns:
- the
MemoryManagerthat will be used by the createdNIOTransport. If not explicitly set, thenMemoryManager.DEFAULT_MEMORY_MANAGERwill be used.
-
setMemoryManager
Set theMemoryManagerto be used by the createdNIOTransport.- Parameters:
memoryManager- theMemoryManager.- Returns:
- this
NIOTransportBuilder
-
getSelectorHandler
- Returns:
- the
SelectorHandlerthat will be used by the createdNIOTransport. If not explicitly set, thenSelectorHandler.DEFAULT_SELECTOR_HANDLERwill be used.
-
setSelectorHandler
Set theSelectorHandlerto be used by the createdNIOTransport.- Parameters:
selectorHandler- theSelectorHandler.- Returns:
- this
NIOTransportBuilder
-
getSelectionKeyHandler
- Returns:
- the
SelectionKeyHandlerthat will be used by the createdNIOTransport. If not explicitly set, thenSelectionKeyHandler.DEFAULT_SELECTION_KEY_HANDLERwill be used.
-
setSelectionKeyHandler
Set theSelectionKeyHandlerto be used by the createdNIOTransport.- Parameters:
selectionKeyHandler- theSelectionKeyHandler.- Returns:
- this
NIOTransportBuilder
-
getAttributeBuilder
- Returns:
- the
AttributeBuilderthat will be used by the createdNIOTransport. If not explicitly set, thenAttributeBuilder.DEFAULT_ATTRIBUTE_BUILDERwill be used.
-
setAttributeBuilder
Set theAttributeBuilderto be used by the createdNIOTransport.- Parameters:
attributeBuilder- theAttributeBuilder.- Returns:
- this
NIOTransportBuilder
-
getNIOChannelDistributor
- Returns:
- the
NIOChannelDistributorthat will be used by the createdNIOTransport. If not explicitly set, thenAttributeBuilder.DEFAULT_ATTRIBUTE_BUILDERwill be used.
-
setNIOChannelDistributor
Set theNIOChannelDistributorto be used by the createdNIOTransport.- Parameters:
nioChannelDistributor- theNIOChannelDistributor.- Returns:
- this
NIOTransportBuilder
-
getSelectorProvider
- Returns:
- the
SelectorProviderthat will be used by the createdNIOTransport. If not explicitly set, thenSelectorProvider.provider()will be used.
-
setSelectorProvider
Set theSelectorProviderto be used by the createdNIOTransport.- Parameters:
selectorProvider- theSelectorProvider.- Returns:
- this
NIOTransportBuilder
-
getName
- Returns:
- the Transport name
- See Also:
-
setName
- Parameters:
name- theTransportname- Returns:
- this
NIOTransportBuilder - See Also:
-
getProcessor
- Returns:
- the default
Processorif aConnectiondoes not specify a preference - See Also:
-
setProcessor
- Parameters:
processor- the defaultProcessorif aConnectiondoes not specify a preference- Returns:
- this
NIOTransportBuilder - See Also:
-
getProcessorSelector
- Returns:
- the default
ProcessorSelector - See Also:
-
setProcessorSelector
- Parameters:
processorSelector- the defaultProcessorSelector- Returns:
- this
NIOTransportBuilder - See Also:
-
getReadBufferSize
public int getReadBufferSize()- Returns:
- the default buffer size
- See Also:
-
setReadBufferSize
- Parameters:
readBufferSize- the new buffer size- Returns:
- this
NIOTransportBuilder - See Also:
-
getWriteBufferSize
public int getWriteBufferSize()- Returns:
- the default buffer size
- See Also:
-
setWriteBufferSize
- Parameters:
writeBufferSize- the new write buffer size- Returns:
- this
NIOTransportBuilder - See Also:
-
getClientSocketSoTimeout
public int getClientSocketSoTimeout()- Returns:
- gets the timeout on socket blocking operations on the client
- See Also:
-
setClientSocketSoTimeout
Sets the timeout on socket blocking operations for the client- Parameters:
clientSocketSoTimeout- the specified timeout in milliseconds- Returns:
- this
NIOTransportBuilder - See Also:
-
getConnectionTimeout
public int getConnectionTimeout()- Returns:
- value of the connectio timeout in milliseconds
- See Also:
-
setConnectionTimeout
- Parameters:
connectionTimeout- the value of the connection timeout in milliseconds- Returns:
- this
NIOTransportBuilder - See Also:
-
getReadTimeout
-
setReadTimeout
Sets the value of the blocking read timeout- Parameters:
timeout- the new timeout valuetimeUnit- the unit of the new timeout value- Returns:
- this NioTransportBuilder
- See Also:
-
getWriteTimeout
- Parameters:
timeUnit- theTimeUnitto convert the result to- Returns:
- the value of the write timeout
- See Also:
-
setWriteTimeout
- Parameters:
timeout- the new write timeout valuetimeUnit- theTimeUnitof the timeout value- Returns:
- this NIOTransportBuilder
- See Also:
-
isReuseAddress
public boolean isReuseAddress()Whether address may be reused for multiple sockets- Returns:
- SO_REUSEADDR
- See Also:
-
setReuseAddress
Sets whether address may be reused for multiple sockets- Parameters:
reuseAddress- SO_REUSEADDR- Returns:
- this
TCPNIOTransportBuilder - See Also:
-
getMaxAsyncWriteQueueSizeInBytes
public int getMaxAsyncWriteQueueSizeInBytes()Max asynchronous write queue size in bytes- Returns:
- the value is per connection, not transport total.
- See Also:
-
setMaxAsyncWriteQueueSizeInBytes
- Parameters:
maxAsyncWriteQueueSizeInBytes- the value is per connection, not transport total.- Returns:
- this
TCPNIOTransportBuilder - See Also:
-
isOptimizedForMultiplexing
public boolean isOptimizedForMultiplexing()- Returns:
- true, if NIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.
- See Also:
-
setOptimizedForMultiplexing
- Parameters:
optimizedForMultiplexing- Configure NIOTransport to be optimized for connection multiplexing- Returns:
- this
TCPNIOTransportBuilder - See Also:
-
build
- Returns:
- an
NIOTransportbased on the builder's configuration.
-
getThis
- Returns:
- this NIOTransportBuilder
- See Also:
-
create
-