1 7 8 package com.sun.corba.se.impl.transport; 9 10 import java.io.IOException ; 11 import java.net.InetSocketAddress ; 12 import java.net.Socket ; 13 import java.net.SocketException ; 14 import java.net.ServerSocket ; 15 import java.nio.channels.SocketChannel ; 16 import java.nio.channels.ServerSocketChannel ; 17 18 import com.sun.corba.se.pept.transport.Acceptor; 19 20 import com.sun.corba.se.spi.orb.ORB; 21 import com.sun.corba.se.spi.transport.ORBSocketFactory; 22 23 import com.sun.corba.se.impl.orbutil.ORBConstants; 24 25 public class DefaultSocketFactoryImpl 26 implements ORBSocketFactory 27 { 28 private ORB orb; 29 30 public void setORB(ORB orb) 31 { 32 this.orb = orb; 33 } 34 35 public ServerSocket createServerSocket(String type, 36 InetSocketAddress inetSocketAddress) 37 throws IOException 38 { 39 ServerSocketChannel serverSocketChannel = null; 40 ServerSocket serverSocket = null; 41 42 if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) { 43 serverSocketChannel = ServerSocketChannel.open(); 44 serverSocket = serverSocketChannel.socket(); 45 } else { 46 serverSocket = new ServerSocket (); 47 } 48 serverSocket.bind(inetSocketAddress); 49 return serverSocket; 50 } 51 52 public Socket createSocket(String type, 53 InetSocketAddress inetSocketAddress) 54 throws IOException 55 { 56 SocketChannel socketChannel = null; 57 Socket socket = null; 58 59 if (orb.getORBData().connectionSocketType().equals(ORBConstants.SOCKETCHANNEL)) { 60 socketChannel = SocketChannel.open(inetSocketAddress); 61 socket = socketChannel.socket(); 62 } else { 63 socket = new Socket (inetSocketAddress.getHostName(), 64 inetSocketAddress.getPort()); 65 } 66 67 socket.setTcpNoDelay(true); 69 70 return socket; 71 } 72 73 public void setAcceptedSocketOptions(Acceptor acceptor, 74 ServerSocket serverSocket, 75 Socket socket) 76 throws SocketException 77 { 78 socket.setTcpNoDelay(true); 80 } 81 } 82 83 | Popular Tags |