KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SocketFactoryConnectionImpl.java 1.12 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
8 package com.sun.corba.se.impl.legacy.connection;
9
10 import java.net.Socket JavaDoc;
11 import java.nio.channels.SocketChannel JavaDoc;
12 import java.util.Collections JavaDoc;
13
14 import org.omg.CORBA.COMM_FAILURE JavaDoc;
15 import org.omg.CORBA.CompletionStatus JavaDoc;
16
17 import com.sun.corba.se.pept.transport.Acceptor;
18 import com.sun.corba.se.pept.transport.ContactInfo;
19
20 import com.sun.corba.se.spi.ior.IOR;
21 import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
22 import com.sun.corba.se.spi.orb.ORB;
23 import com.sun.corba.se.spi.transport.CorbaConnection;
24 import com.sun.corba.se.spi.transport.CorbaContactInfo;
25 import com.sun.corba.se.spi.transport.SocketInfo;
26
27 import com.sun.corba.se.impl.orbutil.ORBUtility;
28 import com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl;
29 import com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl;
30
31 /**
32  * @author Harold Carr
33  */

34 public class SocketFactoryConnectionImpl
35     extends
36     SocketOrChannelConnectionImpl
37 {
38     // Socket-factory client constructor.
39
public SocketFactoryConnectionImpl(ORB orb,
40                        CorbaContactInfo contactInfo,
41                        boolean useSelectThreadToWait,
42                        boolean useWorkerThread)
43     {
44     super(orb, useSelectThreadToWait, useWorkerThread);
45
46     // REVISIT - probably need a contact info for both
47
// client and server for removing connections from cache?
48
this.contactInfo = contactInfo;
49
50     boolean isBlocking = !useSelectThreadToWait;
51     SocketInfo socketInfo =
52         // REVISIT - case - needs interface method
53
((SocketFactoryContactInfoImpl)contactInfo).socketInfo;
54     try {
55         socket =
56         orb.getORBData().getLegacySocketFactory().createSocket(socketInfo);
57         socketChannel = socket.getChannel();
58         if (socketChannel != null) {
59         socketChannel.configureBlocking(isBlocking);
60         } else {
61         // IMPORTANT: non-channel-backed sockets must use
62
// dedicated reader threads.
63
setUseSelectThreadToWait(false);
64         }
65         if (orb.transportDebugFlag) {
66         dprint(".initialize: connection created: " + socket);
67         }
68     } catch (GetEndPointInfoAgainException ex) {
69         throw wrapper.connectFailure(
70                 ex, socketInfo.getType(), socketInfo.getHost(),
71         Integer.toString(socketInfo.getPort())) ;
72     } catch (Exception JavaDoc ex) {
73         throw wrapper.connectFailure(
74                 ex, socketInfo.getType(), socketInfo.getHost(),
75         Integer.toString(socketInfo.getPort())) ;
76     }
77     state = OPENING;
78     }
79
80     public String JavaDoc toString()
81     {
82         synchronized ( stateEvent ){
83             return
84         "SocketFactoryConnectionImpl[" + " "
85         + (socketChannel == null ?
86            socket.toString() : socketChannel.toString()) + " "
87         + getStateString( state ) + " "
88         + shouldUseSelectThreadToWait() + " "
89         + shouldUseWorkerThreadForEvent()
90         + "]" ;
91         }
92     }
93
94     // Note: public to override parent.
95
public void dprint(String JavaDoc msg)
96     {
97     ORBUtility.dprint("SocketFactoryConnectionImpl", msg);
98     }
99
100 }
101
102 // End of file.
103
Popular Tags