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