public interface ChannelConfig
Channel
.
Please down-cast to more specific configuration type such as
SocketChannelConfig
or use setOptions(Map)
to set the
transport-specific properties:
Channel
ch = ...;SocketChannelConfig
cfg = (SocketChannelConfig
) ch.getConfig(); cfg.setTcpNoDelay(false);
Channel
without down-casting its associated
ChannelConfig
. To update an option map, please call setOptions(Map)
.
All ChannelConfig
has the following options:
More options are available in the sub-types of ChannelConfig
. For
example, you can configure the parameters which are specific to a TCP/IP
socket as explained in SocketChannelConfig
.
限定符和类型 | 方法和说明 |
---|---|
ByteBufAllocator |
getAllocator()
Returns
ByteBufAllocator which is used for the channel
to allocate buffers. |
int |
getConnectTimeoutMillis()
Returns the connect timeout of the channel in milliseconds.
|
int |
getMaxMessagesPerRead()
Returns the maximum number of messages to read per read loop.
|
MessageSizeEstimator |
getMessageSizeEstimator()
Returns
MessageSizeEstimator which is used for the channel
to detect the size of a message. |
<T> T |
getOption(ChannelOption<T> option)
Return the value of the given
ChannelOption |
java.util.Map<ChannelOption<?>,java.lang.Object> |
getOptions()
Return all set
ChannelOption 's. |
RecvByteBufAllocator |
getRecvByteBufAllocator()
Returns
RecvByteBufAllocator which is used for the channel
to allocate receive buffers. |
int |
getWriteBufferHighWaterMark()
Returns the high water mark of the write buffer.
|
int |
getWriteBufferLowWaterMark()
Returns the low water mark of the write buffer.
|
int |
getWriteSpinCount()
Returns the maximum loop count for a write operation until
WritableByteChannel.write(ByteBuffer) returns a non-zero value. |
boolean |
isAutoClose()
已过时。
Auto close will be removed in a future release.
Returns
true if and only if the Channel will be closed automatically and immediately on
write failure. The default is false . |
boolean |
isAutoRead()
Returns
true if and only if ChannelHandlerContext.read() will be invoked automatically so that
a user application doesn't need to call it at all. |
ChannelConfig |
setAllocator(ByteBufAllocator allocator)
Set the
ByteBufAllocator which is used for the channel
to allocate buffers. |
ChannelConfig |
setAutoClose(boolean autoClose)
已过时。
Auto close will be removed in a future release.
Sets whether the
Channel should be closed automatically and immediately on write failure.
The default is false . |
ChannelConfig |
setAutoRead(boolean autoRead)
Sets if
ChannelHandlerContext.read() will be invoked automatically so that a user application doesn't
need to call it at all. |
ChannelConfig |
setConnectTimeoutMillis(int connectTimeoutMillis)
Sets the connect timeout of the channel in milliseconds.
|
ChannelConfig |
setMaxMessagesPerRead(int maxMessagesPerRead)
Sets the maximum number of messages to read per read loop.
|
ChannelConfig |
setMessageSizeEstimator(MessageSizeEstimator estimator)
Set the
MessageSizeEstimator which is used for the channel
to detect the size of a message. |
<T> boolean |
setOption(ChannelOption<T> option,
T value)
Sets a configuration property with the specified name and value.
|
boolean |
setOptions(java.util.Map<ChannelOption<?>,?> options)
Sets the configuration properties from the specified
Map . |
ChannelConfig |
setRecvByteBufAllocator(RecvByteBufAllocator allocator)
Set the
ByteBufAllocator which is used for the channel
to allocate receive buffers. |
ChannelConfig |
setWriteBufferHighWaterMark(int writeBufferHighWaterMark)
Sets the high water mark of the write buffer.
|
ChannelConfig |
setWriteBufferLowWaterMark(int writeBufferLowWaterMark)
Sets the low water mark of the write buffer.
|
ChannelConfig |
setWriteSpinCount(int writeSpinCount)
Sets the maximum loop count for a write operation until
WritableByteChannel.write(ByteBuffer) returns a non-zero value. |
java.util.Map<ChannelOption<?>,java.lang.Object> getOptions()
ChannelOption
's.boolean setOptions(java.util.Map<ChannelOption<?>,?> options)
Map
.<T> T getOption(ChannelOption<T> option)
ChannelOption
<T> boolean setOption(ChannelOption<T> option, T value)
public boolean setOption(ChannelOption<T> option, T value) { if (super.setOption(option, value)) { return true; } if (option.equals(additionalOption)) { .... return true; } return false; }
true
if and only if the property has been setint getConnectTimeoutMillis()
Channel
does not support connect operation, this property is not
used at all, and therefore will be ignored.0
if disabled.ChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis)
Channel
does not support connect operation, this property is not
used at all, and therefore will be ignored.connectTimeoutMillis
- the connect timeout in milliseconds.
0
to disable.int getMaxMessagesPerRead()
channelRead()
event.
If this value is greater than 1, an event loop might attempt to read multiple times to procure multiple messages.ChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead)
int getWriteSpinCount()
WritableByteChannel.write(ByteBuffer)
returns a non-zero value.
It is similar to what a spin lock is used for in concurrency programming.
It improves memory utilization and write throughput depending on
the platform that JVM runs on. The default value is 16
.ChannelConfig setWriteSpinCount(int writeSpinCount)
WritableByteChannel.write(ByteBuffer)
returns a non-zero value.
It is similar to what a spin lock is used for in concurrency programming.
It improves memory utilization and write throughput depending on
the platform that JVM runs on. The default value is 16
.java.lang.IllegalArgumentException
- if the specified value is 0
or less than 0
ByteBufAllocator getAllocator()
ByteBufAllocator
which is used for the channel
to allocate buffers.ChannelConfig setAllocator(ByteBufAllocator allocator)
ByteBufAllocator
which is used for the channel
to allocate buffers.RecvByteBufAllocator getRecvByteBufAllocator()
RecvByteBufAllocator
which is used for the channel
to allocate receive buffers.ChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator)
ByteBufAllocator
which is used for the channel
to allocate receive buffers.boolean isAutoRead()
true
if and only if ChannelHandlerContext.read()
will be invoked automatically so that
a user application doesn't need to call it at all. The default value is true
.ChannelConfig setAutoRead(boolean autoRead)
ChannelHandlerContext.read()
will be invoked automatically so that a user application doesn't
need to call it at all. The default value is true
.@Deprecated boolean isAutoClose()
true
if and only if the Channel
will be closed automatically and immediately on
write failure. The default is false
.@Deprecated ChannelConfig setAutoClose(boolean autoClose)
Channel
should be closed automatically and immediately on write failure.
The default is false
.int getWriteBufferHighWaterMark()
Channel.isWritable()
will start to return false
.ChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark)
Channel.isWritable()
will start to return false
.int getWriteBufferLowWaterMark()
Channel.isWritable()
will start to return
true
again.ChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark)
Channel.isWritable()
will start to return
true
again.MessageSizeEstimator getMessageSizeEstimator()
MessageSizeEstimator
which is used for the channel
to detect the size of a message.ChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator)
MessageSizeEstimator
which is used for the channel
to detect the size of a message.