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 TCP transport session configuration.
27   * 
28   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
29   */
30  public abstract class AbstractSocketSessionConfig extends AbstractIoSessionConfig implements SocketSessionConfig {
31      /**
32       * {@inheritDoc}
33       */
34      @Override
35      public void setAll(IoSessionConfig config) {
36          super.setAll(config);
37          
38          if (!(config instanceof SocketSessionConfig)) {
39              return;
40          }
41  
42          if (config instanceof AbstractSocketSessionConfig) {
43              // Minimize unnecessary system calls by checking all 'propertyChanged' properties.
44              AbstractSocketSessionConfig/apache/mina/transport/socket/AbstractSocketSessionConfig.html#AbstractSocketSessionConfig">AbstractSocketSessionConfig cfg = (AbstractSocketSessionConfig) config;
45              if (cfg.isKeepAliveChanged()) {
46                  setKeepAlive(cfg.isKeepAlive());
47              }
48              if (cfg.isOobInlineChanged()) {
49                  setOobInline(cfg.isOobInline());
50              }
51              if (cfg.isReceiveBufferSizeChanged()) {
52                  setReceiveBufferSize(cfg.getReceiveBufferSize());
53              }
54              if (cfg.isReuseAddressChanged()) {
55                  setReuseAddress(cfg.isReuseAddress());
56              }
57              if (cfg.isSendBufferSizeChanged()) {
58                  setSendBufferSize(cfg.getSendBufferSize());
59              }
60              if (cfg.isSoLingerChanged()) {
61                  setSoLinger(cfg.getSoLinger());
62              }
63              if (cfg.isTcpNoDelayChanged()) {
64                  setTcpNoDelay(cfg.isTcpNoDelay());
65              }
66              if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) {
67                  setTrafficClass(cfg.getTrafficClass());
68              }
69          } else {
70              SocketSessionConfig./../org/apache/mina/transport/socket/SocketSessionConfig.html#SocketSessionConfig">SocketSessionConfig cfg = (SocketSessionConfig) config;
71              setKeepAlive(cfg.isKeepAlive());
72              setOobInline(cfg.isOobInline());
73              setReceiveBufferSize(cfg.getReceiveBufferSize());
74              setReuseAddress(cfg.isReuseAddress());
75              setSendBufferSize(cfg.getSendBufferSize());
76              setSoLinger(cfg.getSoLinger());
77              setTcpNoDelay(cfg.isTcpNoDelay());
78              if (getTrafficClass() != cfg.getTrafficClass()) {
79                  setTrafficClass(cfg.getTrafficClass());
80              }
81          }
82      }
83  
84      /**
85       * @return <tt>true</tt> if and only if the <tt>keepAlive</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 isKeepAliveChanged() {
92          return true;
93      }
94  
95      /**
96       * @return <tt>true</tt> if and only if the <tt>oobInline</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 isOobInlineChanged() {
103         return true;
104     }
105 
106     /**
107      * @return <tt>true</tt> if and only if the <tt>receiveBufferSize</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 isReceiveBufferSizeChanged() {
114         return true;
115     }
116 
117     /**
118      * @return <tt>true</tt> if and only if the <tt>reuseAddress</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 isReuseAddressChanged() {
125         return true;
126     }
127 
128     /**
129      * @return <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property
130      * has been changed by its setter method.  The system call related with
131      * the property is made only when this method returns <tt>true</tt>.  By
132      * default, this method always returns <tt>true</tt> to simplify implementation
133      * of subclasses, but overriding the default behavior is always encouraged.
134      */
135     protected boolean isSendBufferSizeChanged() {
136         return true;
137     }
138 
139     /**
140      * @return <tt>true</tt> if and only if the <tt>soLinger</tt> property
141      * has been changed by its setter method.  The system call related with
142      * the property is made only when this method returns <tt>true</tt>.  By
143      * default, this method always returns <tt>true</tt> to simplify implementation
144      * of subclasses, but overriding the default behavior is always encouraged.
145      */
146     protected boolean isSoLingerChanged() {
147         return true;
148     }
149 
150     /**
151      * @return <tt>true</tt> if and only if the <tt>tcpNoDelay</tt> property
152      * has been changed by its setter method.  The system call related with
153      * the property is made only when this method returns <tt>true</tt>.  By
154      * default, this method always returns <tt>true</tt> to simplify implementation
155      * of subclasses, but overriding the default behavior is always encouraged.
156      */
157     protected boolean isTcpNoDelayChanged() {
158         return true;
159     }
160 
161     /**
162      * @return <tt>true</tt> if and only if the <tt>trafficClass</tt> property
163      * has been changed by its setter method.  The system call related with
164      * the property is made only when this method returns <tt>true</tt>.  By
165      * default, this method always returns <tt>true</tt> to simplify implementation
166      * of subclasses, but overriding the default behavior is always encouraged.
167      */
168     protected boolean isTrafficClassChanged() {
169         return true;
170     }
171 }