View Javadoc
1   /*
2    * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package com.sun.corba.se.spi.extension ;
27  
28  import org.omg.CORBA.Policy ;
29  import org.omg.CORBA.LocalObject ;
30  import com.sun.corba.se.impl.orbutil.ORBConstants ;
31  
32  /** Policy used to implement servant caching optimization in the POA.
33  * Creating a POA with an instance pol of this policy where
34  * pol.getType() > NO_SERVANT_CACHING will cause the servant to be
35  * looked up in the POA and cached in the LocalClientRequestDispatcher when
36  * the ClientRequestDispatcher is colocated with the implementation of the
37  * objref.  This greatly speeds up invocations at the cost of violating the
38  * POA semantics.  In particular, every request to a particular objref
39  * must be handled by the same servant.  Note that this is typically the
40  * case for EJB implementations.
41  * <p>
42  * If servant caching is used, there are two different additional
43  * features of the POA that are expensive:
44  * <ol>
45  * <li>POA current semantics
46  * <li>Proper handling of POA destroy.
47  * <ol>
48  * POA current semantics requires maintaining a ThreadLocal stack of
49  * invocation information that is always available for POACurrent operations.
50  * Maintaining this stack is expensive on the timescale of optimized co-located
51  * calls, so the option is provided to turn it off.  Similarly, causing
52  * POA.destroy() calls to wait for all active calls in the POA to complete
53  * requires careful tracking of the entry and exit of invocations in the POA.
54  * Again, tracking this is somewhat expensive.
55  */
56  public class ServantCachingPolicy extends LocalObject implements Policy
57  {
58      /** Do not cache servants in the ClientRequestDispatcher.  This will
59       * always support the full POA semantics, including changing the
60       * servant that handles requests on a particular objref.
61       */
62      public static final int NO_SERVANT_CACHING = 0 ;
63  
64      /** Perform servant caching, preserving POA current and POA destroy semantics.
65      * We will use this as the new default, as the app server is making heavier use
66      * now of POA facilities.
67      */
68      public static final int FULL_SEMANTICS = 1 ;
69  
70      /** Perform servant caching, preservent only POA current semantics.
71      * At least this level is required in order to support selection of ObjectCopiers
72      * for co-located RMI-IIOP calls, as the current copier is stored in
73      * OAInvocationInfo, which must be present on the stack inside the call.
74      */
75      public static final int INFO_ONLY_SEMANTICS =  2 ;
76  
77      /** Perform servant caching, not preserving POA current or POA destroy semantics.
78      */
79      public static final int MINIMAL_SEMANTICS = 3 ;
80  
81      private static ServantCachingPolicy policy = null ;
82      private static ServantCachingPolicy infoOnlyPolicy = null ;
83      private static ServantCachingPolicy minimalPolicy = null ;
84  
85      private int type ;
86  
87      public String typeToName()
88      {
89          switch (type) {
90              case FULL_SEMANTICS:
91                  return "FULL" ;
92              case INFO_ONLY_SEMANTICS:
93                  return "INFO_ONLY" ;
94              case MINIMAL_SEMANTICS:
95                  return "MINIMAL" ;
96              default:
97                  return "UNKNOWN(" + type + ")" ;
98          }
99      }
100 
101     public String toString()
102     {
103         return "ServantCachingPolicy[" + typeToName() + "]" ;
104     }
105 
106     private ServantCachingPolicy( int type )
107     {
108         this.type = type ;
109     }
110 
111     public int getType()
112     {
113         return type ;
114     }
115 
116     /** Return the default servant caching policy.
117     */
118     public synchronized static ServantCachingPolicy getPolicy()
119     {
120         return getFullPolicy() ;
121     }
122 
123     public synchronized static ServantCachingPolicy getFullPolicy()
124     {
125         if (policy == null)
126             policy = new ServantCachingPolicy( FULL_SEMANTICS ) ;
127 
128         return policy ;
129     }
130 
131     public synchronized static ServantCachingPolicy getInfoOnlyPolicy()
132     {
133         if (infoOnlyPolicy == null)
134             infoOnlyPolicy = new ServantCachingPolicy( INFO_ONLY_SEMANTICS ) ;
135 
136         return infoOnlyPolicy ;
137     }
138 
139     public synchronized static ServantCachingPolicy getMinimalPolicy()
140     {
141         if (minimalPolicy == null)
142             minimalPolicy = new ServantCachingPolicy( MINIMAL_SEMANTICS ) ;
143 
144         return minimalPolicy ;
145     }
146 
147     public int policy_type ()
148     {
149         return ORBConstants.SERVANT_CACHING_POLICY ;
150     }
151 
152     public org.omg.CORBA.Policy copy ()
153     {
154         return this ;
155     }
156 
157     public void destroy ()
158     {
159         // NO-OP
160     }
161 }