Top Description Fields Constructors Methods
org.glassfish.grizzly

public abstract Class NIOTransportBuilder<T extends NIOTransportBuilder>

extends Object
Class Inheritance
Known Direct Subclasses
org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder, org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder
Annotations
@SuppressWarnings:UnusedDeclaration
Imports
java.nio.channels.spi.SelectorProvider, java.util.concurrent.TimeUnit, org.glassfish.grizzly.asyncqueue.AsyncQueueWriter, org.glassfish.grizzly.attributes.AttributeBuilder, org.glassfish.grizzly.memory.MemoryManager, org.glassfish.grizzly.nio.NIOChannelDistributor, .NIOTransport, .SelectionKeyHandler, .SelectorHandler, org.glassfish.grizzly.strategies.WorkerThreadIOStrategy, org.glassfish.grizzly.threadpool.ThreadPoolConfig

This builder is responsible for creating NIOTransport implementations as well as providing basic configuration for IOStrategies and thread pools.
Since
2.0
See Also
NIOTransport, IOStrategy, ThreadPoolConfig

Field Summary

Modifier and TypeField and Description
protected AttributeBuilder
protected int
protected int
protected IOStrategy
protected ThreadPoolConfig
protected int
protected MemoryManager<E extends Buffer>
protected String
protected NIOChannelDistributor
protected boolean
protected Processor<E extends Context>
protected ProcessorSelector
protected int
protected long
protected boolean
protected boolean
protected SelectionKeyHandler
protected SelectorHandler
protected SelectorProvider
protected int
protected final Class<? extends NIOTransport>
protected ThreadPoolConfig
protected int
protected long

Constructor Summary

AccessConstructor and Description
protected
NIOTransportBuilder(final Class<? extends NIOTransport>
the class of the NIOTransport implementation to be used.
transportClass
)

Constructs a new NIOTransport using the given transportClass and IOStrategy.

Method Summary

Modifier and TypeMethod and Description
public NIOTransport
build()

Returns: an NIOTransport based on the builder's configuration.

protected abstract NIOTransport
create(String name)

public AttributeBuilder
getAttributeBuilder()

Returns: the AttributeBuilder that will be used by the created NIOTransport.

public int
getClientSocketSoTimeout()

Returns: gets the timeout on socket blocking operations on the client

public int
getConnectionTimeout()

Returns: value of the connectio timeout in milliseconds

public IOStrategy
getIOStrategy()

Returns: the IOStrategy that will be used by the created NIOTransport.

public int

Returns:

the value is per connection, not transport total.
getMaxAsyncWriteQueueSizeInBytes
()

Max asynchronous write queue size in bytes

public MemoryManager<E extends Buffer>
getMemoryManager()

Returns: the MemoryManager that will be used by the created NIOTransport.

public String
getName()

Returns: the Transport name

public NIOChannelDistributor
getNIOChannelDistributor()

Returns: the NIOChannelDistributor that will be used by the created NIOTransport.

public Processor<E extends Context>
getProcessor()

Returns: the default Processor if a Connection does not specify a preference

public ProcessorSelector
public int
getReadBufferSize()

Returns: the default buffer size

public long
getReadTimeout(final TimeUnit
the TimeUnit to convert the result to
timeUnit
)

Returns: the blocking read timeout in the specified TimeUnit

public SelectionKeyHandler
getSelectionKeyHandler()

Returns: the SelectionKeyHandler that will be used by the created NIOTransport.

public SelectorHandler
getSelectorHandler()

Returns: the SelectorHandler that will be used by the created NIOTransport.

public SelectorProvider
getSelectorProvider()

Returns: the SelectorProvider that will be used by the created NIOTransport.

public int
getSelectorRunnersCount()

Returns: the number of java.nio.channels.Selectors to be created to serve Transport connections.

public ThreadPoolConfig
protected abstract T
getThis()

Returns: this NIOTransportBuilder

public ThreadPoolConfig
getWorkerThreadPoolConfig()

Returns: the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService for IOStrategies that require worker threads.

public int
getWriteBufferSize()

Returns: the default buffer size

public long
getWriteTimeout(final TimeUnit
the TimeUnit to convert the result to
timeUnit
)

Returns: the value of the write timeout

public boolean
isOptimizedForMultiplexing()

Returns: true, if NIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

public boolean

Returns:

SO_REUSEADDR
isReuseAddress
()

Whether address may be reused for multiple sockets

public boolean

Returns:

SO_REUSEPORT
isReusePort
()

Whether both same address and same port may be reused for multiple sockets

public T

Returns:

this NIOTransportBuilder
setAttributeBuilder
(AttributeBuilder attributeBuilder)

