1 /* 2 * Copyright 2012 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package org.jboss.netty.channel.socket; 17 18 import java.net.InetAddress; 19 import java.net.NetworkInterface; 20 import java.net.StandardSocketOptions; 21 22 import org.jboss.netty.channel.ChannelConfig; 23 import org.jboss.netty.channel.FixedReceiveBufferSizePredictor; 24 import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory; 25 import org.jboss.netty.channel.ReceiveBufferSizePredictor; 26 import org.jboss.netty.channel.ReceiveBufferSizePredictorFactory; 27 28 /** 29 * A {@link ChannelConfig} for a {@link DatagramChannel}. 30 * 31 * <h3>Available options</h3> 32 * 33 * In addition to the options provided by {@link ChannelConfig}, 34 * {@link DatagramChannelConfig} allows the following options in the option map: 35 * 36 * <table border="1" cellspacing="0" cellpadding="6"> 37 * <tr> 38 * <th>Name</th><th>Associated setter method</th> 39 * </tr><tr> 40 * <td>{@code "broadcast"}</td><td>{@link #setBroadcast(boolean)}</td> 41 * </tr><tr> 42 * <td>{@code "interface"}</td><td>{@link #setInterface(InetAddress)}</td> 43 * </tr><tr> 44 * <td>{@code "loopbackModeDisabled"}</td><td>{@link #setLoopbackModeDisabled(boolean)}</td> 45 * </tr><tr> 46 * <td>{@code "networkInterface"}</td><td>{@link #setNetworkInterface(NetworkInterface)}</td> 47 * </tr><tr> 48 * <td>{@code "reuseAddress"}</td><td>{@link #setReuseAddress(boolean)}</td> 49 * </tr><tr> 50 * <td>{@code "receiveBufferSize"}</td><td>{@link #setReceiveBufferSize(int)}</td> 51 * </tr><tr> 52 * <td>{@code "receiveBufferSizePredictor"}</td> 53 * <td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td> 54 * </tr><tr> 55 * <td>{@code "receiveBufferSizePredictorFactory"}</td> 56 * <td>{@link #setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory)}</td> 57 * </tr><tr> 58 * <td>{@code "sendBufferSize"}</td><td>{@link #setSendBufferSize(int)}</td> 59 * </tr><tr> 60 * <td>{@code "timeToLive"}</td><td>{@link #setTimeToLive(int)}</td> 61 * </tr><tr> 62 * <td>{@code "trafficClass"}</td><td>{@link #setTrafficClass(int)}</td> 63 * </tr> 64 * </table> 65 */ 66 public interface DatagramChannelConfig extends ChannelConfig { 67 68 /** 69 * Gets the {@link StandardSocketOptions#SO_SNDBUF} option. 70 */ 71 int getSendBufferSize(); 72 73 /** 74 * Sets the {@link StandardSocketOptions#SO_SNDBUF} option. 75 */ 76 void setSendBufferSize(int sendBufferSize); 77 78 /** 79 * Gets the {@link StandardSocketOptions#SO_RCVBUF} option. 80 */ 81 int getReceiveBufferSize(); 82 83 /** 84 * Sets the {@link StandardSocketOptions#SO_RCVBUF} option. 85 */ 86 void setReceiveBufferSize(int receiveBufferSize); 87 88 /** 89 * Gets the {@link StandardSocketOptions#IP_TOS} option. 90 */ 91 int getTrafficClass(); 92 93 /** 94 * Gets the {@link StandardSocketOptions#IP_TOS} option. 95 */ 96 void setTrafficClass(int trafficClass); 97 98 /** 99 * Gets the {@link StandardSocketOptions#SO_REUSEADDR} option. 100 */ 101 boolean isReuseAddress(); 102 103 /** 104 * Sets the {@link StandardSocketOptions#SO_REUSEADDR} option. 105 */ 106 void setReuseAddress(boolean reuseAddress); 107 108 /** 109 * Gets the {@link StandardSocketOptions#SO_BROADCAST} option. 110 */ 111 boolean isBroadcast(); 112 113 /** 114 * Sets the {@link StandardSocketOptions#SO_BROADCAST} option. 115 */ 116 void setBroadcast(boolean broadcast); 117 118 /** 119 * Gets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option. 120 */ 121 boolean isLoopbackModeDisabled(); 122 123 /** 124 * Sets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option. 125 * 126 * @param loopbackModeDisabled 127 * {@code true} if and only if the loopback mode has been disabled 128 */ 129 void setLoopbackModeDisabled(boolean loopbackModeDisabled); 130 131 /** 132 * Gets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option. 133 */ 134 int getTimeToLive(); 135 136 /** 137 * Sets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option. 138 */ 139 void setTimeToLive(int ttl); 140 141 /** 142 * Gets the address of the network interface used for multicast packets. 143 */ 144 InetAddress getInterface(); 145 146 /** 147 * Sets the address of the network interface used for multicast packets. 148 */ 149 void setInterface(InetAddress interfaceAddress); 150 151 /** 152 * Gets the {@link StandardSocketOptions#IP_MULTICAST_IF} option. 153 */ 154 NetworkInterface getNetworkInterface(); 155 156 /** 157 * Sets the {@link StandardSocketOptions#IP_MULTICAST_IF} option. 158 */ 159 void setNetworkInterface(NetworkInterface networkInterface); 160 161 /** 162 * Returns the {@link ReceiveBufferSizePredictor} which predicts the 163 * number of readable bytes in the socket receive buffer. The default 164 * predictor is <tt>{@link FixedReceiveBufferSizePredictor}(768)</tt>. 165 */ 166 ReceiveBufferSizePredictor getReceiveBufferSizePredictor(); 167 168 /** 169 * Sets the {@link ReceiveBufferSizePredictor} which predicts the 170 * number of readable bytes in the socket receive buffer. The default 171 * predictor is <tt>{@link FixedReceiveBufferSizePredictor}(768)</tt>. 172 */ 173 void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor); 174 175 /** 176 * Returns the {@link ReceiveBufferSizePredictorFactory} which creates a new 177 * {@link ReceiveBufferSizePredictor} when a new channel is created and 178 * no {@link ReceiveBufferSizePredictor} was set. If no predictor was set 179 * for the channel, {@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)} 180 * will be called with the new predictor. The default factory is 181 * <tt>{@link FixedReceiveBufferSizePredictorFactory}(768)</tt>. 182 */ 183 ReceiveBufferSizePredictorFactory getReceiveBufferSizePredictorFactory(); 184 185 /** 186 * Sets the {@link ReceiveBufferSizePredictor} which creates a new 187 * {@link ReceiveBufferSizePredictor} when a new channel is created and 188 * no {@link ReceiveBufferSizePredictor} was set. If no predictor was set 189 * for the channel, {@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)} 190 * will be called with the new predictor. The default factory is 191 * <tt>{@link FixedReceiveBufferSizePredictorFactory}(768)</tt>. 192 */ 193 void setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory predictorFactory); 194 }