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 final boolean DEFAULT_BROADCAST = false;
31  
32      private static final boolean DEFAULT_REUSE_ADDRESS = false;
33  
34      /* The SO_RCVBUF parameter. Set to -1 (ie, will default to OS default) */
35      private static final int DEFAULT_RECEIVE_BUFFER_SIZE = -1;
36  
37      /* The SO_SNDBUF parameter. Set to -1 (ie, will default to OS default) */
38      private static final int DEFAULT_SEND_BUFFER_SIZE = -1;
39  
40      private static final int DEFAULT_TRAFFIC_CLASS = 0;
41  
42      private boolean broadcast = DEFAULT_BROADCAST;
43  
44      private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
45  
46      private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
47  
48      private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
49  
50      private int trafficClass = DEFAULT_TRAFFIC_CLASS;
51  
52      /**
53       * Creates a new instance.
54       */
55      public DefaultDatagramSessionConfig() {
56          // Do nothing
57      }
58  
59      /**
60       * @see DatagramSocket#getBroadcast()
61       */
62      @Override
63      public boolean isBroadcast() {
64          return broadcast;
65      }
66  
67      /**
68       * @see DatagramSocket#setBroadcast(boolean)
69       */
70      @Override
71      public void setBroadcast(boolean broadcast) {
72          this.broadcast = broadcast;
73      }
74  
75      /**
76       * @see DatagramSocket#getReuseAddress()
77       */
78      @Override
79      public boolean isReuseAddress() {
80          return reuseAddress;
81      }
82  
83      /**
84       * @see DatagramSocket#setReuseAddress(boolean)
85       */
86      @Override
87      public void setReuseAddress(boolean reuseAddress) {
88          this.reuseAddress = reuseAddress;
89      }
90  
91      /**
92       * @see DatagramSocket#getReceiveBufferSize()
93       */
94      @Override
95      public int getReceiveBufferSize() {
96          return receiveBufferSize;
97      }
98  
99      /**
100      * @see DatagramSocket#setReceiveBufferSize(int)
101      */
102     @Override
103     public void setReceiveBufferSize(int receiveBufferSize) {
104         this.receiveBufferSize = receiveBufferSize;
105     }
106 
107     /**
108      * @see DatagramSocket#getSendBufferSize()
109      */
110     @Override
111     public int getSendBufferSize() {
112         return sendBufferSize;
113     }
114 
115     /**
116      * @see DatagramSocket#setSendBufferSize(int)
117      */
118     @Override
119     public void setSendBufferSize(int sendBufferSize) {
120         this.sendBufferSize = sendBufferSize;
121     }
122 
123     /**
124      * @see DatagramSocket#getTrafficClass()
125      */
126     @Override
127     public int getTrafficClass() {
128         return trafficClass;
129     }
130 
131     /**
132      * @see DatagramSocket#setTrafficClass(int)
133      */
134     @Override
135     public void setTrafficClass(int trafficClass) {
136         this.trafficClass = trafficClass;
137     }
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     protected boolean isBroadcastChanged() {
144         return broadcast != DEFAULT_BROADCAST;
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     protected boolean isReceiveBufferSizeChanged() {
152         return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
153     }
154 
155     /**
156      * {@inheritDoc}
157      */
158     @Override
159     protected boolean isReuseAddressChanged() {
160         return reuseAddress != DEFAULT_REUSE_ADDRESS;
161     }
162 
163     /**
164      * {@inheritDoc}
165      */
166     @Override
167     protected boolean isSendBufferSizeChanged() {
168         return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
169     }
170 
171     /**
172      * {@inheritDoc}
173      */
174     @Override
175     protected boolean isTrafficClassChanged() {
176         return trafficClass != DEFAULT_TRAFFIC_CLASS;
177     }
178 }