1. /*
  2. * @(#)TOAImpl.java 1.51 04/03/01
  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.toa ;
  8. import org.omg.CORBA.Policy ;
  9. import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
  10. import org.omg.PortableInterceptor.ObjectReferenceFactory ;
  11. import org.omg.PortableInterceptor.ACTIVE;
  12. import org.omg.PortableServer.ServantLocatorPackage.CookieHolder ;
  13. import com.sun.corba.se.pept.protocol.ClientDelegate ;
  14. import com.sun.corba.se.spi.copyobject.CopierManager ;
  15. import com.sun.corba.se.spi.copyobject.ObjectCopier ;
  16. import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
  17. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  18. import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  19. import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
  20. import com.sun.corba.se.spi.oa.OAInvocationInfo ;
  21. import com.sun.corba.se.spi.oa.OADestroyed ;
  22. import com.sun.corba.se.spi.oa.ObjectAdapterBase ;
  23. import com.sun.corba.se.spi.orb.ORB ;
  24. import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
  25. import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
  26. import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ;
  27. import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
  28. import com.sun.corba.se.impl.ior.JIDLObjectKeyTemplate ;
  29. import com.sun.corba.se.impl.oa.NullServantImpl;
  30. import com.sun.corba.se.impl.oa.poa.Policies;
  31. import com.sun.corba.se.impl.oa.toa.TransientObjectManager ;
  32. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  33. import com.sun.corba.se.impl.protocol.JIDLLocalCRDImpl ;
  34. /** The Transient Object Adapter (TOA) represents the OA for purely transient
  35. * objects. It is used for standard RMI-IIOP as well as backwards compatible
  36. * server support (i.e. the ORB.connect() method)
  37. * Its characteristics include:
  38. * <UL>
  39. * <LI>There is only one OA instance of the TOA. Its OAId is { "TOA" }</LI>
  40. * <LI>There is not adapter manager. The TOA manager ID is fixed.<LI>
  41. * <LI>State is the same as ORB state (TBD)</LI>
  42. * </UL>
  43. * Other requirements:
  44. * <UL>
  45. * <LI>All object adapters must invoke ORB.adapterCreated when they are created.
  46. * </LI>
  47. * <LI>All adapter managers must invoke ORB.adapterManagerStateChanged when
  48. * their state changes, mapping the internal state to an ORT state.</LI>
  49. * <LI>AdapterStateChanged must be invoked (from somewhere) whenever
  50. * an adapter state changes that is not due to an adapter manager state change.</LI>
  51. * </UL>
  52. */
  53. public class TOAImpl extends ObjectAdapterBase implements TOA
  54. {
  55. private TransientObjectManager servants ;
  56. public TOAImpl( ORB orb, TransientObjectManager tom, String codebase )
  57. {
  58. super( orb ) ;
  59. servants = tom ;
  60. // Make the object key template
  61. int serverid = ((ORB)getORB()).getTransientServerId();
  62. int scid = ORBConstants.TOA_SCID ;
  63. ObjectKeyTemplate oktemp = new JIDLObjectKeyTemplate( orb, scid, serverid ) ;
  64. // REVISIT - POA specific
  65. Policies policies = Policies.defaultPolicies;
  66. // REVISIT - absorb codebase into a policy
  67. initializeTemplate( oktemp, true,
  68. policies,
  69. codebase,
  70. null, // manager id
  71. oktemp.getObjectAdapterId()
  72. ) ;
  73. }
  74. // Methods required for dispatching requests
  75. public ObjectCopierFactory getObjectCopierFactory()
  76. {
  77. CopierManager cm = getORB().getCopierManager() ;
  78. return cm.getDefaultObjectCopierFactory() ;
  79. }
  80. public org.omg.CORBA.Object getLocalServant( byte[] objectId )
  81. {
  82. return (org.omg.CORBA.Object)(servants.lookupServant( objectId ) ) ;
  83. }
  84. /** Get the servant for the request given by the parameters.
  85. * This will update thread Current, so that subsequent calls to
  86. * returnServant and removeCurrent from the same thread are for the
  87. * same request.
  88. * @param request is the request containing the rest of the request
  89. */
  90. public void getInvocationServant( OAInvocationInfo info )
  91. {
  92. java.lang.Object servant = servants.lookupServant( info.id() ) ;
  93. if (servant == null)
  94. // This is expected to result in an RMI-IIOP NoSuchObjectException.
  95. // See bug 4973160.
  96. servant = new NullServantImpl( lifecycleWrapper().nullServant() ) ;
  97. info.setServant( servant ) ;
  98. }
  99. public void returnServant()
  100. {
  101. // NO-OP
  102. }
  103. /** Return the most derived interface for the given servant and objectId.
  104. */
  105. public String[] getInterfaces( Object servant, byte[] objectId )
  106. {
  107. return StubAdapter.getTypeIds( servant ) ;
  108. }
  109. // XXX For now, this does nothing.
  110. // This will need fixing once we support ORB and thread level policies,
  111. // but for now, there is no way to associate policies with the TOA, so
  112. // getEffectivePolicy must always return null.
  113. public Policy getEffectivePolicy( int type )
  114. {
  115. return null ;
  116. }
  117. public int getManagerId()
  118. {
  119. return -1 ;
  120. }
  121. public short getState()
  122. {
  123. return ACTIVE.value ;
  124. }
  125. public void enter() throws OADestroyed
  126. {
  127. }
  128. public void exit()
  129. {
  130. }
  131. // Methods unique to the TOA
  132. public void connect( org.omg.CORBA.Object objref)
  133. {
  134. // Store the objref and get a userkey allocated by the transient
  135. // object manager.
  136. byte[] key = servants.storeServant(objref, null);
  137. // Find out the repository ID for this objref.
  138. String id = StubAdapter.getTypeIds( objref )[0] ;
  139. // Create the new objref
  140. ObjectReferenceFactory orf = getCurrentFactory() ;
  141. org.omg.CORBA.Object obj = orf.make_object( id, key ) ;
  142. // Copy the delegate from the new objref to the argument
  143. // XXX handle the case of an attempt to connect a local object.
  144. org.omg.CORBA.portable.Delegate delegate = StubAdapter.getDelegate(
  145. obj ) ;
  146. CorbaContactInfoList ccil = (CorbaContactInfoList)
  147. ((ClientDelegate)delegate).getContactInfoList() ;
  148. LocalClientRequestDispatcher lcs =
  149. ccil.getLocalClientRequestDispatcher() ;
  150. if (lcs instanceof JIDLLocalCRDImpl) {
  151. JIDLLocalCRDImpl jlcs = (JIDLLocalCRDImpl)lcs ;
  152. jlcs.setServant( objref ) ;
  153. } else {
  154. throw new RuntimeException(
  155. "TOAImpl.connect can not be called on " + lcs ) ;
  156. }
  157. StubAdapter.setDelegate( objref, delegate ) ;
  158. }
  159. public void disconnect( org.omg.CORBA.Object objref )
  160. {
  161. // Get the delegate, then ior, then transientKey, then delete servant
  162. org.omg.CORBA.portable.Delegate del = StubAdapter.getDelegate(
  163. objref ) ;
  164. CorbaContactInfoList ccil = (CorbaContactInfoList)
  165. ((ClientDelegate)del).getContactInfoList() ;
  166. LocalClientRequestDispatcher lcs =
  167. ccil.getLocalClientRequestDispatcher() ;
  168. if (lcs instanceof JIDLLocalCRDImpl) {
  169. JIDLLocalCRDImpl jlcs = (JIDLLocalCRDImpl)lcs ;
  170. byte[] oid = jlcs.getObjectId() ;
  171. servants.deleteServant(oid);
  172. jlcs.unexport() ;
  173. } else {
  174. throw new RuntimeException(
  175. "TOAImpl.disconnect can not be called on " + lcs ) ;
  176. }
  177. }
  178. }