KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > POALocalCRDImpl


1 /*
2  * @(#)POALocalCRDImpl.java 1.24 03/12/19
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.protocol;
9
10 import org.omg.CORBA.SystemException JavaDoc;
11 import org.omg.CORBA.OBJ_ADAPTER JavaDoc ;
12 import org.omg.CORBA.UNKNOWN JavaDoc ;
13 import org.omg.CORBA.CompletionStatus JavaDoc ;
14
15 import org.omg.CORBA.portable.ServantObject JavaDoc;
16
17 import com.sun.corba.se.pept.protocol.ClientRequestDispatcher;
18
19 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
20 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory;
21 import com.sun.corba.se.spi.protocol.ForwardException ;
22
23 import com.sun.corba.se.spi.oa.ObjectAdapter;
24 import com.sun.corba.se.spi.oa.OAInvocationInfo ;
25 import com.sun.corba.se.spi.oa.OADestroyed;
26
27 import com.sun.corba.se.spi.orb.ORB;
28
29 import com.sun.corba.se.spi.ior.IOR ;
30
31 import com.sun.corba.se.spi.logging.CORBALogDomains ;
32
33 import com.sun.corba.se.impl.logging.POASystemException ;
34 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
35
36 public class POALocalCRDImpl extends LocalClientRequestDispatcherBase
37 {
38     private ORBUtilSystemException wrapper ;
39     private POASystemException poaWrapper ;
40
41     public POALocalCRDImpl( ORB orb, int scid, IOR ior)
42     {
43     super( (com.sun.corba.se.spi.orb.ORB)orb, scid, ior );
44     wrapper = ORBUtilSystemException.get( orb,
45         CORBALogDomains.RPC_PROTOCOL ) ;
46     poaWrapper = POASystemException.get( orb,
47         CORBALogDomains.RPC_PROTOCOL ) ;
48     }
49
50     private OAInvocationInfo servantEnter( ObjectAdapter oa ) throws OADestroyed
51     {
52     oa.enter() ;
53
54     OAInvocationInfo info = oa.makeInvocationInfo( objectId ) ;
55     orb.pushInvocationInfo( info ) ;
56
57     return info ;
58     }
59
60     private void servantExit( ObjectAdapter oa )
61     {
62     try {
63         oa.returnServant();
64     } finally {
65         oa.exit() ;
66         orb.popInvocationInfo() ;
67     }
68     }
69
70     // Look up the servant for this request and return it in a
71
// ServantObject. Note that servant_postinvoke is always called
72
// by the stub UNLESS this method returns null. However, in all
73
// cases we must be sure that ObjectAdapter.getServant and
74
// ObjectAdapter.returnServant calls are paired, as required for
75
// Portable Interceptors and Servant Locators in the POA.
76
// Thus, this method must call returnServant if it returns null.
77
public ServantObject JavaDoc servant_preinvoke(org.omg.CORBA.Object JavaDoc self,
78                                            String JavaDoc operation,
79                                            Class JavaDoc expectedType)
80     {
81     ObjectAdapter oa = oaf.find( oaid ) ;
82     OAInvocationInfo info = null ;
83
84     try {
85         info = servantEnter( oa ) ;
86         info.setOperation( operation ) ;
87         } catch ( OADestroyed ex ) {
88             // Destroyed POAs can be recreated by normal adapter activation.
89
// So just reinvoke this method.
90
return servant_preinvoke(self, operation, expectedType);
91     }
92
93         try {
94         try {
95         oa.getInvocationServant( info );
96         if (!checkForCompatibleServant( info, expectedType ))
97             return null ;
98         } catch (Throwable JavaDoc thr) {
99         // Cleanup after this call, then throw to allow
100
// outer try to handle the exception appropriately.
101
servantExit( oa ) ;
102         throw thr ;
103         }
104         } catch ( ForwardException ex ) {
105         /* REVISIT
106         ClientRequestDispatcher csub = (ClientRequestDispatcher)
107         StubAdapter.getDelegate( ex.forward_reference ) ;
108         IOR ior = csub.getIOR() ;
109         setLocatedIOR( ior ) ;
110         */

111         RuntimeException JavaDoc runexc = new RuntimeException JavaDoc("deal with this.");
112         runexc.initCause( ex ) ;
113         throw runexc ;
114         } catch ( ThreadDeath JavaDoc ex ) {
115         // ThreadDeath on the server side should not cause a client
116
// side thread death in the local case. We want to preserve
117
// this behavior for location transparency, so that a ThreadDeath
118
// has the same affect in either the local or remote case.
119
// The non-colocated case is handled in iiop.ORB.process, which
120
// throws the same exception.
121
throw wrapper.runtimeexception( ex ) ;
122         } catch ( Throwable JavaDoc t ) {
123             if (t instanceof SystemException JavaDoc)
124         throw (SystemException JavaDoc)t ;
125
126         throw poaWrapper.localServantLookup( t ) ;
127         }
128
129     if (!checkForCompatibleServant( info, expectedType )) {
130         servantExit( oa ) ;
131         return null ;
132     }
133
134         return info;
135     }
136
137     public void servant_postinvoke(org.omg.CORBA.Object JavaDoc self,
138                                    ServantObject JavaDoc servantobj)
139     {
140         ObjectAdapter oa = orb.peekInvocationInfo().oa() ;
141     servantExit( oa ) ;
142     }
143 }
144
145 // End of file.
146
Popular Tags