KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > transport > CorbaContactInfoListImpl


1 /*
2  * @(#)CorbaContactInfoListImpl.java 1.37 05/05/27
3  *
4  * Copyright 2005 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.transport;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13
14 import com.sun.corba.se.pept.transport.ContactInfo;
15
16 import com.sun.corba.se.spi.ior.IOR ;
17 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
18 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
19 import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
20 import com.sun.corba.se.spi.orb.ORB;
21 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
22 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory;
23 import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
24 import com.sun.corba.se.spi.transport.SocketInfo;
25
26 import com.sun.corba.se.impl.orbutil.ORBConstants;
27 import com.sun.corba.se.impl.protocol.NotLocalLocalCRDImpl;
28
29 /**
30  * @author Harold Carr
31  */

32 public class CorbaContactInfoListImpl
33     implements
34     CorbaContactInfoList
35 {
36     protected ORB orb;
37     protected LocalClientRequestDispatcher LocalClientRequestDispatcher;
38     protected IOR targetIOR;
39     protected IOR effectiveTargetIOR;
40     protected List JavaDoc effectiveTargetIORContactInfoList;
41     protected ContactInfo primaryContactInfo;
42
43     // XREVISIT - is this used?
44
public CorbaContactInfoListImpl(ORB orb)
45     {
46     this.orb = orb;
47     }
48
49     public CorbaContactInfoListImpl(ORB orb, IOR targetIOR)
50     {
51     this(orb);
52     setTargetIOR(targetIOR);
53     }
54     
55     ////////////////////////////////////////////////////
56
//
57
// pept.transport.ContactInfoList
58
//
59

60     public synchronized Iterator JavaDoc iterator()
61     {
62     createContactInfoList();
63     return new CorbaContactInfoListIteratorImpl(
64             orb, this, primaryContactInfo,
65         effectiveTargetIORContactInfoList);
66     }
67
68     ////////////////////////////////////////////////////
69
//
70
// spi.transport.CorbaContactInfoList
71
//
72

73     public synchronized void setTargetIOR(IOR targetIOR)
74     {
75     this.targetIOR = targetIOR;
76     setEffectiveTargetIOR(targetIOR);
77     }
78
79     public synchronized IOR getTargetIOR()
80     {
81     return targetIOR;
82     }
83
84     public synchronized void setEffectiveTargetIOR(IOR effectiveTargetIOR)
85     {
86     this.effectiveTargetIOR = effectiveTargetIOR;
87     effectiveTargetIORContactInfoList = null;
88     if (primaryContactInfo != null &&
89         orb.getORBData().getIIOPPrimaryToContactInfo() != null)
90     {
91         orb.getORBData().getIIOPPrimaryToContactInfo()
92         .reset(primaryContactInfo);
93     }
94     primaryContactInfo = null;
95     setLocalSubcontract();
96     }
97
98     public synchronized IOR getEffectiveTargetIOR()
99     {
100     return effectiveTargetIOR;
101     }
102
103     public synchronized LocalClientRequestDispatcher getLocalClientRequestDispatcher()
104     {
105     return LocalClientRequestDispatcher;
106     }
107
108     ////////////////////////////////////////////////////
109
//
110
// org.omg.CORBA.portable.Delegate
111
//
112

113     // REVISIT - hashCode(org.omg.CORBA.Object self)
114

115     ////////////////////////////////////////////////////
116
//
117
// java.lang.Object
118
//
119

120     public synchronized int hashCode()
121     {
122         return targetIOR.hashCode();
123     }
124
125     ////////////////////////////////////////////////////
126
//
127
// Implementation
128
//
129

130     protected void createContactInfoList()
131     {
132     if (effectiveTargetIORContactInfoList != null) {
133         return;
134     }
135
136     effectiveTargetIORContactInfoList = new ArrayList JavaDoc();
137
138     IIOPProfile iiopProfile = effectiveTargetIOR.getProfile();
139     String JavaDoc hostname =
140         ((IIOPProfileTemplate)iiopProfile.getTaggedProfileTemplate())
141             .getPrimaryAddress().getHost().toLowerCase();
142     int port =
143         ((IIOPProfileTemplate)iiopProfile.getTaggedProfileTemplate())
144             .getPrimaryAddress().getPort();
145     // For use by "sticky manager" if one is registered.
146
primaryContactInfo =
147         createContactInfo(SocketInfo.IIOP_CLEAR_TEXT, hostname, port);
148
149     if (iiopProfile.isLocal()) {
150         // NOTE: IMPORTANT:
151
// Only do local. The APP Server interceptors check
152
// effectiveTarget.isLocal - which is determined via
153
// the IOR - so if we added other addresses then
154
// transactions and interceptors would not execute.
155
ContactInfo contactInfo = new SharedCDRContactInfoImpl(
156             orb, this, effectiveTargetIOR,
157         orb.getORBData().getGIOPAddressDisposition());
158         effectiveTargetIORContactInfoList.add(contactInfo);
159     } else {
160         addRemoteContactInfos(effectiveTargetIOR,
161                   effectiveTargetIORContactInfoList);
162     }
163     }
164
165     protected void addRemoteContactInfos(
166         IOR effectiveTargetIOR,
167     List JavaDoc effectiveTargetIORContactInfoList)
168     {
169     ContactInfo contactInfo;
170     List JavaDoc socketInfos = orb.getORBData()
171         .getIORToSocketInfo().getSocketInfo(effectiveTargetIOR);
172     Iterator JavaDoc iterator = socketInfos.iterator();
173     while (iterator.hasNext()) {
174         SocketInfo socketInfo = (SocketInfo) iterator.next();
175         String JavaDoc type = socketInfo.getType();
176         String JavaDoc host = socketInfo.getHost().toLowerCase();
177         int port = socketInfo.getPort();
178         contactInfo = createContactInfo(type, host, port);
179         effectiveTargetIORContactInfoList.add(contactInfo);
180     }
181     }
182
183     protected ContactInfo createContactInfo(String JavaDoc type,
184                         String JavaDoc hostname, int port)
185     {
186     return new SocketOrChannelContactInfoImpl(
187         orb, this,
188         // XREVISIT - See Base Line 62
189
effectiveTargetIOR,
190         orb.getORBData().getGIOPAddressDisposition(),
191         type, hostname, port);
192     }
193
194     /**
195      * setLocalSubcontract sets cached information that is set whenever
196      * the effectiveTargetIOR changes.
197      *
198      * Note: this must be maintained accurately whether or not the ORB
199      * allows local optimization, because ServantManagers in the POA
200      * ALWAYS use local optimization ONLY (they do not have a remote case).
201      */

202     protected void setLocalSubcontract()
203     {
204     if (!effectiveTargetIOR.getProfile().isLocal()) {
205         LocalClientRequestDispatcher = new NotLocalLocalCRDImpl();
206         return;
207     }
208
209     // XXX Note that this always uses the first IIOP profile to get the
210
// scid. What about multi-profile IORs? This should perhaps be
211
// tied to the current ContactInfo in some way, together with an
212
// implementation of ClientDelegate that generally prefers co-located
213
// ContactInfo. This may in fact mean that we should do this at
214
// the ContactInfo level, rather than the IOR/profile level.
215
int scid = effectiveTargetIOR.getProfile().getObjectKeyTemplate().
216         getSubcontractId() ;
217     LocalClientRequestDispatcherFactory lcsf = orb.getRequestDispatcherRegistry().getLocalClientRequestDispatcherFactory( scid ) ;
218     LocalClientRequestDispatcher = lcsf.create( scid, effectiveTargetIOR ) ;
219     }
220 }
221
222 // End of file.
223
Popular Tags