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 org.apache.mina.core.session.AbstractIoSessionConfig;
23  import org.apache.mina.core.session.IoSessionConfig;
24  
25  /**
26   * The Datagram transport session configuration.
27   * 
28   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
29   */
30  public abstract class AbstractDatagramSessionConfig extends AbstractIoSessionConfig implements DatagramSessionConfig {
31      /** Tells if we should close the session if the port is unreachable. Default to true */
32      private boolean closeOnPortUnreachable = true;
33  
34      /**
35       * {@inheritDoc}
36       */
37      @Override
38      public void setAll(IoSessionConfig config) {
39          super.setAll(config);
40          
41          if (!(config instanceof DatagramSessionConfig)) {
42              return;
43          }
44  
45          if (config instanceof AbstractDatagramSessionConfig) {
46              // Minimize unnecessary system calls by checking all 'propertyChanged' properties.
47              AbstractDatagramSessionConfigpache/mina/transport/socket/AbstractDatagramSessionConfig.html#AbstractDatagramSessionConfig">AbstractDatagramSessionConfig cfg = (AbstractDatagramSessionConfig) config;
48              
49              if (cfg.isBroadcastChanged()) {
50                  setBroadcast(cfg.isBroadcast());
51              }
52              
53              if (cfg.isReceiveBufferSizeChanged()) {
54                  setReceiveBufferSize(cfg.getReceiveBufferSize());
55              }
56              
57              if (cfg.isReuseAddressChanged()) {
58                  setReuseAddress(cfg.isReuseAddress());
59              }
60              
61              if (cfg.isSendBufferSizeChanged()) {
62                  setSendBufferSize(cfg.getSendBufferSize());
63              }
64              
65              if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) {
66                  setTrafficClass(cfg.getTrafficClass());
67              }
68          } else {
69              DatagramSessionConfig../org/apache/mina/transport/socket/DatagramSessionConfig.html#DatagramSessionConfig">DatagramSessionConfig cfg = (DatagramSessionConfig) config;
70              setBroadcast(cfg.isBroadcast());
71              setReceiveBufferSize(cfg.getReceiveBufferSize());
72              setReuseAddress(cfg.isReuseAddress());
73              setSendBufferSize(cfg.getSendBufferSize());
74              
75              if (getTrafficClass() != cfg.getTrafficClass()) {
76                  setTrafficClass(cfg.getTrafficClass());
77              }
78          }
79      }
80  
81      /**
82       * @return <tt>true</tt> if and only if the <tt>broadcast</tt> property
83       * has been changed by its setter method.  The system call related with
84       * the property is made only when this method returns <tt>true</tt>.  By
85       * default, this method always returns <tt>true</tt> to simplify implementation
86       * of subclasses, but overriding the default behavior is always encouraged.
87       */
88      protected boolean isBroadcastChanged() {
89          return true;
90      }
91  
92      /**
93       * @return <tt>true</tt> if and only if the <tt>receiveBufferSize</tt> property
94       * has been changed by its setter method.  The system call related with
95       * the property is made only when this method returns <tt>true</tt>.  By
96       * default, this method always returns <tt>true</tt> to simplify implementation
97       * of subclasses, but overriding the default behavior is always encouraged.
98       */
99      protected boolean isReceiveBufferSizeChanged() {
100         return true;
101     }
102 
103     /**
104      * @return <tt>true</tt> if and only if the <tt>reuseAddress</tt> property
105      * has been changed by its setter method.  The system call related with
106      * the property is made only when this method returns <tt>true</tt>.  By
107      * default, this method always returns <tt>true</tt> to simplify implementation
108      * of subclasses, but overriding the default behavior is always encouraged.
109      */
110     protected boolean isReuseAddressChanged() {
111         return true;
112     }
113 
114     /**
115      * @return <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property
116      * has been changed by its setter method.  The system call related with
117      * the property is made only when this method returns <tt>true</tt>.  By
118      * default, this method always returns <tt>true</tt> to simplify implementation
119      * of subclasses, but overriding the default behavior is always encouraged.
120      */
121     protected boolean isSendBufferSizeChanged() {
122         return true;
123     }
124 
125     /**
126      * @return <tt>true</tt> if and only if the <tt>trafficClass</tt> property
127      * has been changed by its setter method.  The system call related with
128      * the property is made only when this method returns <tt>true</tt>.  By
129      * default, this method always returns <tt>true</tt> to simplify implementation
130      * of subclasses, but overriding the default behavior is always encouraged.
131      */
132     protected boolean isTrafficClassChanged() {
133         return true;
134     }
135 
136     /**
137      * {@inheritDoc}
138      */
139     @Override
140     public boolean isCloseOnPortUnreachable() {
141         return closeOnPortUnreachable;
142     }
143 
144     /**
145      * {@inheritDoc}
146      */
147     @Override
148     public void setCloseOnPortUnreachable(boolean closeOnPortUnreachable) {
149         this.closeOnPortUnreachable = closeOnPortUnreachable;
150     }
151 }