1. /*
  2. * @(#)LocalClientRequestDispatcherBase.java 1.15 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.portable.ServantObject;
  9. import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
  10. import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
  11. import com.sun.corba.se.spi.orb.ORB;
  12. import com.sun.corba.se.spi.ior.IOR ;
  13. import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
  14. import com.sun.corba.se.spi.ior.ObjectAdapterId;
  15. import com.sun.corba.se.spi.ior.TaggedProfile;
  16. import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
  17. import com.sun.corba.se.spi.ior.ObjectId;
  18. public abstract class LocalClientRequestDispatcherBase implements LocalClientRequestDispatcher
  19. {
  20. protected ORB orb;
  21. int scid;
  22. // Cached information needed for local dispatch
  23. protected boolean servantIsLocal ;
  24. protected ObjectAdapterFactory oaf ;
  25. protected ObjectAdapterId oaid ;
  26. protected byte[] objectId ;
  27. // If isNextIsLocalValid.get() == Boolean.TRUE,
  28. // the next call to isLocal should be valid
  29. protected static ThreadLocal isNextCallValid = new ThreadLocal() {
  30. protected synchronized Object initialValue() {
  31. return Boolean.TRUE;
  32. }
  33. };
  34. protected LocalClientRequestDispatcherBase(ORB orb, int scid, IOR ior)
  35. {
  36. this.orb = orb ;
  37. TaggedProfile prof = ior.getProfile() ;
  38. servantIsLocal = orb.getORBData().isLocalOptimizationAllowed() &&
  39. prof.isLocal();
  40. ObjectKeyTemplate oktemp = prof.getObjectKeyTemplate() ;
  41. this.scid = oktemp.getSubcontractId() ;
  42. RequestDispatcherRegistry sreg = orb.getRequestDispatcherRegistry() ;
  43. oaf = sreg.getObjectAdapterFactory( scid ) ;
  44. oaid = oktemp.getObjectAdapterId() ;
  45. ObjectId oid = prof.getObjectId() ;
  46. objectId = oid.getId() ;
  47. }
  48. public byte[] getObjectId()
  49. {
  50. return objectId ;
  51. }
  52. public boolean is_local(org.omg.CORBA.Object self)
  53. {
  54. return false;
  55. }
  56. /*
  57. * Possible paths through
  58. * useLocalInvocation/servant_preinvoke/servant_postinvoke:
  59. *
  60. * A: call useLocalInvocation
  61. * If useLocalInvocation returns false, servant_preinvoke is not called.
  62. * If useLocalInvocation returns true,
  63. * call servant_preinvoke
  64. * If servant_preinvoke returns null,
  65. * goto A
  66. * else
  67. * (local invocation proceeds normally)
  68. * servant_postinvoke is called
  69. *
  70. */
  71. public boolean useLocalInvocation( org.omg.CORBA.Object self )
  72. {
  73. if (isNextCallValid.get() == Boolean.TRUE)
  74. return servantIsLocal ;
  75. else
  76. isNextCallValid.set( Boolean.TRUE ) ;
  77. return false ;
  78. }
  79. /** Check that the servant in info (which must not be null) is
  80. * an instance of the expectedType. If not, set the thread local flag
  81. * and return false.
  82. */
  83. protected boolean checkForCompatibleServant( ServantObject so,
  84. Class expectedType )
  85. {
  86. if (so == null)
  87. return false ;
  88. // Normally, this test will never fail. However, if the servant
  89. // and the stub were loaded in different class loaders, this test
  90. // will fail.
  91. if (!expectedType.isInstance( so.servant )) {
  92. isNextCallValid.set( Boolean.FALSE ) ;
  93. // When servant_preinvoke returns null, the stub will
  94. // recursively re-invoke itself. Thus, the next call made from
  95. // the stub is another useLocalInvocation call.
  96. return false ;
  97. }
  98. return true ;
  99. }
  100. }
  101. // End of file.