1 4 package com.tc.net.core; 5 6 import com.tc.net.TCSocketAddress; 7 import com.tc.net.core.event.TCConnectionEventListener; 8 import com.tc.net.protocol.ProtocolAdaptorFactory; 9 import com.tc.net.protocol.TCProtocolAdaptor; 10 11 import java.io.IOException ; 12 import java.net.InetSocketAddress ; 13 import java.net.ServerSocket ; 14 import java.nio.channels.ServerSocketChannel ; 15 16 21 class TCConnectionManagerJDK14 extends AbstractTCConnectionManager { 22 TCConnectionManagerJDK14(TCComm comm) { 23 super(comm); 24 25 if (comm != null) { 26 if (!(comm instanceof TCCommJDK14)) { throw new IllegalArgumentException ("Illegal TCComm instance type: " 27 + comm.getClass().getName()); } 28 } 29 } 30 31 protected TCConnection createConnectionImpl(TCProtocolAdaptor adaptor, TCConnectionEventListener listener) { 32 return new TCConnectionJDK14(listener, (TCCommJDK14) comm, adaptor, this); 33 } 34 35 protected TCListener createListenerImpl(TCSocketAddress addr, ProtocolAdaptorFactory factory, int backlog, boolean reuseAddr) 36 throws IOException { 37 ServerSocketChannel ssc = ServerSocketChannel.open(); 38 ssc.configureBlocking(false); 39 ServerSocket serverSocket = ssc.socket(); 40 serverSocket.setReuseAddress(reuseAddr); 41 serverSocket.setReceiveBufferSize(64 * 1024); 42 43 try { 44 serverSocket.bind(new InetSocketAddress (addr.getAddress(), addr.getPort()), backlog); 45 } catch (IOException ioe) { 46 logger.warn("Unable to bind socket on address " + addr.getAddress() + ", port " + addr.getPort() + ", " + ioe.getMessage()); 47 throw ioe; 48 } 49 50 if (logger.isDebugEnabled()) { 51 logger.debug("Bind: " + serverSocket.getLocalSocketAddress()); 52 } 53 54 TCListenerJDK14 rv = new TCListenerJDK14(ssc, factory, (TCCommJDK14) comm, getConnectionListener(), this); 55 ((TCCommJDK14) comm).requestAcceptInterest(rv, ssc); 56 57 return rv; 58 } 59 } | Popular Tags |