/* * Copyright 2012 The Netty Project * * The Netty Project licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package io.netty.channel; import io.netty.buffer.ByteBufAllocator; import io.netty.channel.socket.SocketChannelConfig; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import java.util.Map; /** * A set of configuration properties of a {@link Channel}. *
* Please down-cast to more specific configuration type such as * {@link SocketChannelConfig} or use {@link #setOptions(Map)} to set the * transport-specific properties: *
* {@link Channel} ch = ...; * {@link SocketChannelConfig} cfg = ({@link SocketChannelConfig}) ch.getConfig(); * cfg.setTcpNoDelay(false); ** *
* All {@link ChannelConfig} has the following options: * *
Name | Associated setter method | *
---|---|
{@link ChannelOption#CONNECT_TIMEOUT_MILLIS} | {@link #setConnectTimeoutMillis(int)} | *
{@link ChannelOption#WRITE_SPIN_COUNT} | {@link #setWriteSpinCount(int)} | *
{@link ChannelOption#WRITE_BUFFER_WATER_MARK} | {@link #setWriteBufferWaterMark(WriteBufferWaterMark)} | *
{@link ChannelOption#ALLOCATOR} | {@link #setAllocator(ByteBufAllocator)} | *
{@link ChannelOption#AUTO_READ} | {@link #setAutoRead(boolean)} | *
* More options are available in the sub-types of {@link ChannelConfig}. For
* example, you can configure the parameters which are specific to a TCP/IP
* socket as explained in {@link SocketChannelConfig}.
*/
public interface ChannelConfig {
/**
* Return all set {@link ChannelOption}'s.
*/
Map
* Returns the maximum number of messages to read per read loop.
* a {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event.
* If this value is greater than 1, an event loop might attempt to read multiple times to procure multiple messages.
*/
@Deprecated
int getMaxMessagesPerRead();
/**
* @deprecated Use {@link MaxMessagesRecvByteBufAllocator} and
* {@link MaxMessagesRecvByteBufAllocator#maxMessagesPerRead(int)}.
*
* Sets the maximum number of messages to read per read loop.
* If this value is greater than 1, an event loop might attempt to read multiple times to procure multiple messages.
*/
@Deprecated
ChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
/**
* Returns the maximum loop count for a write operation until
* {@link 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 {@code 16}.
*/
int getWriteSpinCount();
/**
* Sets the maximum loop count for a write operation until
* {@link 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 {@code 16}.
*
* @throws IllegalArgumentException
* if the specified value is {@code 0} or less than {@code 0}
*/
ChannelConfig setWriteSpinCount(int writeSpinCount);
/**
* Returns {@link ByteBufAllocator} which is used for the channel
* to allocate buffers.
*/
ByteBufAllocator getAllocator();
/**
* Set the {@link ByteBufAllocator} which is used for the channel
* to allocate buffers.
*/
ChannelConfig setAllocator(ByteBufAllocator allocator);
/**
* Returns {@link RecvByteBufAllocator} which is used for the channel to allocate receive buffers.
*/
* Sets the high water mark of the write buffer. If the number of bytes
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
* will start to return {@code false}.
*/
ChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark);
/**
* Returns the low water mark of the write buffer. Once the number of bytes
* queued in the write buffer exceeded the
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
* dropped down below this value, {@link Channel#isWritable()} will start to return
* {@code true} again.
*/
int getWriteBufferLowWaterMark();
/**
*
* Sets the low water mark of the write buffer. Once the number of bytes
* queued in the write buffer exceeded the
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
* dropped down below this value, {@link Channel#isWritable()} will start to return
* {@code true} again.
*/
ChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark);
/**
* Returns {@link MessageSizeEstimator} which is used for the channel
* to detect the size of a message.
*/
MessageSizeEstimator getMessageSizeEstimator();
/**
* Set the {@link MessageSizeEstimator} which is used for the channel
* to detect the size of a message.
*/
ChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
/**
* Returns the {@link WriteBufferWaterMark} which is used for setting the high and low
* water mark of the write buffer.
*/
WriteBufferWaterMark getWriteBufferWaterMark();
/**
* Set the {@link WriteBufferWaterMark} which is used for setting the high and low
* water mark of the write buffer.
*/
ChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark);
}
* public boolean setOption(ChannelOption<T> option, T value) {
* if (super.setOption(option, value)) {
* return true;
* }
*
* if (option.equals(additionalOption)) {
* ....
* return true;
* }
*
* return false;
* }
*
*
* @return {@code true} if and only if the property has been set
*/