netty5/src/main/java/io/netty/channel/ChannelConfig.java

147 lines
5.3 KiB
Java
Raw Normal View History

/*
2009-08-28 09:15:49 +02:00
* Copyright 2009 Red Hat, Inc.
*
2009-08-28 09:15:49 +02:00
* Red Hat 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:
*
2009-08-28 09:15:49 +02:00
* http://www.apache.org/licenses/LICENSE-2.0
*
2009-08-28 09:15:49 +02:00
* 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.
*/
2011-12-09 04:38:59 +01:00
package io.netty.channel;
2009-06-19 10:16:56 +02:00
import java.nio.ByteOrder;
import java.util.Map;
2011-12-09 04:38:59 +01:00
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBufferFactory;
import io.netty.buffer.HeapChannelBufferFactory;
import io.netty.channel.socket.SocketChannelConfig;
import io.netty.channel.socket.nio.NioSocketChannelConfig;
2008-09-02 14:04:04 +02:00
/**
* A set of configuration properties of a {@link Channel}.
2008-09-02 09:13:20 +02:00
* <p>
* Please down-cast to more specific configuration type such as
* {@link SocketChannelConfig} or use {@link #setOptions(Map)} to set the
* transport-specific properties:
* <pre>
2010-02-02 03:00:04 +01:00
* {@link Channel} ch = ...;
* {@link SocketChannelConfig} cfg = <strong>({@link SocketChannelConfig}) ch.getConfig();</strong>
* cfg.setTcpNoDelay(false);
* </pre>
*
2008-09-24 13:28:46 +02:00
* <h3>Option map</h3>
*
* An option map property is a dynamic write-only property which allows
* the configuration of a {@link Channel} without down-casting its associated
* {@link ChannelConfig}. To update an option map, please call {@link #setOptions(Map)}.
* <p>
* All {@link ChannelConfig} has the following options:
2008-09-24 14:01:50 +02:00
*
* <table border="1" cellspacing="0" cellpadding="6">
2008-09-24 13:28:46 +02:00
* <tr>
* <th>Name</th><th>Associated setter method</th>
* </tr><tr>
2009-06-19 10:16:56 +02:00
* <td>{@code "bufferFactory"}</td><td>{@link #setBufferFactory(ChannelBufferFactory)}</td>
* </tr><tr>
2008-09-24 13:28:46 +02:00
* <td>{@code "connectTimeoutMillis"}</td><td>{@link #setConnectTimeoutMillis(int)}</td>
* </tr><tr>
* <td>{@code "pipelineFactory"}</td><td>{@link #setPipelineFactory(ChannelPipelineFactory)}</td>
* </tr>
* </table>
2008-09-24 14:01:50 +02:00
* <p>
2008-09-24 13:28:46 +02:00
* 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} or {@link NioSocketChannelConfig}.
2011-12-09 04:38:59 +01:00
* @apiviz.has io.netty.channel.ChannelPipelineFactory
* @apiviz.composedOf io.netty.channel.ReceiveBufferSizePredictor
2009-04-28 14:11:01 +02:00
*
* @apiviz.excludeSubtypes
*/
public interface ChannelConfig {
2008-09-02 09:13:20 +02:00
/**
* Sets the configuration properties from the specified {@link Map}.
*/
void setOptions(Map<String, Object> options);
2008-09-02 09:13:20 +02:00
/**
* Sets a configuration property with the specified name and value.
* To override this method properly, you must call the super class:
* <pre>
* public boolean setOption(String name, Object value) {
* if (super.setOption(name, value)) {
* return true;
* }
*
* if (name.equals("additionalOption")) {
* ....
* return true;
* }
*
* return false;
* }
* </pre>
*
* @return {@code true} if and only if the property has been set
*/
boolean setOption(String name, Object value);
2009-06-19 10:16:56 +02:00
/**
* Returns the default {@link ChannelBufferFactory} used to create a new
* {@link ChannelBuffer}. The default is {@link HeapChannelBufferFactory}.
* You can specify a different factory to change the default
* {@link ByteOrder} for example.
*/
ChannelBufferFactory getBufferFactory();
2009-06-19 10:16:56 +02:00
/**
* Sets the default {@link ChannelBufferFactory} used to create a new
* {@link ChannelBuffer}. The default is {@link HeapChannelBufferFactory}.
* You can specify a different factory to change the default
* {@link ByteOrder} for example.
*/
void setBufferFactory(ChannelBufferFactory bufferFactory);
2008-09-02 09:13:20 +02:00
/**
* Returns the {@link ChannelPipelineFactory} which will be used when
2008-11-14 08:45:53 +01:00
* a child channel is created. If the {@link Channel} does not create
2008-09-02 14:04:04 +02:00
* a child channel, this property is not used at all, and therefore will
* be ignored.
2008-09-02 09:13:20 +02:00
*/
ChannelPipelineFactory getPipelineFactory();
2008-09-02 09:13:20 +02:00
/**
* Sets the {@link ChannelPipelineFactory} which will be used when
2008-11-14 08:45:53 +01:00
* a child channel is created. If the {@link Channel} does not create
2008-09-02 14:04:04 +02:00
* a child channel, this property is not used at all, and therefore will
* be ignored.
2008-09-02 09:13:20 +02:00
*/
void setPipelineFactory(ChannelPipelineFactory pipelineFactory);
2008-09-02 09:13:20 +02:00
/**
2008-09-02 14:04:04 +02:00
* Returns the connect timeout of the channel in milliseconds. If the
2008-11-14 08:45:53 +01:00
* {@link Channel} does not support connect operation, this property is not
2008-09-02 14:04:04 +02:00
* used at all, and therefore will be ignored.
2008-09-02 09:13:20 +02:00
*
* @return the connect timeout in milliseconds. {@code 0} if disabled.
*/
int getConnectTimeoutMillis();
2008-09-02 09:13:20 +02:00
/**
2008-09-02 14:04:04 +02:00
* Sets the connect timeout of the channel in milliseconds. If the
2008-11-14 08:45:53 +01:00
* {@link Channel} does not support connect operation, this property is not
2008-09-02 14:04:04 +02:00
* used at all, and therefore will be ignored.
2008-09-02 09:13:20 +02:00
*
* @param connectTimeoutMillis the connect timeout in milliseconds.
* {@code 0} to disable.
*/
void setConnectTimeoutMillis(int connectTimeoutMillis);
}