1. /*
  2. * @(#)RequestDispatcherRegistryImpl.java 1.22 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 java.util.Set;
  9. import java.util.HashSet;
  10. import java.util.Map;
  11. import java.util.HashMap;
  12. import java.util.Collections;
  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.CorbaServerRequestDispatcher ;
  17. import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
  18. import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
  19. import com.sun.corba.se.spi.orb.ORB ;
  20. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  21. import com.sun.corba.se.impl.orbutil.DenseIntMapImpl ;
  22. /**
  23. * This is a registry of all subcontract ID dependent objects. This includes:
  24. * LocalClientRequestDispatcherFactory, ClientRequestDispatcher, ServerSubcontract, and
  25. * ObjectAdapterFactory.
  26. */
  27. public class RequestDispatcherRegistryImpl implements RequestDispatcherRegistry {
  28. private ORB orb;
  29. protected int defaultId; // The default subcontract ID to use if
  30. // there is no more specific ID available.
  31. // This happens when invoking a foreign IOR.
  32. private DenseIntMapImpl SDRegistry ; // ServerRequestDispatcher registry
  33. private DenseIntMapImpl CSRegistry ; // ClientRequestDispatcher registry
  34. private DenseIntMapImpl OAFRegistry ; // ObjectAdapterFactory registry
  35. private DenseIntMapImpl LCSFRegistry ; // LocalClientRequestDispatcherFactory registry
  36. private Set objectAdapterFactories ; // Set of all ObjectAdapterFactory instances
  37. private Set objectAdapterFactoriesView ; // Read-only view of oaf instances
  38. private Map stringToServerSubcontract ; // Map from obect key string to
  39. // ServerSubcontract
  40. // for special bootstrap IORs
  41. public RequestDispatcherRegistryImpl(ORB orb, int defaultId )
  42. {
  43. this.orb = orb;
  44. this.defaultId = defaultId;
  45. SDRegistry = new DenseIntMapImpl() ;
  46. CSRegistry = new DenseIntMapImpl() ;
  47. OAFRegistry = new DenseIntMapImpl() ;
  48. LCSFRegistry = new DenseIntMapImpl() ;
  49. objectAdapterFactories = new HashSet() ;
  50. objectAdapterFactoriesView = Collections.unmodifiableSet( objectAdapterFactories ) ;
  51. stringToServerSubcontract = new HashMap() ;
  52. }
  53. public synchronized void registerClientRequestDispatcher(
  54. ClientRequestDispatcher csc, int scid)
  55. {
  56. CSRegistry.set( scid, csc ) ;
  57. }
  58. public synchronized void registerLocalClientRequestDispatcherFactory(
  59. LocalClientRequestDispatcherFactory csc, int scid)
  60. {
  61. LCSFRegistry.set( scid, csc ) ;
  62. }
  63. public synchronized void registerServerRequestDispatcher(
  64. CorbaServerRequestDispatcher ssc, int scid)
  65. {
  66. SDRegistry.set( scid, ssc ) ;
  67. }
  68. public synchronized void registerServerRequestDispatcher(
  69. CorbaServerRequestDispatcher scc, String name )
  70. {
  71. stringToServerSubcontract.put( name, scc ) ;
  72. }
  73. public synchronized void registerObjectAdapterFactory(
  74. ObjectAdapterFactory oaf, int scid)
  75. {
  76. objectAdapterFactories.add( oaf ) ;
  77. OAFRegistry.set( scid, oaf ) ;
  78. }
  79. // **************************************************
  80. // Methods to find the subcontract side subcontract
  81. // **************************************************
  82. // Note that both forms of getServerRequestDispatcher need to return
  83. // the default server delegate if no other match is found.
  84. // This is essential to proper handling of errors for
  85. // malformed requests. In particular, a bad MAGIC will
  86. // result in a lookup in the named key table (stringToServerSubcontract),
  87. // which must return a valid ServerRequestDispatcher. A bad subcontract ID
  88. // will similarly need to return the default ServerRequestDispatcher.
  89. public CorbaServerRequestDispatcher getServerRequestDispatcher(int scid)
  90. {
  91. CorbaServerRequestDispatcher sdel =
  92. (CorbaServerRequestDispatcher)(SDRegistry.get(scid)) ;
  93. if ( sdel == null )
  94. sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ;
  95. return sdel;
  96. }
  97. public CorbaServerRequestDispatcher getServerRequestDispatcher( String name )
  98. {
  99. CorbaServerRequestDispatcher sdel =
  100. (CorbaServerRequestDispatcher)stringToServerSubcontract.get( name ) ;
  101. if ( sdel == null )
  102. sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ;
  103. return sdel;
  104. }
  105. public LocalClientRequestDispatcherFactory getLocalClientRequestDispatcherFactory(
  106. int scid )
  107. {
  108. LocalClientRequestDispatcherFactory factory =
  109. (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(scid)) ;
  110. if (factory == null) {
  111. factory = (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(defaultId)) ;
  112. }
  113. return factory ;
  114. }
  115. public ClientRequestDispatcher getClientRequestDispatcher( int scid )
  116. {
  117. ClientRequestDispatcher subcontract =
  118. (ClientRequestDispatcher)(CSRegistry.get(scid)) ;
  119. if (subcontract == null) {
  120. subcontract = (ClientRequestDispatcher)(CSRegistry.get(defaultId)) ;
  121. }
  122. return subcontract ;
  123. }
  124. public ObjectAdapterFactory getObjectAdapterFactory( int scid )
  125. {
  126. ObjectAdapterFactory oaf =
  127. (ObjectAdapterFactory)(OAFRegistry.get(scid)) ;
  128. if ( oaf == null )
  129. oaf = (ObjectAdapterFactory)(OAFRegistry.get(defaultId)) ;
  130. return oaf;
  131. }
  132. public Set getObjectAdapterFactories()
  133. {
  134. return objectAdapterFactoriesView ;
  135. }
  136. }