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   * TODO Add documentation
27   * 
28   * @author The Apache MINA Project (dev@mina.apache.org)
29   */
30  public abstract class AbstractDatagramSessionConfig extends
31          AbstractIoSessionConfig implements DatagramSessionConfig {
32  
33      protected AbstractDatagramSessionConfig() {
34          // Do nothing
35      }
36  
37      @Override
38      protected void doSetAll(IoSessionConfig config) {
39          if (!(config instanceof DatagramSessionConfig)) {
40              return;
41          }
42          
43          if (config instanceof AbstractDatagramSessionConfig) {
44              // Minimize unnecessary system calls by checking all 'propertyChanged' properties.
45              AbstractDatagramSessionConfig cfg = (AbstractDatagramSessionConfig) config;
46              if (cfg.isBroadcastChanged()) {
47                  setBroadcast(cfg.isBroadcast());
48              }
49              if (cfg.isReceiveBufferSizeChanged()) {
50                  setReceiveBufferSize(cfg.getReceiveBufferSize());
51              }
52              if (cfg.isReuseAddressChanged()) {
53                  setReuseAddress(cfg.isReuseAddress());
54              }
55              if (cfg.isSendBufferSizeChanged()) {
56                  setSendBufferSize(cfg.getSendBufferSize());
57              }
58              if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) {
59                  setTrafficClass(cfg.getTrafficClass());
60              }
61          } else {
62              DatagramSessionConfig cfg = (DatagramSessionConfig) config;
63              setBroadcast(cfg.isBroadcast());
64              setReceiveBufferSize(cfg.getReceiveBufferSize());
65              setReuseAddress(cfg.isReuseAddress());
66              setSendBufferSize(cfg.getSendBufferSize());
67              if (getTrafficClass() != cfg.getTrafficClass()) {
68                  setTrafficClass(cfg.getTrafficClass());
69              }
70          }
71      }
72      
73      /**
74       * Returns <tt>true</tt> if and only if the <tt>broadcast</tt> property
75       * has been changed by its setter method.  The system call related with
76       * the property is made only when this method returns <tt>true</tt>.  By
77       * default, this method always returns <tt>true</tt> to simplify implementation
78       * of subclasses, but overriding the default behavior is always encouraged.
79       */
80      protected boolean isBroadcastChanged() {
81          return true;
82      }
83  
84      /**
85       * Returns <tt>true</tt> if and only if the <tt>receiveBufferSize</tt> property
86       * has been changed by its setter method.  The system call related with
87       * the property is made only when this method returns <tt>true</tt>.  By
88       * default, this method always returns <tt>true</tt> to simplify implementation
89       * of subclasses, but overriding the default behavior is always encouraged.
90       */
91      protected boolean isReceiveBufferSizeChanged() {
92          return true;
93      }
94  
95      /**
96       * Returns <tt>true</tt> if and only if the <tt>reuseAddress</tt> property
97       * has been changed by its setter method.  The system call related with
98       * the property is made only when this method returns <tt>true</tt>.  By
99       * default, this method always returns <tt>true</tt> to simplify implementation
100      * of subclasses, but overriding the default behavior is always encouraged.
101      */
102     protected boolean isReuseAddressChanged() {
103         return true;
104     }
105 
106     /**
107      * Returns <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property
108      * has been changed by its setter method.  The system call related with
109      * the property is made only when this method returns <tt>true</tt>.  By
110      * default, this method always returns <tt>true</tt> to simplify implementation
111      * of subclasses, but overriding the default behavior is always encouraged.
112      */
113     protected boolean isSendBufferSizeChanged() {
114         return true;
115     }
116 
117     /**
118      * Returns <tt>true</tt> if and only if the <tt>trafficClass</tt> property
119      * has been changed by its setter method.  The system call related with
120      * the property is made only when this method returns <tt>true</tt>.  By
121      * default, this method always returns <tt>true</tt> to simplify implementation
122      * of subclasses, but overriding the default behavior is always encouraged.
123      */
124     protected  boolean isTrafficClassChanged() {
125         return true;
126     }
127 }