1 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 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 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 76 public boolean isReuseAddress() { 77 return reuseAddress; 78 } 79 80 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 } 95 | Popular Tags |