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.service.server;
21  
22  import org.apache.mina.api.IoServer;
23  import org.apache.mina.api.IoSessionConfig;
24  import org.apache.mina.service.AbstractIoService;
25  import org.apache.mina.service.executor.IoHandlerExecutor;
26  
27  /**
28   * Base implementation for {@link IoServer}s.
29   * 
30   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
31   */
32  public abstract class AbstractIoServer extends AbstractIoService implements IoServer {
33  
34      /**
35       * Create an new AbstractIoServer instance
36       * 
37       * @param eventExecutor used for executing IoHandler event in another pool of thread (not in the low level I/O one).
38       *        Use <code>null</code> if you don't want one. Be careful, the IoHandler processing will block the I/O
39       *        operations.
40       */
41      protected AbstractIoServer(IoSessionConfig config, IoHandlerExecutor eventExecutor) {
42          super(eventExecutor);
43          this.config = config;
44      }
45  
46      // does the reuse address flag should be positioned
47      private boolean reuseAddress = false;
48  
49      /**
50       * Set the reuse address flag on the server socket
51       * 
52       * @param reuseAddress <code>true</code> to enable
53       */
54      public void setReuseAddress(boolean reuseAddress) {
55          this.reuseAddress = reuseAddress;
56      }
57  
58      /**
59       * Is the reuse address enabled for this server.
60       * 
61       * @return
62       */
63      public boolean isReuseAddress() {
64          return this.reuseAddress;
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public IoSessionConfig getSessionConfig() {
72          return config;
73      }
74  
75      /**
76       * Set the default configuration for created TCP sessions
77       * 
78       * @param config
79       */
80      public void setSessionConfig(IoSessionConfig config) {
81          this.config = config;
82      }
83  }