Set the AttributeBuilder to be used by the created NIOTransport.

public T

Returns:

this NIOTransportBuilder
setClientSocketSoTimeout
(int
the specified timeout in milliseconds
clientSocketSoTimeout
)

Sets the timeout on socket blocking operations for the client

public T
setConnectionTimeout(int
the value of the connection timeout in milliseconds
connectionTimeout
)

Returns: this NIOTransportBuilder

public T

Returns:

this NIOTransportBuilder
setIOStrategy
(final IOStrategy
the IOStrategy to use.
ioStrategy
)

Changes the IOStrategy that will be used.

public T
setMaxAsyncWriteQueueSizeInBytes(final int
the value is per connection, not transport total.
maxAsyncWriteQueueSizeInBytes
)

Returns: this TCPNIOTransportBuilder

public T

Returns:

this NIOTransportBuilder
setMemoryManager
(final MemoryManager<E extends Buffer> memoryManager)

Set the MemoryManager to be used by the created NIOTransport.

public T
setName(String
the Transport name
name
)

Returns: this NIOTransportBuilder

public T

Returns:

this NIOTransportBuilder
setNIOChannelDistributor
(NIOChannelDistributor nioChannelDistributor)

Set the NIOChannelDistributor to be used by the created NIOTransport.

public T
setOptimizedForMultiplexing(final boolean
Configure NIOTransport to be optimized for connection multiplexing
optimizedForMultiplexing
)

Returns: this TCPNIOTransportBuilder

public T
setProcessor(Processor<E extends Context>
the default Processor if a Connection does not specify a preference
processor
)

Returns: this NIOTransportBuilder

public T
setProcessorSelector(ProcessorSelector
the default ProcessorSelector
processorSelector
)

Returns: this NIOTransportBuilder

public T
setReadBufferSize(int
the new buffer size
readBufferSize
)

Returns: this NIOTransportBuilder

public T

Returns:

this NioTransportBuilder
setReadTimeout
(final long
the new timeout value
timeout
,
final TimeUnit
the unit of the new timeout value
timeUnit
)

Sets the value of the blocking read timeout

public T

Returns:

this TCPNIOTransportBuilder
setReuseAddress
(boolean
SO_REUSEADDR
reuseAddress
)

Sets whether address may be reused for multiple sockets

public T

Returns:

this TCPNIOTransportBuilder
setReusePort
(boolean
SO_REUSEPORT
reusePort
)

Sets whether both same address and same port may be reused for multiple sockets

public T

Returns:

this NIOTransportBuilder
setSelectionKeyHandler
(final SelectionKeyHandler selectionKeyHandler)

Set the SelectionKeyHandler to be used by the created NIOTransport.

public T

Returns:

this NIOTransportBuilder
setSelectorHandler
(final SelectorHandler selectorHandler)

Set the SelectorHandler to be used by the created NIOTransport.

public T

Returns:

this NIOTransportBuilder
setSelectorProvider
(SelectorProvider selectorProvider)

Set the SelectorProvider to be used by the created NIOTransport.

public T

Returns:

the builder
setSelectorRunnersCount
(final int
number of channels
selectorRunnersCount
)

Sets the number of java.nio.channels.Selectors to be created to serve Transport connections.

public T

Returns:

this builder
setSelectorThreadPoolConfig
(final ThreadPoolConfig
the config
kernelConfig
)

Sets the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService which will run the NIOTransport's org.glassfish.grizzly.nio.SelectorRunners.

public T

Returns:

this builder
setWorkerThreadPoolConfig
(final ThreadPoolConfig
the config
workerConfig
)

Sets the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService for IOStrategies that require worker threads

public T
setWriteBufferSize(int
the new write buffer size
writeBufferSize
)

Returns: this NIOTransportBuilder

public T
setWriteTimeout(final long
the new write timeout value
timeout
,
final TimeUnit
the TimeUnit of the timeout value
timeUnit
)

