KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > oa > toa > TOAImpl


1 /*
2  * @(#)TOAImpl.java 1.51 04/03/01
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.oa.toa ;
9
10 import org.omg.CORBA.Policy JavaDoc ;
11 import org.omg.PortableInterceptor.ObjectReferenceTemplate JavaDoc ;
12 import org.omg.PortableInterceptor.ObjectReferenceFactory JavaDoc ;
13 import org.omg.PortableInterceptor.ACTIVE JavaDoc;
14 import org.omg.PortableServer.ServantLocatorPackage.CookieHolder JavaDoc ;
15
16 import com.sun.corba.se.pept.protocol.ClientDelegate ;
17
18 import com.sun.corba.se.spi.copyobject.CopierManager ;
19 import com.sun.corba.se.spi.copyobject.ObjectCopier ;
20 import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
21 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
22 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
23 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
24 import com.sun.corba.se.spi.oa.OAInvocationInfo ;
25 import com.sun.corba.se.spi.oa.OADestroyed ;
26 import com.sun.corba.se.spi.oa.ObjectAdapterBase ;
27 import com.sun.corba.se.spi.orb.ORB ;
28 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
29 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
30 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ;
31 import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
32
33 import com.sun.corba.se.impl.ior.JIDLObjectKeyTemplate ;
34 import com.sun.corba.se.impl.oa.NullServantImpl;
35 import com.sun.corba.se.impl.oa.poa.Policies;
36 import com.sun.corba.se.impl.oa.toa.TransientObjectManager ;
37 import com.sun.corba.se.impl.orbutil.ORBConstants ;
38 import com.sun.corba.se.impl.protocol.JIDLLocalCRDImpl ;
39
40 /** The Transient Object Adapter (TOA) represents the OA for purely transient
41 * objects. It is used for standard RMI-IIOP as well as backwards compatible
42 * server support (i.e. the ORB.connect() method)
43 * Its characteristics include:
44 * <UL>
45 * <LI>There is only one OA instance of the TOA. Its OAId is { "TOA" }</LI>
46 * <LI>There is not adapter manager. The TOA manager ID is fixed.<LI>
47 * <LI>State is the same as ORB state (TBD)</LI>
48 * </UL>
49 * Other requirements:
50 * <UL>
51 * <LI>All object adapters must invoke ORB.adapterCreated when they are created.
52 * </LI>
53 * <LI>All adapter managers must invoke ORB.adapterManagerStateChanged when
54 * their state changes, mapping the internal state to an ORT state.</LI>
55 * <LI>AdapterStateChanged must be invoked (from somewhere) whenever
56 * an adapter state changes that is not due to an adapter manager state change.</LI>
57 * </UL>
58 */

