1 7 package com.sun.corba.se.impl.legacy.connection; 8 9 import java.io.IOException ; 10 import java.net.InetSocketAddress ; 11 import java.net.ServerSocket ; 12 import java.net.Socket ; 13 import java.net.UnknownHostException ; 14 import java.nio.channels.ServerSocketChannel ; 15 import java.nio.channels.SocketChannel ; 16 17 import org.omg.CORBA.ORB ; 18 import org.omg.CORBA.COMM_FAILURE ; 19 import org.omg.CORBA.CompletionStatus ; 20 21 import com.sun.corba.se.spi.ior.IOR; 22 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; 23 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; 24 import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException; 25 import com.sun.corba.se.spi.legacy.connection.ORBSocketFactory; 26 import com.sun.corba.se.spi.logging.CORBALogDomains; 27 import com.sun.corba.se.spi.transport.SocketInfo; 28 29 import com.sun.corba.se.impl.legacy.connection.EndPointInfoImpl; 30 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 31 import com.sun.corba.se.impl.orbutil.ORBConstants; 32 33 public class DefaultSocketFactory 34 implements 35 ORBSocketFactory 36 { 37 private com.sun.corba.se.spi.orb.ORB orb; 38 private static ORBUtilSystemException wrapper = ORBUtilSystemException.get( 39 CORBALogDomains.RPC_TRANSPORT ) ; 40 41 public DefaultSocketFactory() 42 { 43 } 44 45 public void setORB(com.sun.corba.se.spi.orb.ORB orb) 46 { 47 this.orb = orb; 48 } 49 50 public ServerSocket createServerSocket(String type, int port) 51 throws 52 IOException 53 { 54 if (! type.equals(ORBSocketFactory.IIOP_CLEAR_TEXT)) { 55 throw wrapper.defaultCreateServerSocketGivenNonIiopClearText( type ) ; 56 } 57 58 ServerSocket serverSocket; 59 60 if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) { 61 ServerSocketChannel serverSocketChannel = 62 ServerSocketChannel.open(); 63 serverSocket = serverSocketChannel.socket(); 64 } else { 65 serverSocket = new ServerSocket (); 66 } 67 serverSocket.bind(new InetSocketAddress (port)); 68 return serverSocket; 69 } 70 71 public SocketInfo getEndPointInfo(ORB orb, 72 IOR ior, 73 SocketInfo socketInfo) 74 { 75 IIOPProfileTemplate temp = 76 (IIOPProfileTemplate)ior.getProfile().getTaggedProfileTemplate() ; 77 IIOPAddress primary = temp.getPrimaryAddress() ; 78 79 return new EndPointInfoImpl(ORBSocketFactory.IIOP_CLEAR_TEXT, 80 primary.getPort(), 81 primary.getHost().toLowerCase()); 82 } 83 84 public Socket createSocket(SocketInfo socketInfo) 85 throws 86 IOException , 87 GetEndPointInfoAgainException 88 { 89 Socket socket; 90 91 if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) { 92 InetSocketAddress address = 93 new InetSocketAddress (socketInfo.getHost(), 94 socketInfo.getPort()); 95 SocketChannel socketChannel = SocketChannel.open(address); 96 socket = socketChannel.socket(); 97 } else { 98 socket = new Socket (socketInfo.getHost(), 99 socketInfo.getPort()); 100 } 101 102 try { 104 socket.setTcpNoDelay(true); 105 } catch (Exception e) { 106 ; 107 } 108 return socket; 109 } 110 } 111 112 114 | Popular Tags |