1. /*
  2. * @(#)POALocalCRDImpl.java 1.24 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.protocol;
  8. import org.omg.CORBA.SystemException;
  9. import org.omg.CORBA.OBJ_ADAPTER ;
  10. import org.omg.CORBA.UNKNOWN ;
  11. import org.omg.CORBA.CompletionStatus ;
  12. import org.omg.CORBA.portable.ServantObject;
  13. import com.sun.corba.se.pept.protocol.ClientRequestDispatcher;
  14. import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
  15. import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory;
  16. import com.sun.corba.se.spi.protocol.ForwardException ;
  17. import com.sun.corba.se.spi.oa.ObjectAdapter;
  18. import com.sun.corba.se.spi.oa.OAInvocationInfo ;
  19. import com.sun.corba.se.spi.oa.OADestroyed;
  20. import com.sun.corba.se.spi.orb.ORB;
  21. import com.sun.corba.se.spi.ior.IOR ;
  22. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  23. import com.sun.corba.se.impl.logging.POASystemException ;
  24. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  25. public class POALocalCRDImpl extends LocalClientRequestDispatcherBase
  26. {
  27. private ORBUtilSystemException wrapper ;
  28. private POASystemException poaWrapper ;
  29. public POALocalCRDImpl( ORB orb, int scid, IOR ior)
  30. {
  31. super( (com.sun.corba.se.spi.orb.ORB)orb, scid, ior );
  32. wrapper = ORBUtilSystemException.get( orb,
  33. CORBALogDomains.RPC_PROTOCOL ) ;
  34. poaWrapper = POASystemException.get( orb,
  35. CORBALogDomains.RPC_PROTOCOL ) ;
  36. }
  37. private OAInvocationInfo servantEnter( ObjectAdapter oa ) throws OADestroyed
  38. {
  39. oa.enter() ;
  40. OAInvocationInfo info = oa.makeInvocationInfo( objectId ) ;
  41. orb.pushInvocationInfo( info ) ;
  42. return info ;
  43. }
  44. private void servantExit( ObjectAdapter oa )
  45. {
  46. try {
  47. oa.returnServant();
  48. } finally {
  49. oa.exit() ;
  50. orb.popInvocationInfo() ;
  51. }
  52. }
  53. // Look up the servant for this request and return it in a
  54. // ServantObject. Note that servant_postinvoke is always called
  55. // by the stub UNLESS this method returns null. However, in all
  56. // cases we must be sure that ObjectAdapter.getServant and
  57. // ObjectAdapter.returnServant calls are paired, as required for
  58. // Portable Interceptors and Servant Locators in the POA.
  59. // Thus, this method must call returnServant if it returns null.
  60. public ServantObject servant_preinvoke(org.omg.CORBA.Object self,
  61. String operation,
  62. Class expectedType)
  63. {
  64. ObjectAdapter oa = oaf.find( oaid ) ;
  65. OAInvocationInfo info = null ;
  66. try {
  67. info = servantEnter( oa ) ;
  68. info.setOperation( operation ) ;
  69. } catch ( OADestroyed ex ) {
  70. // Destroyed POAs can be recreated by normal adapter activation.
  71. // So just reinvoke this method.
  72. return servant_preinvoke(self, operation, expectedType);
  73. }
  74. try {
  75. try {
  76. oa.getInvocationServant( info );
  77. if (!checkForCompatibleServant( info, expectedType ))
  78. return null ;
  79. } catch (Throwable thr) {
  80. // Cleanup after this call, then throw to allow
  81. // outer try to handle the exception appropriately.
  82. servantExit( oa ) ;
  83. throw thr ;
  84. }
  85. } catch ( ForwardException ex ) {
  86. /* REVISIT
  87. ClientRequestDispatcher csub = (ClientRequestDispatcher)
  88. StubAdapter.getDelegate( ex.forward_reference ) ;
  89. IOR ior = csub.getIOR() ;
  90. setLocatedIOR( ior ) ;
  91. */
  92. RuntimeException runexc = new RuntimeException("deal with this.");
  93. runexc.initCause( ex ) ;
  94. throw runexc ;
  95. } catch ( ThreadDeath ex ) {
  96. // ThreadDeath on the server side should not cause a client
  97. // side thread death in the local case. We want to preserve
  98. // this behavior for location transparency, so that a ThreadDeath
  99. // has the same affect in either the local or remote case.
  100. // The non-colocated case is handled in iiop.ORB.process, which
  101. // throws the same exception.
  102. throw wrapper.runtimeexception( ex ) ;
  103. } catch ( Throwable t ) {
  104. if (t instanceof SystemException)
  105. throw (SystemException)t ;
  106. throw poaWrapper.localServantLookup( t ) ;
  107. }
  108. if (!checkForCompatibleServant( info, expectedType )) {
  109. servantExit( oa ) ;
  110. return null ;
  111. }
  112. return info;
  113. }
  114. public void servant_postinvoke(org.omg.CORBA.Object self,
  115. ServantObject servantobj)
  116. {
  117. ObjectAdapter oa = orb.peekInvocationInfo().oa() ;
  118. servantExit( oa ) ;
  119. }
  120. }
  121. // End of file.