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      private static int DEFAULT_RECEIVE_BUFFER_SIZE = 1024;
33      private static int DEFAULT_SEND_BUFFER_SIZE = 1024;
34      private static int DEFAULT_TRAFFIC_CLASS = 0;
35  
36      private boolean broadcast = DEFAULT_BROADCAST;
37      private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
38      private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
39      private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
40      private int trafficClass = DEFAULT_TRAFFIC_CLASS;
41      
42      /**
43       * Creates a new instance.
44       */
45      public DefaultDatagramSessionConfig() {
46          // Do nothing
47      }
48  
49      /**
50       * @see DatagramSocket#getBroadcast()
51       */
52      public boolean isBroadcast() {
53          return broadcast;
54      }
55  
56      /**
57       * @see DatagramSocket#setBroadcast(boolean)
58       */
59      public void setBroadcast(boolean broadcast) {
60          this.broadcast = broadcast;
61      }
62  
63      /**
64       * @see DatagramSocket#getReuseAddress()
65       */
66      public boolean isReuseAddress() {
67          return reuseAddress;
68      }
69  
70      /**
71       * @see DatagramSocket#setReuseAddress(boolean)
72       */
73      public void setReuseAddress(boolean reuseAddress) {
74          this.reuseAddress = reuseAddress;
75      }
76  
77      /**
78       * @see DatagramSocket#getReceiveBufferSize()
79       */
80      public int getReceiveBufferSize() {
81          return receiveBufferSize;
82      }
83  
84      /**
85       * @see DatagramSocket#setReceiveBufferSize(int)
86       */
87      public void setReceiveBufferSize(int receiveBufferSize) {
88          this.receiveBufferSize = receiveBufferSize;
89      }
90  
91      /**
92       * @see DatagramSocket#getSendBufferSize()
93       */
94      public int getSendBufferSize() {
95          return sendBufferSize;
96      }
97  
98      /**
99       * @see DatagramSocket#setSendBufferSize(int)
100      */
101     public void setSendBufferSize(int sendBufferSize) {
102         this.sendBufferSize = sendBufferSize;
103     }
104 
105     /**
106      * @see DatagramSocket#getTrafficClass()
107      */
108     public int getTrafficClass() {
109         return trafficClass;
110     }
111 
112     /**
113      * @see DatagramSocket#setTrafficClass(int)
114      */
115     public void setTrafficClass(int trafficClass) {
116         this.trafficClass = trafficClass;
117     }
118 
119     @Override
120     protected boolean isBroadcastChanged() {
121         return broadcast != DEFAULT_BROADCAST;
122     }
123 
124     @Override
125     protected boolean isReceiveBufferSizeChanged() {
126         return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
127     }
128 
129     @Override
130     protected boolean isReuseAddressChanged() {
131         return reuseAddress != DEFAULT_REUSE_ADDRESS;
132     }
133 
134     @Override
135     protected boolean isSendBufferSizeChanged() {
136         return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
137     }
138 
139     @Override
140     protected boolean isTrafficClassChanged() {
141         return trafficClass != DEFAULT_TRAFFIC_CLASS;
142     }
143     
144 }