KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > extension > ServantCachingPolicy


1 /*
2  * @(#)ServantCachingPolicy.java 1.5 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.spi.extension ;
9
10 import org.omg.CORBA.Policy JavaDoc ;
11 import org.omg.CORBA.LocalObject JavaDoc ;
12 import com.sun.corba.se.impl.orbutil.ORBConstants ;
13
14 /** Policy used to implement servant caching optimization in the POA.
15 * Creating a POA with an instance pol of this policy where
16 * pol.getType() > NO_SERVANT_CACHING will cause the servant to be
17 * looked up in the POA and cached in the LocalClientRequestDispatcher when
18 * the ClientRequestDispatcher is colocated with the implementation of the
19 * objref. This greatly speeds up invocations at the cost of violating the
20 * POA semantics. In particular, every request to a particular objref
21 * must be handled by the same servant. Note that this is typically the
22 * case for EJB implementations.
23 * <p>
24 * If servant caching is used, there are two different additional
25 * features of the POA that are expensive:
26 * <ol>
27 * <li>POA current semantics
28 * <li>Proper handling of POA destroy.
29 * <ol>
30 * POA current semantics requires maintaining a ThreadLocal stack of
31 * invocation information that is always available for POACurrent operations.
32 * Maintaining this stack is expensive on the timescale of optimized co-located
33 * calls, so the option is provided to turn it off. Similarly, causing
34 * POA.destroy() calls to wait for all active calls in the POA to complete
35 * requires careful tracking of the entry and exit of invocations in the POA.
36 * Again, tracking this is somewhat expensive.
37 */

38 public class ServantCachingPolicy extends LocalObject JavaDoc implements Policy JavaDoc
39 {
40     /** Do not cache servants in the ClientRequestDispatcher. This will
41      * always support the full POA semantics, including changing the
42      * servant that handles requests on a particular objref.
43      */

44     public static final int NO_SERVANT_CACHING = 0 ;
45
46     /** Perform servant caching, preserving POA current and POA destroy semantics.
47     * We will use this as the new default, as the app server is making heavier use
48     * now of POA facilities.
49     */

50     public static final int FULL_SEMANTICS = 1 ;
51
52     /** Perform servant caching, preservent only POA current semantics.
53     * At least this level is required in order to support selection of ObjectCopiers
54     * for co-located RMI-IIOP calls, as the current copier is stored in
55     * OAInvocationInfo, which must be present on the stack inside the call.
56     */

57     public static final int INFO_ONLY_SEMANTICS = 2 ;
58
59     /** Perform servant caching, not preserving POA current or POA destroy semantics.
60     */

61     public static final int MINIMAL_SEMANTICS = 3 ;
62
63     private static ServantCachingPolicy policy = null ;
64     private static ServantCachingPolicy infoOnlyPolicy = null ;
65     private static ServantCachingPolicy minimalPolicy = null ;
66
67     private int type ;
68     
69     public String JavaDoc typeToName()
70     {
71     switch (type) {
72         case FULL_SEMANTICS:
73         return "FULL" ;
74         case INFO_ONLY_SEMANTICS:
75         return "INFO_ONLY" ;
76         case MINIMAL_SEMANTICS:
77         return "MINIMAL" ;
78         default:
79         return "UNKNOWN(" + type + ")" ;
80     }
81     }
82
83     public String JavaDoc toString()
84     {
85     return "ServantCachingPolicy[" + typeToName() + "]" ;
86     }
87
88     private ServantCachingPolicy( int type )
89     {
90     this.type = type ;
91     }
92
93     public int getType()
94     {
95     return type ;
96     }
97
98     /** Return the default servant caching policy.
99     */

100     public synchronized static ServantCachingPolicy getPolicy()
101     {
102     return getFullPolicy() ;
103     }
104
105     public synchronized static ServantCachingPolicy getFullPolicy()
106     {
107     if (policy == null)
108         policy = new ServantCachingPolicy( FULL_SEMANTICS ) ;
109
110     return policy ;
111     }
112
113     public synchronized static ServantCachingPolicy getInfoOnlyPolicy()
114     {
115     if (infoOnlyPolicy == null)
116         infoOnlyPolicy = new ServantCachingPolicy( INFO_ONLY_SEMANTICS ) ;
117
118     return infoOnlyPolicy ;
119     }
120
121     public synchronized static ServantCachingPolicy getMinimalPolicy()
122     {
123     if (minimalPolicy == null)
124         minimalPolicy = new ServantCachingPolicy( MINIMAL_SEMANTICS ) ;
125
126     return minimalPolicy ;
127     }
128
129     public int policy_type ()
130     {
131     return ORBConstants.SERVANT_CACHING_POLICY ;
132     }
133
134     public org.omg.CORBA.Policy JavaDoc copy ()
135     {
136     return this ;
137     }
138
139     public void destroy ()
140     {
141     // NO-OP
142
}
143 }
144
Popular Tags