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.nio;
21
22 import java.io.IOException;
23 import java.net.ServerSocket;
24
25 import org.apache.mina.common.ExceptionMonitor;
26 import org.apache.mina.common.IoAcceptorConfig;
27 import org.apache.mina.common.RuntimeIOException;
28 import org.apache.mina.common.support.BaseIoAcceptorConfig;
29
30 /**
31 * An {@link IoAcceptorConfig} for {@link SocketAcceptor}.
32 *
33 * @author The Apache Directory Project (mina-dev@directory.apache.org)
34 * @version $Rev: 587373 $, $Date: 2007-10-23 11:54:05 +0900 (Tue, 23 Oct 2007) $
35 */
36 public class SocketAcceptorConfig extends BaseIoAcceptorConfig {
37 private SocketSessionConfig sessionConfig = new SocketSessionConfigImpl();
38
39 private int backlog = 50;
40
41 private boolean reuseAddress;
42
43 /**
44 * Creates a new instance.
45 *
46 * @throws RuntimeIOException if failed to get the default configuration
47 */
48 public SocketAcceptorConfig() {
49 ServerSocket s = null;
50 try {
51 s = new ServerSocket();
52 reuseAddress = s.getReuseAddress();
53 } catch (IOException e) {
54 throw new RuntimeIOException(
55 "Failed to get the default configuration.", e);
56 } finally {
57 if (s != null) {
58 try {
59 s.close();
60 } catch (IOException e) {
61 ExceptionMonitor.getInstance().exceptionCaught(e);
62 }
63 }
64 }
65
66 sessionConfig.setReuseAddress(true);
67 }
68
69 public SocketSessionConfig getSessionConfig() {
70 return sessionConfig;
71 }
72
73 /**
74 * @see ServerSocket#getReuseAddress()
75 */
76 public boolean isReuseAddress() {
77 return reuseAddress;
78 }
79
80 /**
81 * @see ServerSocket#setReuseAddress(boolean)
82 */
83 public void setReuseAddress(boolean reuseAddress) {
84 this.reuseAddress = reuseAddress;
85 }
86
87 public int getBacklog() {
88 return backlog;
89 }
90
91 public void setBacklog(int backlog) {
92 this.backlog = backlog;
93 }
94 }