RequestDispatcherRegistryImpl.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.corba.se.impl.protocol; 27 28import java.util.Set; 29import java.util.HashSet; 30import java.util.Map; 31import java.util.HashMap; 32import java.util.Collections; 33 34import com.sun.corba.se.pept.protocol.ClientRequestDispatcher ; 35 36import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ; 37import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory ; 38import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ; 39import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ; 40 41import com.sun.corba.se.spi.oa.ObjectAdapterFactory ; 42 43import com.sun.corba.se.spi.orb.ORB ; 44 45import com.sun.corba.se.impl.orbutil.ORBConstants ; 46import com.sun.corba.se.impl.orbutil.DenseIntMapImpl ; 47 48/** 49 * This is a registry of all subcontract ID dependent objects. This includes: 50 * LocalClientRequestDispatcherFactory, ClientRequestDispatcher, ServerSubcontract, and 51 * ObjectAdapterFactory. 52 */ 53public class RequestDispatcherRegistryImpl implements RequestDispatcherRegistry { 54 private ORB orb; 55 56 protected int defaultId; // The default subcontract ID to use if 57 // there is no more specific ID available. 58 // This happens when invoking a foreign IOR. 59 private DenseIntMapImpl SDRegistry ; // ServerRequestDispatcher registry 60 private DenseIntMapImpl CSRegistry ; // ClientRequestDispatcher registry 61 private DenseIntMapImpl OAFRegistry ; // ObjectAdapterFactory registry 62 private DenseIntMapImpl LCSFRegistry ; // LocalClientRequestDispatcherFactory registry 63 private Set objectAdapterFactories ; // Set of all ObjectAdapterFactory instances 64 private Set objectAdapterFactoriesView ; // Read-only view of oaf instances 65 private Map stringToServerSubcontract ; // Map from obect key string to 66 // ServerSubcontract 67 // for special bootstrap IORs 68 69 public RequestDispatcherRegistryImpl(ORB orb, int defaultId ) 70 { 71 this.orb = orb; 72 this.defaultId = defaultId; 73 SDRegistry = new DenseIntMapImpl() ; 74 CSRegistry = new DenseIntMapImpl() ; 75 OAFRegistry = new DenseIntMapImpl() ; 76 LCSFRegistry = new DenseIntMapImpl() ; 77 objectAdapterFactories = new HashSet() ; 78 objectAdapterFactoriesView = Collections.unmodifiableSet( objectAdapterFactories ) ; 79 stringToServerSubcontract = new HashMap() ; 80 } 81 82 public synchronized void registerClientRequestDispatcher( 83 ClientRequestDispatcher csc, int scid) 84 { 85 CSRegistry.set( scid, csc ) ; 86 } 87 88 public synchronized void registerLocalClientRequestDispatcherFactory( 89 LocalClientRequestDispatcherFactory csc, int scid) 90 { 91 LCSFRegistry.set( scid, csc ) ; 92 } 93 94 public synchronized void registerServerRequestDispatcher( 95 CorbaServerRequestDispatcher ssc, int scid) 96 { 97 SDRegistry.set( scid, ssc ) ; 98 } 99 100 public synchronized void registerServerRequestDispatcher( 101 CorbaServerRequestDispatcher scc, String name ) 102 { 103 stringToServerSubcontract.put( name, scc ) ; 104 } 105 106 public synchronized void registerObjectAdapterFactory( 107 ObjectAdapterFactory oaf, int scid) 108 { 109 objectAdapterFactories.add( oaf ) ; 110 OAFRegistry.set( scid, oaf ) ; 111 } 112 113 // ************************************************** 114 // Methods to find the subcontract side subcontract 115 // ************************************************** 116 117 // Note that both forms of getServerRequestDispatcher need to return 118 // the default server delegate if no other match is found. 119 // This is essential to proper handling of errors for 120 // malformed requests. In particular, a bad MAGIC will 121 // result in a lookup in the named key table (stringToServerSubcontract), 122 // which must return a valid ServerRequestDispatcher. A bad subcontract ID 123 // will similarly need to return the default ServerRequestDispatcher. 124 125 public CorbaServerRequestDispatcher getServerRequestDispatcher(int scid) 126 { 127 CorbaServerRequestDispatcher sdel = 128 (CorbaServerRequestDispatcher)(SDRegistry.get(scid)) ; 129 if ( sdel == null ) 130 sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ; 131 132 return sdel; 133 } 134 135 public CorbaServerRequestDispatcher getServerRequestDispatcher( String name ) 136 { 137 CorbaServerRequestDispatcher sdel = 138 (CorbaServerRequestDispatcher)stringToServerSubcontract.get( name ) ; 139 140 if ( sdel == null ) 141 sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ; 142 143 return sdel; 144 } 145 146 public LocalClientRequestDispatcherFactory getLocalClientRequestDispatcherFactory( 147 int scid ) 148 { 149 LocalClientRequestDispatcherFactory factory = 150 (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(scid)) ; 151 if (factory == null) { 152 factory = (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(defaultId)) ; 153 } 154 155 return factory ; 156 } 157 158 public ClientRequestDispatcher getClientRequestDispatcher( int scid ) 159 { 160 ClientRequestDispatcher subcontract = 161 (ClientRequestDispatcher)(CSRegistry.get(scid)) ; 162 if (subcontract == null) { 163 subcontract = (ClientRequestDispatcher)(CSRegistry.get(defaultId)) ; 164 } 165 166 return subcontract ; 167 } 168 169 public ObjectAdapterFactory getObjectAdapterFactory( int scid ) 170 { 171 ObjectAdapterFactory oaf = 172 (ObjectAdapterFactory)(OAFRegistry.get(scid)) ; 173 if ( oaf == null ) 174 oaf = (ObjectAdapterFactory)(OAFRegistry.get(defaultId)) ; 175 176 return oaf; 177 } 178 179 public Set getObjectAdapterFactories() 180 { 181 return objectAdapterFactoriesView ; 182 } 183} 184