1 /* 2 * Copyright 2009 Red Hat, Inc. 3 * 4 * Red Hat licenses this file to you under the Apache License, version 2.0 5 * (the "License"); you may not use this file except in compliance with the 6 * 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.DatagramSocket; 19 import java.net.InetAddress; 20 import java.net.NetworkInterface; 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><td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td> 53 * </tr><tr> 54 * <td>{@code "receiveBufferSizePredictorFactory"}</td><td>{@link #setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory)}</td> 55 * </tr><tr> 56 * <td>{@code "sendBufferSize"}</td><td>{@link #setSendBufferSize(int)}</td> 57 * </tr><tr> 58 * <td>{@code "timeToLive"}</td><td>{@link #setTimeToLive(int)}</td> 59 * </tr><tr> 60 * <td>{@code "trafficClass"}</td><td>{@link #setTrafficClass(int)}</td> 61 * </tr> 62 * </table> 63 * 64 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a> 65 * @author <a href="http://gleamynode.net/">Trustin Lee</a> 66 * 67 * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ 68 */ 69 public interface DatagramChannelConfig extends ChannelConfig { 70 71 /** 72 * Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option. 73 */ 74 int getSendBufferSize(); 75 76 /** 77 * Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option. 78 */ 79 void setSendBufferSize(int sendBufferSize); 80 81 /** 82 * Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option. 83 */ 84 int getReceiveBufferSize(); 85 86 /** 87 * Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option. 88 */ 89 void setReceiveBufferSize(int receiveBufferSize); 90 91 /** 92 * Gets the traffic class. 93 */ 94 int getTrafficClass(); 95 96 /** 97 * Sets the traffic class as specified in {@link DatagramSocket#setTrafficClass(int)}. 98 */ 99 void setTrafficClass(int trafficClass); 100 101 /** 102 * Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option. 103 */ 104 boolean isReuseAddress(); 105 106 /** 107 * Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option. 108 */ 109 void setReuseAddress(boolean reuseAddress); 110 111 /** 112 * Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_BROADCAST}</a> option. 113 */ 114 boolean isBroadcast(); 115 116 /** 117 * Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_BROADCAST}</a> option. 118 */ 119 void setBroadcast(boolean broadcast); 120 121 /** 122 * Gets the setting for local loopback of multicast datagrams. 123 * 124 * @return {@code true} if and only if the loopback mode has been disabled 125 */ 126 boolean isLoopbackModeDisabled(); 127 128 /** 129 * Sets the setting for local loopback of multicast datagrams. 130 * 131 * @param loopbackModeDisabled 132 * {@code true} if and only if the loopback mode has been disabled 133 */ 134 void setLoopbackModeDisabled(boolean loopbackModeDisabled); 135 136 /** 137 * Gets the default time-to-live for multicast packets sent out on the 138 * socket. 139 */ 140 int getTimeToLive(); 141 142 /** 143 * Sets the default time-to-live for multicast packets sent out on the 144 * {@link DatagramChannel} in order to control the scope of the multicasts. 145 */ 146 void setTimeToLive(int ttl); 147 148 /** 149 * Gets the address of the network interface used for multicast packets. 150 */ 151 InetAddress getInterface(); 152 153 /** 154 * Sets the address of the network interface used for multicast packets. 155 */ 156 void setInterface(InetAddress interfaceAddress); 157 158 /** 159 * Gets the network interface for outgoing multicast datagrams sent on 160 * the {@link DatagramChannel}. 161 */ 162 NetworkInterface getNetworkInterface(); 163 164 /** 165 * Sets the network interface for outgoing multicast datagrams sent on 166 * the {@link DatagramChannel}. 167 */ 168 void setNetworkInterface(NetworkInterface networkInterface); 169 170 /** 171 * Returns the {@link ReceiveBufferSizePredictor} which predicts the 172 * number of readable bytes in the socket receive buffer. The default 173 * predictor is <tt>{@link FixedReceiveBufferSizePredictor}(768)</tt>. 174 */ 175 ReceiveBufferSizePredictor getReceiveBufferSizePredictor(); 176 177 /** 178 * Sets the {@link ReceiveBufferSizePredictor} which predicts the 179 * number of readable bytes in the socket receive buffer. The default 180 * predictor is <tt>{@link FixedReceiveBufferSizePredictor}(768)</tt>. 181 */ 182 void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor); 183 184 /** 185 * Returns the {@link ReceiveBufferSizePredictorFactory} which creates a new 186 * {@link ReceiveBufferSizePredictor} when a new channel is created and 187 * no {@link ReceiveBufferSizePredictor} was set. If no predictor was set 188 * for the channel, {@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)} 189 * will be called with the new predictor. The default factory is 190 * <tt>{@link FixedReceiveBufferSizePredictorFactory}(768)</tt>. 191 */ 192 ReceiveBufferSizePredictorFactory getReceiveBufferSizePredictorFactory(); 193 194 /** 195 * Sets the {@link ReceiveBufferSizePredictor} which creates a new 196 * {@link ReceiveBufferSizePredictor} when a new channel is created and 197 * no {@link ReceiveBufferSizePredictor} was set. If no predictor was set 198 * for the channel, {@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)} 199 * will be called with the new predictor. The default factory is 200 * <tt>{@link FixedReceiveBufferSizePredictorFactory}(768)</tt>. 201 */ 202 void setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory predictorFactory); 203 }