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   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
30   */
31  public abstract class AbstractSocketSessionConfig extends AbstractIoSessionConfig
32          implements SocketSessionConfig {
33  
34      protected AbstractSocketSessionConfig() {
35      }
36  
37      @Override
38      protected final void doSetAll(IoSessionConfig config) {
39          if (!(config instanceof SocketSessionConfig)) {
40              return;
41          }
42          
43          if (config instanceof AbstractSocketSessionConfig) {
44              // Minimize unnecessary system calls by checking all 'propertyChanged' properties.
45              AbstractSocketSessionConfig cfg = (AbstractSocketSessionConfig) config;
46              if (cfg.isKeepAliveChanged()) {
47                  setKeepAlive(cfg.isKeepAlive());
48              }
49              if (cfg.isOobInlineChanged()) {
50                  setOobInline(cfg.isOobInline());
51              }
52              if (cfg.isReceiveBufferSizeChanged()) {
53                  setReceiveBufferSize(cfg.getReceiveBufferSize());
54              }
55              if (cfg.isReuseAddressChanged()) {
56                  setReuseAddress(cfg.isReuseAddress());
57              }
58              if (cfg.isSendBufferSizeChanged()) {
59                  setSendBufferSize(cfg.getSendBufferSize());
60              }
61              if (cfg.isSoLingerChanged()) {
62                  setSoLinger(cfg.getSoLinger());
63              }
64              if (cfg.isTcpNoDelayChanged()) {
65                  setTcpNoDelay(cfg.isTcpNoDelay());
66              }
67              if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) {
68                  setTrafficClass(cfg.getTrafficClass());
69              }
70          } else {
71              SocketSessionConfig cfg = (SocketSessionConfig) config;
72              setKeepAlive(cfg.isKeepAlive());
73              setOobInline(cfg.isOobInline());
74              setReceiveBufferSize(cfg.getReceiveBufferSize());
75              setReuseAddress(cfg.isReuseAddress());
76              setSendBufferSize(cfg.getSendBufferSize());
77              setSoLinger(cfg.getSoLinger());
78              setTcpNoDelay(cfg.isTcpNoDelay());
79              if (getTrafficClass() != cfg.getTrafficClass()) {
80                  setTrafficClass(cfg.getTrafficClass());
81              }
82          }
83      }
84  
85      /**
86       * Returns <tt>true</tt> if and only if the <tt>keepAlive</tt> property
87       * has been changed by its setter method.  The system call related with
88       * the property is made only when this method returns <tt>true</tt>.  By
89       * default, this method always returns <tt>true</tt> to simplify implementation
90       * of subclasses, but overriding the default behavior is always encouraged.
91       */
92      protected boolean isKeepAliveChanged() {
93          return true;
94      }
95  
96      /**
97       * Returns <tt>true</tt> if and only if the <tt>oobInline</tt> property
98       * has been changed by its setter method.  The system call related with
99       * the property is made only when this method returns <tt>true</tt>.  By
100      * default, this method always returns <tt>true</tt> to simplify implementation
101      * of subclasses, but overriding the default behavior is always encouraged.
102      */
103     protected boolean isOobInlineChanged() {
104         return true;
105     }
106 
107     /**
108      * Returns <tt>true</tt> if and only if the <tt>receiveBufferSize</tt> property
109      * has been changed by its setter method.  The system call related with
110      * the property is made only when this method returns <tt>true</tt>.  By
111      * default, this method always returns <tt>true</tt> to simplify implementation
112      * of subclasses, but overriding the default behavior is always encouraged.
113      */
114     protected boolean isReceiveBufferSizeChanged() {
115         return true;
116     }
117     
118     /**
119      * Returns <tt>true</tt> if and only if the <tt>reuseAddress</tt> property
120      * has been changed by its setter method.  The system call related with
121      * the property is made only when this method returns <tt>true</tt>.  By
122      * default, this method always returns <tt>true</tt> to simplify implementation
123      * of subclasses, but overriding the default behavior is always encouraged.
124      */
125     protected boolean isReuseAddressChanged() {
126         return true;
127     }
128     
129     /**
130      * Returns <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property
131      * has been changed by its setter method.  The system call related with
132      * the property is made only when this method returns <tt>true</tt>.  By
133      * default, this method always returns <tt>true</tt> to simplify implementation
134      * of subclasses, but overriding the default behavior is always encouraged.
135      */
136     protected boolean isSendBufferSizeChanged() {
137         return true;
138     }
139     
140     /**
141      * Returns <tt>true</tt> if and only if the <tt>soLinger</tt> property
142      * has been changed by its setter method.  The system call related with
143      * the property is made only when this method returns <tt>true</tt>.  By
144      * default, this method always returns <tt>true</tt> to simplify implementation
145      * of subclasses, but overriding the default behavior is always encouraged.
146      */
147     protected boolean isSoLingerChanged() {
148         return true;
149     }
150     
151     /**
152      * Returns <tt>true</tt> if and only if the <tt>tcpNoDelay</tt> property
153      * has been changed by its setter method.  The system call related with
154      * the property is made only when this method returns <tt>true</tt>.  By
155      * default, this method always returns <tt>true</tt> to simplify implementation
156      * of subclasses, but overriding the default behavior is always encouraged.
157      */
158     protected boolean isTcpNoDelayChanged() {
159         return true;
160     }
161     
162     /**
163      * Returns <tt>true</tt> if and only if the <tt>trafficClass</tt> property
164      * has been changed by its setter method.  The system call related with
165      * the property is made only when this method returns <tt>true</tt>.  By
166      * default, this method always returns <tt>true</tt> to simplify implementation
167      * of subclasses, but overriding the default behavior is always encouraged.
168      */
169     protected boolean isTrafficClassChanged() {
170         return true;
171     }
172 }