1. /*
  2. * @(#)POAPolicyMediatorBase.java 1.42 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.impl.oa.poa ;
  8. import java.util.Collection;
  9. import java.util.Enumeration ;
  10. import org.omg.PortableServer.Servant ;
  11. import org.omg.PortableServer.ForwardRequest ;
  12. import org.omg.PortableServer.POAPackage.WrongPolicy ;
  13. import com.sun.corba.se.spi.extension.ServantCachingPolicy ;
  14. import com.sun.corba.se.spi.orb.ORB ;
  15. import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
  16. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  17. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  18. import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
  19. /** Implementation of POARequesHandler that provides policy specific
  20. * operations on the POA.
  21. */
  22. public abstract class POAPolicyMediatorBase implements POAPolicyMediator {
  23. protected POAImpl poa ;
  24. protected ORB orb ;
  25. private int sysIdCounter ;
  26. private Policies policies ;
  27. private DelegateImpl delegateImpl ;
  28. private int serverid ;
  29. private int scid ;
  30. protected boolean isImplicit ;
  31. protected boolean isUnique ;
  32. protected boolean isSystemId ;
  33. public final Policies getPolicies()
  34. {
  35. return policies ;
  36. }
  37. public final int getScid()
  38. {
  39. return scid ;
  40. }
  41. public final int getServerId()
  42. {
  43. return serverid ;
  44. }
  45. POAPolicyMediatorBase( Policies policies, POAImpl poa )
  46. {
  47. if (policies.isSingleThreaded())
  48. throw poa.invocationWrapper().singleThreadNotSupported() ;
  49. POAManagerImpl poam = (POAManagerImpl)(poa.the_POAManager()) ;
  50. POAFactory poaf = poam.getFactory() ;
  51. delegateImpl = (DelegateImpl)(poaf.getDelegateImpl()) ;
  52. this.policies = policies ;
  53. this.poa = poa ;
  54. orb = (ORB)poa.getORB() ;
  55. switch (policies.servantCachingLevel()) {
  56. case ServantCachingPolicy.NO_SERVANT_CACHING :
  57. scid = ORBConstants.TRANSIENT_SCID ;
  58. break ;
  59. case ServantCachingPolicy.FULL_SEMANTICS :
  60. scid = ORBConstants.SC_TRANSIENT_SCID ;
  61. break ;
  62. case ServantCachingPolicy.INFO_ONLY_SEMANTICS :
  63. scid = ORBConstants.IISC_TRANSIENT_SCID ;
  64. break ;
  65. case ServantCachingPolicy.MINIMAL_SEMANTICS :
  66. scid = ORBConstants.MINSC_TRANSIENT_SCID ;
  67. break ;
  68. }
  69. if ( policies.isTransient() ) {
  70. serverid = orb.getTransientServerId();
  71. } else {
  72. serverid = orb.getORBData().getPersistentServerId();
  73. scid = ORBConstants.makePersistent( scid ) ;
  74. }
  75. isImplicit = policies.isImplicitlyActivated() ;
  76. isUnique = policies.isUniqueIds() ;
  77. isSystemId = policies.isSystemAssignedIds() ;
  78. sysIdCounter = 0 ;
  79. }
  80. public final java.lang.Object getInvocationServant( byte[] id,
  81. String operation ) throws ForwardRequest
  82. {
  83. java.lang.Object result = internalGetServant( id, operation ) ;
  84. return result ;
  85. }
  86. // Create a delegate and stick it in the servant.
  87. // This delegate is needed during dispatch for the ObjectImpl._orb()
  88. // method to work.
  89. protected final void setDelegate(Servant servant, byte[] id)
  90. {
  91. //This new servant delegate no longer needs the id for
  92. // its initialization.
  93. servant._set_delegate(delegateImpl);
  94. }
  95. public synchronized byte[] newSystemId() throws WrongPolicy
  96. {
  97. if (!isSystemId)
  98. throw new WrongPolicy() ;
  99. byte[] array = new byte[8];
  100. ORBUtility.intToBytes(++sysIdCounter, array, 0);
  101. ORBUtility.intToBytes( poa.getPOAId(), array, 4);
  102. return array;
  103. }
  104. protected abstract java.lang.Object internalGetServant( byte[] id,
  105. String operation ) throws ForwardRequest ;
  106. }