View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.transport.socket;
21  
22  import java.net.DatagramSocket;
23  
24  /**
25   * A default implementation of {@link DatagramSessionConfig}.
26   *
27   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
28   */
29  public class DefaultDatagramSessionConfig extends AbstractDatagramSessionConfig {
30      private static boolean DEFAULT_BROADCAST = false;
31      private static boolean DEFAULT_REUSE_ADDRESS = false;
32  
33      /* The SO_RCVBUF parameter. Set to -1 (ie, will default to OS default) */
34      private static int DEFAULT_RECEIVE_BUFFER_SIZE = -1;
35  
36      /* The SO_SNDBUF parameter. Set to -1 (ie, will default to OS default) */
37      private static int DEFAULT_SEND_BUFFER_SIZE = -1;
38  
39      private static int DEFAULT_TRAFFIC_CLASS = 0;
40  
41      private boolean broadcast = DEFAULT_BROADCAST;
42      private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
43      private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
44      private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
45      private int trafficClass = DEFAULT_TRAFFIC_CLASS;
46      
47      /**
48       * Creates a new instance.
49       */
50      public DefaultDatagramSessionConfig() {
51          // Do nothing
52      }
53  
54      /**
55       * @see DatagramSocket#getBroadcast()
56       */
57      public boolean isBroadcast() {
58          return broadcast;
59      }
60  
61      /**
62       * @see DatagramSocket#setBroadcast(boolean)
63       */
64      public void setBroadcast(boolean broadcast) {
65          this.broadcast = broadcast;
66      }
67  
68      /**
69       * @see DatagramSocket#getReuseAddress()
70       */
71      public boolean isReuseAddress() {
72          return reuseAddress;
73      }
74  
75      /**
76       * @see DatagramSocket#setReuseAddress(boolean)
77       */
78      public void setReuseAddress(boolean reuseAddress) {
79          this.reuseAddress = reuseAddress;
80      }
81  
82      /**
83       * @see DatagramSocket#getReceiveBufferSize()
84       */
85      public int getReceiveBufferSize() {
86          return receiveBufferSize;
87      }
88  
89      /**
90       * @see DatagramSocket#setReceiveBufferSize(int)
91       */
92      public void setReceiveBufferSize(int receiveBufferSize) {
93          this.receiveBufferSize = receiveBufferSize;
94      }
95  
96      /**
97       * @see DatagramSocket#getSendBufferSize()
98       */
99      public int getSendBufferSize() {
100         return sendBufferSize;
101     }
102 
103     /**
104      * @see DatagramSocket#setSendBufferSize(int)
105      */
106     public void setSendBufferSize(int sendBufferSize) {
107         this.sendBufferSize = sendBufferSize;
108     }
109 
110     /**
111      * @see DatagramSocket#getTrafficClass()
112      */
113     public int getTrafficClass() {
114         return trafficClass;
115     }
116 
117     /**
118      * @see DatagramSocket#setTrafficClass(int)
119      */
120     public void setTrafficClass(int trafficClass) {
121         this.trafficClass = trafficClass;
122     }
123 
124     @Override
125     protected boolean isBroadcastChanged() {
126         return broadcast != DEFAULT_BROADCAST;
127     }
128 
129     @Override
130     protected boolean isReceiveBufferSizeChanged() {
131         return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
132     }
133 
134     @Override
135     protected boolean isReuseAddressChanged() {
136         return reuseAddress != DEFAULT_REUSE_ADDRESS;
137     }
138 
139     @Override
140     protected boolean isSendBufferSizeChanged() {
141         return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
142     }
143 
144     @Override
145     protected boolean isTrafficClassChanged() {
146         return trafficClass != DEFAULT_TRAFFIC_CLASS;
147     }
148     
149 }