Returns: this NIOTransportBuilder

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeBuilderback to summary
protected AttributeBuilder attributeBuilder
clientSocketSoTimeoutback to summary
protected int clientSocketSoTimeout
connectionTimeoutback to summary
protected int connectionTimeout
ioStrategyback to summary
protected IOStrategy ioStrategy
kernelConfigback to summary
protected ThreadPoolConfig kernelConfig
maxPendingBytesPerConnectionback to summary
protected int maxPendingBytesPerConnection
memoryManagerback to summary
protected MemoryManager<E extends Buffer> memoryManager
nameback to summary
protected String name
nioChannelDistributorback to summary
protected NIOChannelDistributor nioChannelDistributor
optimizedForMultiplexingback to summary
protected boolean optimizedForMultiplexing
processorback to summary
protected Processor<E extends Context> processor
processorSelectorback to summary
protected ProcessorSelector processorSelector
readBufferSizeback to summary
protected int readBufferSize
readTimeoutback to summary
protected long readTimeout
reuseAddressback to summary
protected boolean reuseAddress
reusePortback to summary
protected boolean reusePort
selectionKeyHandlerback to summary
protected SelectionKeyHandler selectionKeyHandler
selectorHandlerback to summary
protected SelectorHandler selectorHandler
selectorProviderback to summary
protected SelectorProvider selectorProvider
selectorRunnerCountback to summary
protected int selectorRunnerCount
transportClassback to summary
protected final Class<? extends NIOTransport> transportClass
workerConfigback to summary
protected ThreadPoolConfig workerConfig
writeBufferSizeback to summary
protected int writeBufferSize
writeTimeoutback to summary
protected long writeTimeout

Constructor Detail