59 public class TOAImpl extends ObjectAdapterBase implements TOA
60 {
61     private TransientObjectManager servants ;
62
63     public TOAImpl( ORB orb, TransientObjectManager tom, String JavaDoc codebase )
64     {
65     super( orb ) ;
66     servants = tom ;
67
68     // Make the object key template
69
int serverid = ((ORB)getORB()).getTransientServerId();
70     int scid = ORBConstants.TOA_SCID ;
71
72     ObjectKeyTemplate oktemp = new JIDLObjectKeyTemplate( orb, scid, serverid ) ;
73
74     // REVISIT - POA specific
75
Policies policies = Policies.defaultPolicies;
76
77     // REVISIT - absorb codebase into a policy
78
initializeTemplate( oktemp, true,
79                 policies,
80                 codebase,
81                 null, // manager id
82
oktemp.getObjectAdapterId()
83                 ) ;
84     }
85
86     // Methods required for dispatching requests
87

88     public ObjectCopierFactory getObjectCopierFactory()
89     {
90     CopierManager cm = getORB().getCopierManager() ;
91     return cm.getDefaultObjectCopierFactory() ;
92     }
93
94     public org.omg.CORBA.Object JavaDoc getLocalServant( byte[] objectId )
95     {
96     return (org.omg.CORBA.Object JavaDoc)(servants.lookupServant( objectId ) ) ;
97     }
98
99     /** Get the servant for the request given by the parameters.
100     * This will update thread Current, so that subsequent calls to
101     * returnServant and removeCurrent from the same thread are for the
102     * same request.
103     * @param request is the request containing the rest of the request
104     */

105     public void getInvocationServant( OAInvocationInfo info )
106     {
107     java.lang.Object JavaDoc servant = servants.lookupServant( info.id() ) ;
108     if (servant == null)
109         // This is expected to result in an RMI-IIOP NoSuchObjectException.
110
// See bug 4973160.
111
servant = new NullServantImpl( lifecycleWrapper().nullServant() ) ;
112     info.setServant( servant ) ;
113     }
114
115     public void returnServant()
116     {
117     // NO-OP
118
}
119
120     /** Return the most derived interface for the given servant and objectId.
121     */

122     public String JavaDoc[] getInterfaces( Object JavaDoc servant, byte[] objectId )
123     {
124     return StubAdapter.getTypeIds( servant ) ;
125     }
126
127     // XXX For now, this does nothing.
128
// This will need fixing once we support ORB and thread level policies,
129
// but for now, there is no way to associate policies with the TOA, so
130
// getEffectivePolicy must always return null.
131
public Policy JavaDoc getEffectivePolicy( int type )
132     {
133     return null ;
134     }
135
136     public int getManagerId()
137     {
138     return -1 ;
139     }
140
141     public short getState()
142     {
143     return ACTIVE.value ;
144     }
145
146     public void enter() throws OADestroyed
147     {
148     }
149
150     public void exit()
151     {
152     }
153  
154     // Methods unique to the TOA
155

156     public void connect( org.omg.CORBA.Object JavaDoc objref)
157     {
158         // Store the objref and get a userkey allocated by the transient
159
// object manager.
160
byte[] key = servants.storeServant(objref, null);
161
162         // Find out the repository ID for this objref.
163
String JavaDoc id = StubAdapter.getTypeIds( objref )[0] ;
164
165     // Create the new objref
166
ObjectReferenceFactory JavaDoc orf = getCurrentFactory() ;
167     org.omg.CORBA.Object JavaDoc obj = orf.make_object( id, key ) ;
168
169     // Copy the delegate from the new objref to the argument
170
// XXX handle the case of an attempt to connect a local object.
171

172     org.omg.CORBA.portable.Delegate JavaDoc delegate = StubAdapter.getDelegate(
173         obj ) ;
174     CorbaContactInfoList ccil = (CorbaContactInfoList)
175         ((ClientDelegate)delegate).getContactInfoList() ;
176     LocalClientRequestDispatcher lcs =
177         ccil.getLocalClientRequestDispatcher() ;
178
179     if (lcs instanceof JIDLLocalCRDImpl) {
180         JIDLLocalCRDImpl jlcs = (JIDLLocalCRDImpl)lcs ;
181         jlcs.setServant( objref ) ;
182     } else {
183         throw new RuntimeException JavaDoc(
184         "TOAImpl.connect can not be called on " + lcs ) ;
185     }
186
187     StubAdapter.setDelegate( objref, delegate ) ;
188     }
189
190     public void disconnect( org.omg.CORBA.Object JavaDoc objref )
191     {
192         // Get the delegate, then ior, then transientKey, then delete servant
193
org.omg.CORBA.portable.Delegate JavaDoc del = StubAdapter.getDelegate(
194         objref ) ;
195     CorbaContactInfoList ccil = (CorbaContactInfoList)
196         ((ClientDelegate)del).getContactInfoList() ;
197     LocalClientRequestDispatcher lcs =
198         ccil.getLocalClientRequestDispatcher() ;
199
200     if (lcs instanceof JIDLLocalCRDImpl) {
201         JIDLLocalCRDImpl jlcs = (JIDLLocalCRDImpl)lcs ;
202         byte[] oid = jlcs.getObjectId() ;
203         servants.deleteServant(oid);
204         jlcs.unexport() ;
205     } else {
206         throw new RuntimeException JavaDoc(
207         "TOAImpl.disconnect can not be called on " + lcs ) ;
208     }
209     }
210 }
211
Popular Tags