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. package com.sun.corba.se.spi.extension ;
  8. import org.omg.CORBA.Policy ;
  9. import org.omg.CORBA.LocalObject ;
  10. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  11. /** Policy used to implement servant caching optimization in the POA.
  12. * Creating a POA with an instance pol of this policy where
  13. * pol.getType() > NO_SERVANT_CACHING will cause the servant to be
  14. * looked up in the POA and cached in the LocalClientRequestDispatcher when
  15. * the ClientRequestDispatcher is colocated with the implementation of the
  16. * objref. This greatly speeds up invocations at the cost of violating the
  17. * POA semantics. In particular, every request to a particular objref
  18. * must be handled by the same servant. Note that this is typically the
  19. * case for EJB implementations.
  20. * <p>
  21. * If servant caching is used, there are two different additional
  22. * features of the POA that are expensive:
  23. * <ol>
  24. * <li>POA current semantics
  25. * <li>Proper handling of POA destroy.
  26. * <ol>
  27. * POA current semantics requires maintaining a ThreadLocal stack of
  28. * invocation information that is always available for POACurrent operations.
  29. * Maintaining this stack is expensive on the timescale of optimized co-located
  30. * calls, so the option is provided to turn it off. Similarly, causing
  31. * POA.destroy() calls to wait for all active calls in the POA to complete
  32. * requires careful tracking of the entry and exit of invocations in the POA.
  33. * Again, tracking this is somewhat expensive.
  34. */
  35. public class ServantCachingPolicy extends LocalObject implements Policy
  36. {
  37. /** Do not cache servants in the ClientRequestDispatcher. This will
  38. * always support the full POA semantics, including changing the
  39. * servant that handles requests on a particular objref.
  40. */
  41. public static final int NO_SERVANT_CACHING = 0 ;
  42. /** Perform servant caching, preserving POA current and POA destroy semantics.
  43. * We will use this as the new default, as the app server is making heavier use
  44. * now of POA facilities.
  45. */
  46. public static final int FULL_SEMANTICS = 1 ;
  47. /** Perform servant caching, preservent only POA current semantics.
  48. * At least this level is required in order to support selection of ObjectCopiers
  49. * for co-located RMI-IIOP calls, as the current copier is stored in
  50. * OAInvocationInfo, which must be present on the stack inside the call.
  51. */
  52. public static final int INFO_ONLY_SEMANTICS = 2 ;
  53. /** Perform servant caching, not preserving POA current or POA destroy semantics.
  54. */
  55. public static final int MINIMAL_SEMANTICS = 3 ;
  56. private static ServantCachingPolicy policy = null ;
  57. private static ServantCachingPolicy infoOnlyPolicy = null ;
  58. private static ServantCachingPolicy minimalPolicy = null ;
  59. private int type ;
  60. public String typeToName()
  61. {
  62. switch (type) {
  63. case FULL_SEMANTICS:
  64. return "FULL" ;
  65. case INFO_ONLY_SEMANTICS:
  66. return "INFO_ONLY" ;
  67. case MINIMAL_SEMANTICS:
  68. return "MINIMAL" ;
  69. default:
  70. return "UNKNOWN(" + type + ")" ;
  71. }
  72. }
  73. public String toString()
  74. {
  75. return "ServantCachingPolicy[" + typeToName() + "]" ;
  76. }
  77. private ServantCachingPolicy( int type )
  78. {
  79. this.type = type ;
  80. }
  81. public int getType()
  82. {
  83. return type ;
  84. }
  85. /** Return the default servant caching policy.
  86. */
  87. public synchronized static ServantCachingPolicy getPolicy()
  88. {
  89. return getFullPolicy() ;
  90. }
  91. public synchronized static ServantCachingPolicy getFullPolicy()
  92. {
  93. if (policy == null)
  94. policy = new ServantCachingPolicy( FULL_SEMANTICS ) ;
  95. return policy ;
  96. }
  97. public synchronized static ServantCachingPolicy getInfoOnlyPolicy()
  98. {
  99. if (infoOnlyPolicy == null)
  100. infoOnlyPolicy = new ServantCachingPolicy( INFO_ONLY_SEMANTICS ) ;
  101. return infoOnlyPolicy ;
  102. }
  103. public synchronized static ServantCachingPolicy getMinimalPolicy()
  104. {
  105. if (minimalPolicy == null)
  106. minimalPolicy = new ServantCachingPolicy( MINIMAL_SEMANTICS ) ;
  107. return minimalPolicy ;
  108. }
  109. public int policy_type ()
  110. {
  111. return ORBConstants.SERVANT_CACHING_POLICY ;
  112. }
  113. public org.omg.CORBA.Policy copy ()
  114. {
  115. return this ;
  116. }
  117. public void destroy ()
  118. {
  119. // NO-OP
  120. }
  121. }