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 final 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()
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 cores
Runtime.availableProcessors()public T setSelectorRunnersCount(int selectorRunnersCount)
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 cores
Runtime.availableProcessors().selectorRunnersCount - number of channelspublic 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 threadsworkerConfig - the configpublic ThreadPoolConfig getSelectorThreadPoolConfig()
ThreadPoolConfig that will be used to construct the ExecutorService
which will run the NIOTransport's SelectorRunners.public T setSelectorThreadPoolConfig(ThreadPoolConfig kernelConfig)
ThreadPoolConfig that will be used to construct the ExecutorService
which will run the NIOTransport's SelectorRunners.kernelConfig - the configpublic 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.NIOTransportBuilderpublic 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.NIOTransportBuilderpublic 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.NIOTransportBuilderpublic 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.NIOTransportBuilderpublic 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.NIOTransportBuilderpublic 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.NIOTransportBuilderpublic 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.NIOTransportBuilderpublic String getName()
Transport.getName()public T setName(String name)
name - the Transport nameNIOTransportBuilderTransport.setName(String)public Processor getProcessor()
Processor if a Connection does not specify a preferenceTransport.getProcessor()public T setProcessor(Processor processor)
processor - the default Processor if a Connection does not specify a preferenceNIOTransportBuilderTransport.setProcessor(Processor)public ProcessorSelector getProcessorSelector()
ProcessorSelectorTransport.getProcessorSelector()public T setProcessorSelector(ProcessorSelector processorSelector)
processorSelector - the default ProcessorSelectorNIOTransportBuilderTransport.setProcessorSelector(ProcessorSelector)public int getReadBufferSize()
Transport.getReadBufferSize()public T setReadBufferSize(int readBufferSize)
readBufferSize - the new buffer sizeNIOTransportBuilderTransport.setReadBufferSize(int)public int getWriteBufferSize()
Transport.getWriteBufferSize()public T setWriteBufferSize(int writeBufferSize)
writeBufferSize - the new write buffer sizeNIOTransportBuilderTransport.setWriteBufferSize(int)public int getClientSocketSoTimeout()
Socket.getSoTimeout()public T setClientSocketSoTimeout(int clientSocketSoTimeout)
clientSocketSoTimeout - the specified timeout in millisecondsNIOTransportBuilderSocket.setSoTimeout(int)public int getConnectionTimeout()
URLConnection.getConnectTimeout()public T setConnectionTimeout(int connectionTimeout)
connectionTimeout - the value of the connection timeout in millisecondsNIOTransportBuilderNIOTransport.setConnectionTimeout(int)public long getReadTimeout(TimeUnit timeUnit)
timeUnit - the TimeUnit to convert the result toTimeUnitTransport.getReadTimeout(java.util.concurrent.TimeUnit)public T setReadTimeout(long timeout, TimeUnit timeUnit)
timeout - the new timeout valuetimeUnit - the unit of the new timeout valueTransport.setReadTimeout(long, java.util.concurrent.TimeUnit)public long getWriteTimeout(TimeUnit timeUnit)
timeUnit - the TimeUnit to convert the result toTransport.getWriteTimeout(java.util.concurrent.TimeUnit)public T setWriteTimeout(long timeout, TimeUnit timeUnit)
timeout - the new write timeout valuetimeUnit - the TimeUnit of the timeout valueTransport.setWriteTimeout(long, java.util.concurrent.TimeUnit)public boolean isReuseAddress()
public T setReuseAddress(boolean reuseAddress)
reuseAddress - SO_REUSEADDRTCPNIOTransportBuilderpublic int getMaxAsyncWriteQueueSizeInBytes()
AsyncQueueWriter.getMaxPendingBytesPerConnection()public T setMaxAsyncWriteQueueSizeInBytes(int maxAsyncWriteQueueSizeInBytes)
maxAsyncWriteQueueSizeInBytes - the value is per connection, not transport total.TCPNIOTransportBuilderAsyncQueueWriter.setMaxPendingBytesPerConnection(int)public boolean isOptimizedForMultiplexing()
NIOTransport.isOptimizedForMultiplexing()public T setOptimizedForMultiplexing(boolean optimizedForMultiplexing)
optimizedForMultiplexing - Configure NIOTransport to be optimized for connection multiplexingTCPNIOTransportBuilderNIOTransport.setOptimizedForMultiplexing(boolean)public NIOTransport build()
NIOTransport based on the builder's configuration.protected abstract T getThis()
protected abstract NIOTransport create(String name)
Copyright © 2017–2020 Oracle Corporation. All rights reserved.