Package org.glassfish.grizzly
Class NIOTransportBuilder<T extends NIOTransportBuilder>
- java.lang.Object
-
- org.glassfish.grizzly.NIOTransportBuilder<T>
-
- Direct Known Subclasses:
TCPNIOTransportBuilder,UDPNIOTransportBuilder
public abstract class NIOTransportBuilder<T extends NIOTransportBuilder> extends Object
This builder is responsible for creatingNIOTransportimplementations as well as providing basic configuration forIOStrategiesand thread pools.- Since:
- 2.0
- See Also:
NIOTransport,IOStrategy,ThreadPoolConfig
-
-
Field Summary
Fields Modifier and Type Field Description protected AttributeBuilderattributeBuilderprotected intclientSocketSoTimeoutprotected intconnectionTimeoutprotected IOStrategyioStrategyprotected ThreadPoolConfigkernelConfigprotected intmaxPendingBytesPerConnectionprotected MemoryManagermemoryManagerprotected Stringnameprotected NIOChannelDistributornioChannelDistributorprotected booleanoptimizedForMultiplexingprotected Processorprocessorprotected ProcessorSelectorprocessorSelectorprotected intreadBufferSizeprotected longreadTimeoutprotected booleanreuseAddressprotected SelectionKeyHandlerselectionKeyHandlerprotected SelectorHandlerselectorHandlerprotected SelectorProviderselectorProviderprotected intselectorRunnerCountprotected Class<? extends NIOTransport>transportClassprotected ThreadPoolConfigworkerConfigprotected intwriteBufferSizeprotected longwriteTimeout
-
Constructor Summary
Constructors Modifier Constructor Description protectedNIOTransportBuilder(Class<? extends NIOTransport> transportClass)
-
Method Summary
-
-
-
Field Detail
-
transportClass
protected final Class<? extends NIOTransport> transportClass
-
workerConfig
protected ThreadPoolConfig workerConfig
-
kernelConfig
protected ThreadPoolConfig kernelConfig
-
selectorProvider
protected SelectorProvider selectorProvider
-
selectorHandler
protected SelectorHandler selectorHandler
-
selectionKeyHandler
protected SelectionKeyHandler selectionKeyHandler
-
memoryManager
protected MemoryManager memoryManager
-
attributeBuilder
protected AttributeBuilder attributeBuilder
-
ioStrategy
protected IOStrategy ioStrategy
-
selectorRunnerCount
protected int selectorRunnerCount
-
nioChannelDistributor
protected NIOChannelDistributor nioChannelDistributor
-
name
protected String name
-
processor
protected Processor processor
-
processorSelector
protected ProcessorSelector 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 Detail
-
NIOTransportBuilder
protected NIOTransportBuilder(Class<? extends NIOTransport> transportClass)
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 Detail
-
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
public T setSelectorRunnersCount(int selectorRunnersCount)
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
public ThreadPoolConfig getWorkerThreadPoolConfig()
- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threads. This method will returnnullif aThreadPoolConfighad not been previously set.
-
setWorkerThreadPoolConfig
public T setWorkerThreadPoolConfig(ThreadPoolConfig workerConfig)
Sets theThreadPoolConfigthat will be used to construct theExecutorServiceforIOStrategiesthat require worker threads- Parameters:
workerConfig- the config- Returns:
- this builder
-
getSelectorThreadPoolConfig
public ThreadPoolConfig getSelectorThreadPoolConfig()
- Returns:
- the
ThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theNIOTransport'sSelectorRunners.
-
setSelectorThreadPoolConfig
public T setSelectorThreadPoolConfig(ThreadPoolConfig kernelConfig)
Sets theThreadPoolConfigthat will be used to construct theExecutorServicewhich will run theNIOTransport'sSelectorRunners.- Parameters:
kernelConfig- the config- Returns:
- this builder
-
getIOStrategy
public IOStrategy getIOStrategy()
- Returns:
- the
IOStrategythat will be used by the createdNIOTransport.
-
setIOStrategy
public T setIOStrategy(IOStrategy ioStrategy)
Changes the
IOStrategythat will be used. Invoking this method may change the return value ofgetWorkerThreadPoolConfig()- Parameters:
ioStrategy- theIOStrategyto use.- Returns:
- this
NIOTransportBuilder
-
getMemoryManager
public MemoryManager getMemoryManager()
- Returns:
- the
MemoryManagerthat will be used by the createdNIOTransport. If not explicitly set, thenMemoryManager.DEFAULT_MEMORY_MANAGERwill be used.
-
setMemoryManager
public T setMemoryManager(MemoryManager memoryManager)
Set theMemoryManagerto be used by the createdNIOTransport.- Parameters:
memoryManager- theMemoryManager.- Returns:
- this
NIOTransportBuilder
-
getSelectorHandler
public SelectorHandler getSelectorHandler()
- Returns:
- the
SelectorHandlerthat will be used by the createdNIOTransport. If not explicitly set, thenSelectorHandler.DEFAULT_SELECTOR_HANDLERwill be used.
-
setSelectorHandler
public T setSelectorHandler(SelectorHandler selectorHandler)
Set theSelectorHandlerto be used by the createdNIOTransport.- Parameters:
selectorHandler- theSelectorHandler.- Returns:
- this
NIOTransportBuilder
-
getSelectionKeyHandler
public SelectionKeyHandler getSelectionKeyHandler()
- Returns:
- the
SelectionKeyHandlerthat will be used by the createdNIOTransport. If not explicitly set, thenSelectionKeyHandler.DEFAULT_SELECTION_KEY_HANDLERwill be used.
-
setSelectionKeyHandler
public T setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)
Set theSelectionKeyHandlerto be used by the createdNIOTransport.- Parameters:
selectionKeyHandler- theSelectionKeyHandler.- Returns:
- this
NIOTransportBuilder
-
getAttributeBuilder
public AttributeBuilder getAttributeBuilder()
- Returns:
- the
AttributeBuilderthat will be used by the createdNIOTransport. If not explicitly set, thenAttributeBuilder.DEFAULT_ATTRIBUTE_BUILDERwill be used.
-
setAttributeBuilder
public T setAttributeBuilder(AttributeBuilder attributeBuilder)
Set theAttributeBuilderto be used by the createdNIOTransport.- Parameters:
attributeBuilder- theAttributeBuilder.- Returns:
- this
NIOTransportBuilder
-
getNIOChannelDistributor
public NIOChannelDistributor getNIOChannelDistributor()
- Returns:
- the
NIOChannelDistributorthat will be used by the createdNIOTransport. If not explicitly set, thenAttributeBuilder.DEFAULT_ATTRIBUTE_BUILDERwill be used.
-
setNIOChannelDistributor
public T setNIOChannelDistributor(NIOChannelDistributor nioChannelDistributor)
Set theNIOChannelDistributorto be used by the createdNIOTransport.- Parameters:
nioChannelDistributor- theNIOChannelDistributor.- Returns:
- this
NIOTransportBuilder
-
getSelectorProvider
public SelectorProvider getSelectorProvider()
- Returns:
- the
SelectorProviderthat will be used by the createdNIOTransport. If not explicitly set, thenSelectorProvider.provider()will be used.
-
setSelectorProvider
public T setSelectorProvider(SelectorProvider selectorProvider)
Set theSelectorProviderto be used by the createdNIOTransport.- Parameters:
selectorProvider- theSelectorProvider.- Returns:
- this
NIOTransportBuilder
-
getName
public String getName()
- Returns:
- the Transport name
- See Also:
Transport.getName()
-
setName
public T setName(String name)
- Parameters:
name- theTransportname- Returns:
- this
NIOTransportBuilder - See Also:
Transport.setName(String)
-
getProcessor
public Processor getProcessor()
- Returns:
- the default
Processorif aConnectiondoes not specify a preference - See Also:
Transport.getProcessor()
-
setProcessor
public T setProcessor(Processor processor)
- Parameters:
processor- the defaultProcessorif aConnectiondoes not specify a preference- Returns:
- this
NIOTransportBuilder - See Also:
Transport.setProcessor(Processor)
-
getProcessorSelector
public ProcessorSelector getProcessorSelector()
- Returns:
- the default
ProcessorSelector - See Also:
Transport.getProcessorSelector()
-
setProcessorSelector
public T setProcessorSelector(ProcessorSelector processorSelector)
- Parameters:
processorSelector- the defaultProcessorSelector- Returns:
- this
NIOTransportBuilder - See Also:
Transport.setProcessorSelector(ProcessorSelector)
-
getReadBufferSize
public int getReadBufferSize()
- Returns:
- the default buffer size
- See Also:
Transport.getReadBufferSize()
-
setReadBufferSize
public T setReadBufferSize(int readBufferSize)
- Parameters:
readBufferSize- the new buffer size- Returns:
- this
NIOTransportBuilder - See Also:
Transport.setReadBufferSize(int)
-
getWriteBufferSize
public int getWriteBufferSize()
- Returns:
- the default buffer size
- See Also:
Transport.getWriteBufferSize()
-
setWriteBufferSize
public T setWriteBufferSize(int writeBufferSize)
- Parameters:
writeBufferSize- the new write buffer size- Returns:
- this
NIOTransportBuilder - See Also:
Transport.setWriteBufferSize(int)
-
getClientSocketSoTimeout
public int getClientSocketSoTimeout()
- Returns:
- gets the timeout on socket blocking operations on the client
- See Also:
Socket.getSoTimeout()
-
setClientSocketSoTimeout
public T setClientSocketSoTimeout(int clientSocketSoTimeout)
Sets the timeout on socket blocking operations for the client- Parameters:
clientSocketSoTimeout- the specified timeout in milliseconds- Returns:
- this
NIOTransportBuilder - See Also:
Socket.setSoTimeout(int)
-
getConnectionTimeout
public int getConnectionTimeout()
- Returns:
- value of the connectio timeout in milliseconds
- See Also:
URLConnection.getConnectTimeout()
-
setConnectionTimeout
public T setConnectionTimeout(int connectionTimeout)
- Parameters:
connectionTimeout- the value of the connection timeout in milliseconds- Returns:
- this
NIOTransportBuilder - See Also:
NIOTransport.setConnectionTimeout(int)
-
getReadTimeout
public long getReadTimeout(TimeUnit timeUnit)
- Parameters:
timeUnit- theTimeUnitto convert the result to- Returns:
- the blocking read timeout in the specified
TimeUnit - See Also:
Transport.getReadTimeout(java.util.concurrent.TimeUnit)
-
setReadTimeout
public T setReadTimeout(long timeout, TimeUnit timeUnit)
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:
Transport.setReadTimeout(long, java.util.concurrent.TimeUnit)
-
getWriteTimeout
public long getWriteTimeout(TimeUnit timeUnit)
- Parameters:
timeUnit- theTimeUnitto convert the result to- Returns:
- the value of the write timeout
- See Also:
Transport.getWriteTimeout(java.util.concurrent.TimeUnit)
-
setWriteTimeout
public T setWriteTimeout(long timeout, TimeUnit timeUnit)
- Parameters:
timeout- the new write timeout valuetimeUnit- theTimeUnitof the timeout value- Returns:
- this NIOTransportBuilder
- See Also:
Transport.setWriteTimeout(long, java.util.concurrent.TimeUnit)
-
isReuseAddress
public boolean isReuseAddress()
Whether address may be reused for multiple sockets- Returns:
- SO_REUSEADDR
- See Also:
- Socket man page
-
setReuseAddress
public T setReuseAddress(boolean reuseAddress)
Sets whether address may be reused for multiple sockets- Parameters:
reuseAddress- SO_REUSEADDR- Returns:
- this
TCPNIOTransportBuilder - See Also:
- Socket man page
-
getMaxAsyncWriteQueueSizeInBytes
public int getMaxAsyncWriteQueueSizeInBytes()
Max asynchronous write queue size in bytes- Returns:
- the value is per connection, not transport total.
- See Also:
AsyncQueueWriter.getMaxPendingBytesPerConnection()
-
setMaxAsyncWriteQueueSizeInBytes
public T setMaxAsyncWriteQueueSizeInBytes(int maxAsyncWriteQueueSizeInBytes)
- Parameters:
maxAsyncWriteQueueSizeInBytes- the value is per connection, not transport total.- Returns:
- this
TCPNIOTransportBuilder - See Also:
AsyncQueueWriter.setMaxPendingBytesPerConnection(int)
-
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:
NIOTransport.isOptimizedForMultiplexing()
-
setOptimizedForMultiplexing
public T setOptimizedForMultiplexing(boolean optimizedForMultiplexing)
- Parameters:
optimizedForMultiplexing- Configure NIOTransport to be optimized for connection multiplexing- Returns:
- this
TCPNIOTransportBuilder - See Also:
NIOTransport.setOptimizedForMultiplexing(boolean)
-
build
public NIOTransport build()
- Returns:
- an
NIOTransportbased on the builder's configuration.
-
getThis
protected abstract T getThis()
- Returns:
- this NIOTransportBuilder
- See Also:
- http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ205
-
create
protected abstract NIOTransport create(String name)
-
-