NIOTransportBuilderback to summary
protected NIOTransportBuilder(final 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 IOStrategy#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:Class<? extends NIOTransport>

the class of the NIOTransport implementation to be used.

Method Detail

buildback to summary
public NIOTransport build()
Returns:NIOTransport

an NIOTransport based on the builder's configuration.

createback to summary
protected abstract NIOTransport create(String name)
getAttributeBuilderback to summary
public AttributeBuilder getAttributeBuilder()
Returns:AttributeBuilder

the AttributeBuilder that will be used by the created NIOTransport. If not explicitly set, then AttributeBuilder#DEFAULT_ATTRIBUTE_BUILDER will be used.

getClientSocketSoTimeoutback to summary
public int getClientSocketSoTimeout()
Returns:int

gets the timeout on socket blocking operations on the client

See Also
java.net.Socket#getSoTimeout()
getConnectionTimeoutback to summary
public int getConnectionTimeout()
Returns:int

value of the connectio timeout in milliseconds

See Also
java.net.URLConnection#getConnectTimeout()
getIOStrategyback to summary
public IOStrategy getIOStrategy()
Returns:IOStrategy

the IOStrategy that will be used by the created NIOTransport.

getMaxAsyncWriteQueueSizeInBytesback to summary
public int getMaxAsyncWriteQueueSizeInBytes()

Max asynchronous write queue size in bytes

Returns:int

the value is per connection, not transport total.

See Also
org.glassfish.grizzly.asyncqueue.AsyncQueueWriter#getMaxPendingBytesPerConnection()
getMemoryManagerback to summary
public MemoryManager<E extends Buffer> getMemoryManager()
Returns:MemoryManager<E extends Buffer>

the MemoryManager that will be used by the created NIOTransport. If not explicitly set, then MemoryManager#DEFAULT_MEMORY_MANAGER will be used.

getNameback to summary
public String getName()
Returns:String

the Transport name

See Also
Transport#getName()
getNIOChannelDistributorback to summary
public NIOChannelDistributor getNIOChannelDistributor()
Returns:NIOChannelDistributor

the NIOChannelDistributor that will be used by the created NIOTransport. If not explicitly set, then AttributeBuilder#DEFAULT_ATTRIBUTE_BUILDER will be used.

getProcessorback to summary
public Processor<E extends Context> getProcessor()
Returns:Processor<E extends Context>

the default Processor if a Connection does not specify a preference

See Also
Transport#getProcessor()
getProcessorSelectorback to summary
public ProcessorSelector getProcessorSelector()
Returns:ProcessorSelector

the default ProcessorSelector

See Also
Transport#getProcessorSelector()
getReadBufferSizeback to summary
public int getReadBufferSize()
Returns:int

the default buffer size

See Also
Transport#getReadBufferSize()
getReadTimeoutback to summary
public long getReadTimeout(final TimeUnit timeUnit)
Parameters
timeUnit:TimeUnit

the TimeUnit to convert the result to

Returns:long

the blocking read timeout in the specified TimeUnit

See Also
Transport#getReadTimeout(java.util.concurrent.TimeUnit)
getSelectionKeyHandlerback to summary
public SelectionKeyHandler getSelectionKeyHandler()
Returns:SelectionKeyHandler

the SelectionKeyHandler that will be used by the created NIOTransport. If not explicitly set, then SelectionKeyHandler#DEFAULT_SELECTION_KEY_HANDLER will be used.

getSelectorHandlerback to summary
public SelectorHandler getSelectorHandler()
Returns:SelectorHandler

the SelectorHandler that will be used by the created NIOTransport. If not explicitly set, then SelectorHandler#DEFAULT_SELECTOR_HANDLER will be used.

getSelectorProviderback to summary
public SelectorProvider getSelectorProvider()
Returns:SelectorProvider

the SelectorProvider that will be used by the created NIOTransport. If not explicitly set, then SelectorProvider#provider() will be used.

getSelectorRunnersCountback to summary
public int getSelectorRunnersCount()
Returns:int

the number of java.nio.channels.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()

getSelectorThreadPoolConfigback to summary
public ThreadPoolConfig getSelectorThreadPoolConfig()
Returns:ThreadPoolConfig

the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService which will run the NIOTransport's org.glassfish.grizzly.nio.SelectorRunners.

getThisback to summary
protected abstract T getThis()
Returns:T

this NIOTransportBuilder

See Also
http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ205
getWorkerThreadPoolConfigback to summary
public ThreadPoolConfig getWorkerThreadPoolConfig()
Returns:ThreadPoolConfig

the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService for IOStrategies that require worker threads. This method will return null if a ThreadPoolConfig had not been previously set.

getWriteBufferSizeback to summary
public int getWriteBufferSize()
Returns:int

the default buffer size

See Also
Transport#getWriteBufferSize()
getWriteTimeoutback to summary
public long getWriteTimeout(final TimeUnit timeUnit)
Parameters
timeUnit:TimeUnit

the TimeUnit to convert the result to

Returns:long

the value of the write timeout

See Also
Transport#getWriteTimeout(java.util.concurrent.TimeUnit)
isOptimizedForMultiplexingback to summary
public boolean isOptimizedForMultiplexing()
Returns:boolean

true, if NIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

See Also
org.glassfish.grizzly.nio.NIOTransport#isOptimizedForMultiplexing()
isReuseAddressback to summary
public boolean isReuseAddress()

Whether address may be reused for multiple sockets

Returns:boolean

SO_REUSEADDR

See Also
Socket man page
isReusePortback to summary
public boolean isReusePort()

Whether both same address and same port may be reused for multiple sockets

Returns:boolean

SO_REUSEPORT

See Also
Socket man page
setAttributeBuilderback to summary
public T setAttributeBuilder(AttributeBuilder attributeBuilder)

Set the AttributeBuilder to be used by the created NIOTransport.

Parameters
attributeBuilder:AttributeBuilder

the AttributeBuilder.

Returns:T

this NIOTransportBuilder

setClientSocketSoTimeoutback to summary
public T setClientSocketSoTimeout(int clientSocketSoTimeout)

Sets the timeout on socket blocking operations for the client

Parameters
clientSocketSoTimeout:int

the specified timeout in milliseconds

Returns:T

this NIOTransportBuilder

See Also
java.net.Socket#setSoTimeout(int)
setConnectionTimeoutback to summary
public T setConnectionTimeout(int connectionTimeout)
Parameters
connectionTimeout:int

the value of the connection timeout in milliseconds

Returns:T

this NIOTransportBuilder

See Also
NIOTransport#setConnectionTimeout(int)
setIOStrategyback to summary
public T setIOStrategy(final IOStrategy ioStrategy)

Changes the IOStrategy that will be used. Invoking this method may change the return value of getWorkerThreadPoolConfig()

Parameters
ioStrategy:IOStrategy

the IOStrategy to use.

Returns:T

this NIOTransportBuilder

setMaxAsyncWriteQueueSizeInBytesback to summary
public T setMaxAsyncWriteQueueSizeInBytes(final int maxAsyncWriteQueueSizeInBytes)
Parameters
maxAsyncWriteQueueSizeInBytes:int

the value is per connection, not transport total.

Returns:T

this TCPNIOTransportBuilder

See Also
org.glassfish.grizzly.asyncqueue.AsyncQueueWriter#setMaxPendingBytesPerConnection(int)
setMemoryManagerback to summary
public T setMemoryManager(final MemoryManager<E extends Buffer> memoryManager)

Set the MemoryManager to be used by the created NIOTransport.

Parameters
memoryManager:MemoryManager<E extends Buffer>

the MemoryManager.

Returns:T

this NIOTransportBuilder

setNameback to summary
public T setName(String name)
Parameters
name:String

the Transport name

Returns:T

this NIOTransportBuilder

See Also
Transport#setName(String)
setNIOChannelDistributorback to summary
public T setNIOChannelDistributor(NIOChannelDistributor nioChannelDistributor)

Set the NIOChannelDistributor to be used by the created NIOTransport.

Parameters
nioChannelDistributor:NIOChannelDistributor

the NIOChannelDistributor.

Returns:T

this NIOTransportBuilder

setOptimizedForMultiplexingback to summary
public T setOptimizedForMultiplexing(final boolean optimizedForMultiplexing)
Parameters
optimizedForMultiplexing:boolean

Configure NIOTransport to be optimized for connection multiplexing

Returns:T

this TCPNIOTransportBuilder

See Also
org.glassfish.grizzly.nio.NIOTransport#setOptimizedForMultiplexing(boolean)
setProcessorback to summary
public T setProcessor(Processor<E extends Context> processor)
Parameters
processor:Processor<E extends Context>

the default Processor if a Connection does not specify a preference

Returns:T

this NIOTransportBuilder

See Also
Transport#setProcessor(Processor)
setProcessorSelectorback to summary
public T setProcessorSelector(ProcessorSelector processorSelector)
Parameters
processorSelector:ProcessorSelector

the default ProcessorSelector

Returns:T

this NIOTransportBuilder

See Also
Transport#setProcessorSelector(ProcessorSelector)
setReadBufferSizeback to summary
public T setReadBufferSize(int readBufferSize)
Parameters
readBufferSize:int

the new buffer size

Returns:T

this NIOTransportBuilder

See Also
Transport#setReadBufferSize(int)
setReadTimeoutback to summary
public T setReadTimeout(final long timeout, final TimeUnit timeUnit)

Sets the value of the blocking read timeout

Parameters
timeout:long

the new timeout value

timeUnit:TimeUnit

the unit of the new timeout value

Returns:T

this NioTransportBuilder

See Also
Transport#setReadTimeout(long, java.util.concurrent.TimeUnit)
setReuseAddressback to summary
public T setReuseAddress(boolean reuseAddress)

Sets whether address may be reused for multiple sockets

Parameters
reuseAddress:boolean

SO_REUSEADDR

Returns:T

this TCPNIOTransportBuilder

See Also
Socket man page
setReusePortback to summary
public T setReusePort(boolean reusePort)

Sets whether both same address and same port may be reused for multiple sockets

Parameters
reusePort:boolean

SO_REUSEPORT

Returns:T

this TCPNIOTransportBuilder

See Also
Socket man page
setSelectionKeyHandlerback to summary
public T setSelectionKeyHandler(final SelectionKeyHandler selectionKeyHandler)

Set the SelectionKeyHandler to be used by the created NIOTransport.

Parameters
selectionKeyHandler:SelectionKeyHandler

the SelectionKeyHandler.

Returns:T

this NIOTransportBuilder

setSelectorHandlerback to summary
public T setSelectorHandler(final SelectorHandler selectorHandler)

Set the SelectorHandler to be used by the created NIOTransport.

Parameters
selectorHandler:SelectorHandler

the SelectorHandler.

Returns:T

this NIOTransportBuilder

setSelectorProviderback to summary
public T setSelectorProvider(SelectorProvider selectorProvider)

Set the SelectorProvider to be used by the created NIOTransport.

Parameters
selectorProvider:SelectorProvider

the SelectorProvider.

Returns:T

this NIOTransportBuilder

setSelectorRunnersCountback to summary
public T setSelectorRunnersCount(final int selectorRunnersCount)

Sets the number of java.nio.channels.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().

Parameters
selectorRunnersCount:int

number of channels

Returns:T

the builder

setSelectorThreadPoolConfigback to summary
public T setSelectorThreadPoolConfig(final ThreadPoolConfig kernelConfig)

Sets the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService which will run the NIOTransport's org.glassfish.grizzly.nio.SelectorRunners.

Parameters
kernelConfig:ThreadPoolConfig

the config

Returns:T

this builder

setWorkerThreadPoolConfigback to summary
public T setWorkerThreadPoolConfig(final ThreadPoolConfig workerConfig)

Sets the ThreadPoolConfig that will be used to construct the java.util.concurrent.ExecutorService for IOStrategies that require worker threads

Parameters
workerConfig:ThreadPoolConfig

the config

Returns:T

this builder

setWriteBufferSizeback to summary
public T setWriteBufferSize(int writeBufferSize)
Parameters
writeBufferSize:int

the new write buffer size

Returns:T

this NIOTransportBuilder

See Also
Transport#setWriteBufferSize(int)
setWriteTimeoutback to summary
public T setWriteTimeout(final long timeout, final TimeUnit timeUnit)
Parameters
timeout:long

the new write timeout value

timeUnit:TimeUnit

the TimeUnit of the timeout value

Returns:T

this NIOTransportBuilder

See Also
Transport#setWriteTimeout(long, java.util.concurrent.TimeUnit)