KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)LocalClientRequestDispatcherBase.java 1.15 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.portable.ServantObject JavaDoc;
11
12 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
13 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
14
15 import com.sun.corba.se.spi.orb.ORB;
16 import com.sun.corba.se.spi.ior.IOR ;
17 import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
18
19 import com.sun.corba.se.spi.ior.ObjectAdapterId;
20 import com.sun.corba.se.spi.ior.TaggedProfile;
21 import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
22 import com.sun.corba.se.spi.ior.ObjectId;
23
24 public abstract class LocalClientRequestDispatcherBase implements LocalClientRequestDispatcher
25 {
26     protected ORB orb;
27     int scid;
28
29     // Cached information needed for local dispatch
30
protected boolean servantIsLocal ;
31     protected ObjectAdapterFactory oaf ;
32     protected ObjectAdapterId oaid ;
33     protected byte[] objectId ;
34
35     // If isNextIsLocalValid.get() == Boolean.TRUE,
36
// the next call to isLocal should be valid
37
protected static ThreadLocal JavaDoc isNextCallValid = new ThreadLocal JavaDoc() {
38         protected synchronized Object JavaDoc initialValue() {
39         return Boolean.TRUE;
40         }
41     };
42
43     protected LocalClientRequestDispatcherBase(ORB orb, int scid, IOR ior)
44     {
45     this.orb = orb ;
46
47     TaggedProfile prof = ior.getProfile() ;
48     servantIsLocal = orb.getORBData().isLocalOptimizationAllowed() &&
49         prof.isLocal();
50
51     ObjectKeyTemplate oktemp = prof.getObjectKeyTemplate() ;
52     this.scid = oktemp.getSubcontractId() ;
53     RequestDispatcherRegistry sreg = orb.getRequestDispatcherRegistry() ;
54     oaf = sreg.getObjectAdapterFactory( scid ) ;
55     oaid = oktemp.getObjectAdapterId() ;
56     ObjectId oid = prof.getObjectId() ;
57     objectId = oid.getId() ;
58     }
59
60     public byte[] getObjectId()
61     {
62     return objectId ;
63     }
64
65     public boolean is_local(org.omg.CORBA.Object JavaDoc self)
66     {
67     return false;
68     }
69
70     /*
71     * Possible paths through
72     * useLocalInvocation/servant_preinvoke/servant_postinvoke:
73     *
74     * A: call useLocalInvocation
75     * If useLocalInvocation returns false, servant_preinvoke is not called.
76     * If useLocalInvocation returns true,
77     * call servant_preinvoke
78     * If servant_preinvoke returns null,
79     * goto A
80     * else
81     * (local invocation proceeds normally)
82     * servant_postinvoke is called
83     *
84     */

85     public boolean useLocalInvocation( org.omg.CORBA.Object JavaDoc self )
86     {
87     if (isNextCallValid.get() == Boolean.TRUE)
88         return servantIsLocal ;
89     else
90         isNextCallValid.set( Boolean.TRUE ) ;
91
92     return false ;
93     }
94
95     /** Check that the servant in info (which must not be null) is
96     * an instance of the expectedType. If not, set the thread local flag
97     * and return false.
98     */

99     protected boolean checkForCompatibleServant( ServantObject JavaDoc so,
100     Class JavaDoc expectedType )
101     {
102     if (so == null)
103         return false ;
104
105     // Normally, this test will never fail. However, if the servant
106
// and the stub were loaded in different class loaders, this test
107
// will fail.
108
if (!expectedType.isInstance( so.servant )) {
109         isNextCallValid.set( Boolean.FALSE ) ;
110
111         // When servant_preinvoke returns null, the stub will
112
// recursively re-invoke itself. Thus, the next call made from
113
// the stub is another useLocalInvocation call.
114
return false ;
115     }
116
117     return true ;
118     }
119
120 }
121
122 // End of file.
123
Popular Tags