KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > legacy > connection > DefaultSocketFactory


1 /*
2  * @(#)DefaultSocketFactory.java 1.22 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.impl.legacy.connection;
8
9 import java.io.IOException JavaDoc;
10 import java.net.InetSocketAddress JavaDoc;
11 import java.net.ServerSocket JavaDoc;
12 import java.net.Socket JavaDoc;
13 import java.net.UnknownHostException JavaDoc;
14 import java.nio.channels.ServerSocketChannel JavaDoc;
15 import java.nio.channels.SocketChannel JavaDoc;
16
17 import org.omg.CORBA.ORB JavaDoc;
18 import org.omg.CORBA.COMM_FAILURE JavaDoc;
19 import org.omg.CORBA.CompletionStatus JavaDoc;
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 JavaDoc createServerSocket(String JavaDoc type, int port)
51     throws
52         IOException JavaDoc
53     {
54     if (! type.equals(ORBSocketFactory.IIOP_CLEAR_TEXT)) {
55         throw wrapper.defaultCreateServerSocketGivenNonIiopClearText( type ) ;
56     }
57
58     ServerSocket JavaDoc serverSocket;
59
60     if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) {
61         ServerSocketChannel JavaDoc serverSocketChannel =
62         ServerSocketChannel.open();
63         serverSocket = serverSocketChannel.socket();
64     } else {
65         serverSocket = new ServerSocket JavaDoc();
66     }
67     serverSocket.bind(new InetSocketAddress JavaDoc(port));
68     return serverSocket;
69     }
70
71     public SocketInfo getEndPointInfo(ORB JavaDoc 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 JavaDoc createSocket(SocketInfo socketInfo)
85     throws
86         IOException JavaDoc,
87         GetEndPointInfoAgainException
88     {
89     Socket JavaDoc socket;
90
91     if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) {
92         InetSocketAddress JavaDoc address =
93         new InetSocketAddress JavaDoc(socketInfo.getHost(),
94                       socketInfo.getPort());
95         SocketChannel JavaDoc socketChannel = SocketChannel.open(address);
96         socket = socketChannel.socket();
97     } else {
98         socket = new Socket JavaDoc(socketInfo.getHost(),
99                 socketInfo.getPort());
100     }
101
102     // REVISIT - this is done in SocketOrChannelConnectionImpl
103
try {
104         socket.setTcpNoDelay(true);
105     } catch (Exception JavaDoc e) {
106         ;
107     }
108     return socket;
109     }
110 }
111
112 // End of file.
113

114
Popular Tags