Package io.netty.channel
Class DefaultChannelConfig
- java.lang.Object
-
- io.netty.channel.DefaultChannelConfig
-
- All Implemented Interfaces:
ChannelConfig
- Direct Known Subclasses:
DefaultDatagramChannelConfig
,DefaultSctpChannelConfig
,DefaultSctpServerChannelConfig
,DefaultServerSocketChannelConfig
,DefaultSocketChannelConfig
,DefaultUdtChannelConfig
,EpollChannelConfig
,KQueueChannelConfig
public class DefaultChannelConfig extends java.lang.Object implements ChannelConfig
The defaultChannelConfig
implementation.
-
-
Constructor Summary
Constructors Modifier Constructor Description DefaultChannelConfig(Channel channel)
protected
DefaultChannelConfig(Channel channel, RecvByteBufAllocator allocator)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
autoReadCleared()
ByteBufAllocator
getAllocator()
ReturnsByteBufAllocator
which is used for the channel to allocate buffers.int
getConnectTimeoutMillis()
Returns the connect timeout of the channel in milliseconds.int
getMaxMessagesPerRead()
Deprecated.int
getMaxMessagesPerWrite()
Get the maximum number of message to write per eventloop run.MessageSizeEstimator
getMessageSizeEstimator()
ReturnsMessageSizeEstimator
which is used for the channel to detect the size of a message.<T> T
getOption(ChannelOption<T> option)
Return the value of the givenChannelOption
java.util.Map<ChannelOption<?>,java.lang.Object>
getOptions()
Return all setChannelOption
's.protected java.util.Map<ChannelOption<?>,java.lang.Object>
getOptions(java.util.Map<ChannelOption<?>,java.lang.Object> result, ChannelOption<?>... options)
<T extends RecvByteBufAllocator>
TgetRecvByteBufAllocator()
ReturnsRecvByteBufAllocator
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.WriteBufferWaterMark
getWriteBufferWaterMark()
Returns theWriteBufferWaterMark
which is used for setting the high and low water mark of the write buffer.int
getWriteSpinCount()
Returns the maximum loop count for a write operation untilWritableByteChannel.write(ByteBuffer)
returns a non-zero value.boolean
isAutoClose()
Returnstrue
if and only if theChannel
will be closed automatically and immediately on write failure.boolean
isAutoRead()
Returnstrue
if and only ifChannelHandlerContext.read()
will be invoked automatically so that a user application doesn't need to call it at all.ChannelConfig
setAllocator(ByteBufAllocator allocator)
Set theByteBufAllocator
which is used for the channel to allocate buffers.ChannelConfig
setAutoClose(boolean autoClose)
Sets whether theChannel
should be closed automatically and immediately on write failure.ChannelConfig
setAutoRead(boolean autoRead)
Sets ifChannelHandlerContext.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)
Deprecated.ChannelConfig
setMaxMessagesPerWrite(int maxMessagesPerWrite)
Set the maximum number of message to write per eventloop run.ChannelConfig
setMessageSizeEstimator(MessageSizeEstimator estimator)
Set theMessageSizeEstimator
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 specifiedMap
.ChannelConfig
setRecvByteBufAllocator(RecvByteBufAllocator allocator)
Set theRecvByteBufAllocator
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
setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark)
Set theWriteBufferWaterMark
which is used for setting the high and low water mark of the write buffer.ChannelConfig
setWriteSpinCount(int writeSpinCount)
Sets the maximum loop count for a write operation untilWritableByteChannel.write(ByteBuffer)
returns a non-zero value.protected <T> void
validate(ChannelOption<T> option, T value)
-
-
-
Field Detail
-
channel
protected final Channel channel
-
-
Constructor Detail
-
DefaultChannelConfig
public DefaultChannelConfig(Channel channel)
-
DefaultChannelConfig
protected DefaultChannelConfig(Channel channel, RecvByteBufAllocator allocator)
-
-
Method Detail
-
getOptions
public java.util.Map<ChannelOption<?>,java.lang.Object> getOptions()
Description copied from interface:ChannelConfig
Return all setChannelOption
's.- Specified by:
getOptions
in interfaceChannelConfig
-
getOptions
protected java.util.Map<ChannelOption<?>,java.lang.Object> getOptions(java.util.Map<ChannelOption<?>,java.lang.Object> result, ChannelOption<?>... options)
-
setOptions
public boolean setOptions(java.util.Map<ChannelOption<?>,?> options)
Description copied from interface:ChannelConfig
Sets the configuration properties from the specifiedMap
.- Specified by:
setOptions
in interfaceChannelConfig
-
getOption
public <T> T getOption(ChannelOption<T> option)
Description copied from interface:ChannelConfig
Return the value of the givenChannelOption
- Specified by:
getOption
in interfaceChannelConfig
-
setOption
public <T> boolean setOption(ChannelOption<T> option, T value)
Description copied from interface:ChannelConfig
Sets a configuration property with the specified name and value. To override this method properly, you must call the super class:public boolean setOption(ChannelOption<T> option, T value) { if (super.setOption(option, value)) { return true; } if (option.equals(additionalOption)) { .... return true; } return false; }
- Specified by:
setOption
in interfaceChannelConfig
- Returns:
true
if and only if the property has been set
-
validate
protected <T> void validate(ChannelOption<T> option, T value)
-
getConnectTimeoutMillis
public int getConnectTimeoutMillis()
Description copied from interface:ChannelConfig
Returns the connect timeout of the channel in milliseconds. If theChannel
does not support connect operation, this property is not used at all, and therefore will be ignored.- Specified by:
getConnectTimeoutMillis
in interfaceChannelConfig
- Returns:
- the connect timeout in milliseconds.
0
if disabled.
-
setConnectTimeoutMillis
public ChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis)
Description copied from interface:ChannelConfig
Sets the connect timeout of the channel in milliseconds. If theChannel
does not support connect operation, this property is not used at all, and therefore will be ignored.- Specified by:
setConnectTimeoutMillis
in interfaceChannelConfig
- Parameters:
connectTimeoutMillis
- the connect timeout in milliseconds.0
to disable.
-
getMaxMessagesPerRead
@Deprecated public int getMaxMessagesPerRead()
Deprecated.- Specified by:
getMaxMessagesPerRead
in interfaceChannelConfig
- Throws:
java.lang.IllegalStateException
- ifgetRecvByteBufAllocator()
does not return an object of typeMaxMessagesRecvByteBufAllocator
.
-
setMaxMessagesPerRead
@Deprecated public ChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead)
Deprecated.- Specified by:
setMaxMessagesPerRead
in interfaceChannelConfig
- Throws:
java.lang.IllegalStateException
- ifgetRecvByteBufAllocator()
does not return an object of typeMaxMessagesRecvByteBufAllocator
.
-
getMaxMessagesPerWrite
public int getMaxMessagesPerWrite()
Get the maximum number of message to write per eventloop run. Once this limit is reached we will continue to process other events before trying to write the remaining messages.
-
setMaxMessagesPerWrite
public ChannelConfig setMaxMessagesPerWrite(int maxMessagesPerWrite)
Set the maximum number of message to write per eventloop run. Once this limit is reached we will continue to process other events before trying to write the remaining messages.
-
getWriteSpinCount
public int getWriteSpinCount()
Description copied from interface:ChannelConfig
Returns the maximum loop count for a write operation untilWritableByteChannel.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 is16
.- Specified by:
getWriteSpinCount
in interfaceChannelConfig
-
setWriteSpinCount
public ChannelConfig setWriteSpinCount(int writeSpinCount)
Description copied from interface:ChannelConfig
Sets the maximum loop count for a write operation untilWritableByteChannel.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 is16
.- Specified by:
setWriteSpinCount
in interfaceChannelConfig
-
getAllocator
public ByteBufAllocator getAllocator()
Description copied from interface:ChannelConfig
ReturnsByteBufAllocator
which is used for the channel to allocate buffers.- Specified by:
getAllocator
in interfaceChannelConfig
-
setAllocator
public ChannelConfig setAllocator(ByteBufAllocator allocator)
Description copied from interface:ChannelConfig
Set theByteBufAllocator
which is used for the channel to allocate buffers.- Specified by:
setAllocator
in interfaceChannelConfig
-
getRecvByteBufAllocator
public <T extends RecvByteBufAllocator> T getRecvByteBufAllocator()
Description copied from interface:ChannelConfig
ReturnsRecvByteBufAllocator
which is used for the channel to allocate receive buffers.- Specified by:
getRecvByteBufAllocator
in interfaceChannelConfig
-
setRecvByteBufAllocator
public ChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator)
Description copied from interface:ChannelConfig
Set theRecvByteBufAllocator
which is used for the channel to allocate receive buffers.- Specified by:
setRecvByteBufAllocator
in interfaceChannelConfig
-
isAutoRead
public boolean isAutoRead()
Description copied from interface:ChannelConfig
Returnstrue
if and only ifChannelHandlerContext.read()
will be invoked automatically so that a user application doesn't need to call it at all. The default value istrue
.- Specified by:
isAutoRead
in interfaceChannelConfig
-
setAutoRead
public ChannelConfig setAutoRead(boolean autoRead)
Description copied from interface:ChannelConfig
Sets ifChannelHandlerContext.read()
will be invoked automatically so that a user application doesn't need to call it at all. The default value istrue
.- Specified by:
setAutoRead
in interfaceChannelConfig
-
autoReadCleared
protected void autoReadCleared()
-
isAutoClose
public boolean isAutoClose()
Description copied from interface:ChannelConfig
Returnstrue
if and only if theChannel
will be closed automatically and immediately on write failure. The default istrue
.- Specified by:
isAutoClose
in interfaceChannelConfig
-
setAutoClose
public ChannelConfig setAutoClose(boolean autoClose)
Description copied from interface:ChannelConfig
Sets whether theChannel
should be closed automatically and immediately on write failure. The default istrue
.- Specified by:
setAutoClose
in interfaceChannelConfig
-
getWriteBufferHighWaterMark
public int getWriteBufferHighWaterMark()
Description copied from interface:ChannelConfig
Returns the high water mark of the write buffer. If the number of bytes queued in the write buffer exceeds this value,Channel.isWritable()
will start to returnfalse
.- Specified by:
getWriteBufferHighWaterMark
in interfaceChannelConfig
-
setWriteBufferHighWaterMark
public ChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark)
Description copied from interface:ChannelConfig
Sets the high water mark of the write buffer. If the number of bytes queued in the write buffer exceeds this value,
Channel.isWritable()
will start to returnfalse
.- Specified by:
setWriteBufferHighWaterMark
in interfaceChannelConfig
-
getWriteBufferLowWaterMark
public int getWriteBufferLowWaterMark()
Description copied from interface:ChannelConfig
Returns the low water mark of the write buffer. Once the number of bytes queued in the write buffer exceeded the high water mark and then dropped down below this value,Channel.isWritable()
will start to returntrue
again.- Specified by:
getWriteBufferLowWaterMark
in interfaceChannelConfig
-
setWriteBufferLowWaterMark
public ChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark)
Description copied from interface:ChannelConfig
Sets the low water mark of the write buffer. Once the number of bytes queued in the write buffer exceeded the high water mark and then dropped down below this value,
Channel.isWritable()
will start to returntrue
again.- Specified by:
setWriteBufferLowWaterMark
in interfaceChannelConfig
-
setWriteBufferWaterMark
public ChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark)
Description copied from interface:ChannelConfig
Set theWriteBufferWaterMark
which is used for setting the high and low water mark of the write buffer.- Specified by:
setWriteBufferWaterMark
in interfaceChannelConfig
-
getWriteBufferWaterMark
public WriteBufferWaterMark getWriteBufferWaterMark()
Description copied from interface:ChannelConfig
Returns theWriteBufferWaterMark
which is used for setting the high and low water mark of the write buffer.- Specified by:
getWriteBufferWaterMark
in interfaceChannelConfig
-
getMessageSizeEstimator
public MessageSizeEstimator getMessageSizeEstimator()
Description copied from interface:ChannelConfig
ReturnsMessageSizeEstimator
which is used for the channel to detect the size of a message.- Specified by:
getMessageSizeEstimator
in interfaceChannelConfig
-
setMessageSizeEstimator
public ChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator)
Description copied from interface:ChannelConfig
Set theMessageSizeEstimator
which is used for the channel to detect the size of a message.- Specified by:
setMessageSizeEstimator
in interfaceChannelConfig
-
-