public abstract class NIOTransportBuilder<T extends NIOTransportBuilder> extends Object
NIOTransport
implementations
as well as providing basic configuration for IOStrategies
and
thread pools.NIOTransport
,
IOStrategy
,
ThreadPoolConfig
Modifier and Type | Field and Description |
---|---|
protected AttributeBuilder |
attributeBuilder |
protected int |
clientSocketSoTimeout |
protected int |
connectionTimeout |
protected IOStrategy |
ioStrategy |
protected ThreadPoolConfig |
kernelConfig |
protected int |
maxPendingBytesPerConnection |
protected MemoryManager |
memoryManager |
protected String |
name |
protected NIOChannelDistributor |
nioChannelDistributor |
protected boolean |
optimizedForMultiplexing |
protected Processor |
processor |
protected ProcessorSelector |
processorSelector |
protected int |
readBufferSize |
protected long |
readTimeout |
protected boolean |
reuseAddress |
protected SelectionKeyHandler |
selectionKeyHandler |
protected SelectorHandler |
selectorHandler |
protected SelectorProvider |
selectorProvider |
protected int |
selectorRunnerCount |
protected Class<? extends NIOTransport> |
transportClass |
protected ThreadPoolConfig |
workerConfig |
protected int |
writeBufferSize |
protected long |
writeTimeout |
Modifier | Constructor and Description |
---|---|
protected |
NIOTransportBuilder(Class<? extends NIOTransport> transportClass)
|
protected Class<? extends NIOTransport> transportClass
protected ThreadPoolConfig workerConfig
protected ThreadPoolConfig kernelConfig
protected SelectorProvider selectorProvider
protected SelectorHandler selectorHandler
protected SelectionKeyHandler selectionKeyHandler
protected MemoryManager memoryManager
protected AttributeBuilder attributeBuilder
protected IOStrategy ioStrategy
protected int selectorRunnerCount
protected NIOChannelDistributor nioChannelDistributor
protected String name
protected Processor processor
protected ProcessorSelector processorSelector
protected int readBufferSize
protected int writeBufferSize
protected int clientSocketSoTimeout
protected int connectionTimeout
protected boolean reuseAddress
protected int maxPendingBytesPerConnection
protected boolean optimizedForMultiplexing
protected long readTimeout
protected long writeTimeout
protected NIOTransportBuilder(Class<? extends NIOTransport> transportClass)
Constructs a new NIOTransport
using the given
transportClass
and IOStrategy
.
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.
transportClass
- the class of the NIOTransport
implementation to be used.public int getSelectorRunnersCount()
Selector
s 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 cores
Runtime.availableProcessors()
public T setSelectorRunnersCount(int selectorRunnersCount)
Selector
s 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 cores
Runtime.availableProcessors()
.selectorRunnersCount
- public ThreadPoolConfig getWorkerThreadPoolConfig()
ThreadPoolConfig
that will be used to construct the
ExecutorService
for IOStrategies
that require worker threads. This method will return null
if a ThreadPoolConfig
had not been previously set.public T setWorkerThreadPoolConfig(ThreadPoolConfig workerConfig)
ThreadPoolConfig
that will be used to construct the
ExecutorService
for IOStrategies
that require worker threadspublic ThreadPoolConfig getSelectorThreadPoolConfig()
ThreadPoolConfig
that will be used to construct the
ExecutorService
which will run the NIOTransport
's
SelectorRunner
s.public T setSelectorThreadPoolConfig(ThreadPoolConfig kernelConfig)
ThreadPoolConfig
that will be used to construct the
ExecutorService
which will run the NIOTransport
's
SelectorRunner
s.public IOStrategy getIOStrategy()
IOStrategy
that will be used by the created NIOTransport
.public T setIOStrategy(IOStrategy ioStrategy)
Changes the IOStrategy
that will be used. Invoking this method
may change the return value of getWorkerThreadPoolConfig()
ioStrategy
- the IOStrategy
to use.NIOTransportBuilder
public MemoryManager getMemoryManager()
MemoryManager
that will be used by the created NIOTransport
.
If not explicitly set, then MemoryManager.DEFAULT_MEMORY_MANAGER
will be used.public T setMemoryManager(MemoryManager memoryManager)
MemoryManager
to be used by the created NIOTransport
.memoryManager
- the MemoryManager
.NIOTransportBuilder
public SelectorHandler getSelectorHandler()
SelectorHandler
that will be used by the created NIOTransport
.
If not explicitly set, then SelectorHandler.DEFAULT_SELECTOR_HANDLER
will be used.public T setSelectorHandler(SelectorHandler selectorHandler)
SelectorHandler
to be used by the created NIOTransport
.selectorHandler
- the SelectorHandler
.NIOTransportBuilder
public SelectionKeyHandler getSelectionKeyHandler()
SelectionKeyHandler
that will be used by the created NIOTransport
.
If not explicitly set, then SelectionKeyHandler.DEFAULT_SELECTION_KEY_HANDLER
will be used.public T setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)
SelectionKeyHandler
to be used by the created NIOTransport
.selectionKeyHandler
- the SelectionKeyHandler
.NIOTransportBuilder
public AttributeBuilder getAttributeBuilder()
AttributeBuilder
that will be used by the created NIOTransport
.
If not explicitly set, then AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER
will be used.public T setAttributeBuilder(AttributeBuilder attributeBuilder)
AttributeBuilder
to be used by the created NIOTransport
.attributeBuilder
- the AttributeBuilder
.NIOTransportBuilder
public NIOChannelDistributor getNIOChannelDistributor()
NIOChannelDistributor
that will be used by the created NIOTransport
.
If not explicitly set, then AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER
will be used.public T setNIOChannelDistributor(NIOChannelDistributor nioChannelDistributor)
NIOChannelDistributor
to be used by the created NIOTransport
.nioChannelDistributor
- the NIOChannelDistributor
.NIOTransportBuilder
public SelectorProvider getSelectorProvider()
SelectorProvider
that will be used by the created NIOTransport
.
If not explicitly set, then SelectorProvider.provider()
will be used.public T setSelectorProvider(SelectorProvider selectorProvider)
SelectorProvider
to be used by the created NIOTransport
.selectorProvider
- the SelectorProvider
.NIOTransportBuilder
public String getName()
Transport.getName()
public T setName(String name)
NIOTransportBuilder
Transport.setName(String)
public Processor getProcessor()
Transport.getProcessor()
public T setProcessor(Processor processor)
NIOTransportBuilder
Transport.setProcessor(Processor)
public ProcessorSelector getProcessorSelector()
()
public T setProcessorSelector(ProcessorSelector processorSelector)
NIOTransportBuilder
Transport.setProcessorSelector(ProcessorSelector)
public int getReadBufferSize()
()
public T setReadBufferSize(int readBufferSize)
NIOTransportBuilder
Transport.setReadBufferSize(int)
public int getWriteBufferSize()
Transport.getWriteBufferSize()
public T setWriteBufferSize(int writeBufferSize)
NIOTransportBuilder
Transport.setWriteBufferSize(int)
public int getClientSocketSoTimeout()
public T setClientSocketSoTimeout(int clientSocketSoTimeout)
NIOTransportBuilder
NIOTransport.setClientSocketSoTimeout(int)
public int getConnectionTimeout()
NIOTransport.getConnectionTimeout()
public T setConnectionTimeout(int connectionTimeout)
NIOTransportBuilder
NIOTransport.setConnectionTimeout(int)
public long getReadTimeout(TimeUnit timeUnit)
public long getWriteTimeout(TimeUnit timeUnit)
public boolean isReuseAddress()
NIOTransport.isReuseAddress()
public T setReuseAddress(boolean reuseAddress)
TCPNIOTransportBuilder
NIOTransport.setReuseAddress(boolean)
public int getMaxAsyncWriteQueueSizeInBytes()
public T setMaxAsyncWriteQueueSizeInBytes(int maxAsyncWriteQueueSizeInBytes)
TCPNIOTransportBuilder
Note: the value is per connection, not transport total.
public boolean isOptimizedForMultiplexing()
public T setOptimizedForMultiplexing(boolean optimizedForMultiplexing)
TCPNIOTransportBuilder
NIOTransport.setOptimizedForMultiplexing(boolean)
public NIOTransport build()
NIOTransport
based on the builder's configuration.protected abstract T getThis()
protected abstract NIOTransport create(String name)
Copyright © 2014 Oracle Corporation. All Rights Reserved.