001: /*
002: * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.corba.se.impl.protocol;
027:
028: import java.util.Set;
029: import java.util.HashSet;
030: import java.util.Map;
031: import java.util.HashMap;
032: import java.util.Collections;
033:
034: import com.sun.corba.se.pept.protocol.ClientRequestDispatcher;
035:
036: import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
037: import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory;
038: import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
039: import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
040:
041: import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
042:
043: import com.sun.corba.se.spi.orb.ORB;
044:
045: import com.sun.corba.se.impl.orbutil.ORBConstants;
046: import com.sun.corba.se.impl.orbutil.DenseIntMapImpl;
047:
048: /**
049: * This is a registry of all subcontract ID dependent objects. This includes:
050: * LocalClientRequestDispatcherFactory, ClientRequestDispatcher, ServerSubcontract, and
051: * ObjectAdapterFactory.
052: */
053: public class RequestDispatcherRegistryImpl implements
054: RequestDispatcherRegistry {
055: private ORB orb;
056:
057: protected int defaultId; // The default subcontract ID to use if
058: // there is no more specific ID available.
059: // This happens when invoking a foreign IOR.
060: private DenseIntMapImpl SDRegistry; // ServerRequestDispatcher registry
061: private DenseIntMapImpl CSRegistry; // ClientRequestDispatcher registry
062: private DenseIntMapImpl OAFRegistry; // ObjectAdapterFactory registry
063: private DenseIntMapImpl LCSFRegistry; // LocalClientRequestDispatcherFactory registry
064: private Set objectAdapterFactories; // Set of all ObjectAdapterFactory instances
065: private Set objectAdapterFactoriesView; // Read-only view of oaf instances
066: private Map stringToServerSubcontract; // Map from obect key string to
067:
068: // ServerSubcontract
069: // for special bootstrap IORs
070:
071: public RequestDispatcherRegistryImpl(ORB orb, int defaultId) {
072: this .orb = orb;
073: this .defaultId = defaultId;
074: SDRegistry = new DenseIntMapImpl();
075: CSRegistry = new DenseIntMapImpl();
076: OAFRegistry = new DenseIntMapImpl();
077: LCSFRegistry = new DenseIntMapImpl();
078: objectAdapterFactories = new HashSet();
079: objectAdapterFactoriesView = Collections
080: .unmodifiableSet(objectAdapterFactories);
081: stringToServerSubcontract = new HashMap();
082: }
083:
084: public synchronized void registerClientRequestDispatcher(
085: ClientRequestDispatcher csc, int scid) {
086: CSRegistry.set(scid, csc);
087: }
088:
089: public synchronized void registerLocalClientRequestDispatcherFactory(
090: LocalClientRequestDispatcherFactory csc, int scid) {
091: LCSFRegistry.set(scid, csc);
092: }
093:
094: public synchronized void registerServerRequestDispatcher(
095: CorbaServerRequestDispatcher ssc, int scid) {
096: SDRegistry.set(scid, ssc);
097: }
098:
099: public synchronized void registerServerRequestDispatcher(
100: CorbaServerRequestDispatcher scc, String name) {
101: stringToServerSubcontract.put(name, scc);
102: }
103:
104: public synchronized void registerObjectAdapterFactory(
105: ObjectAdapterFactory oaf, int scid) {
106: objectAdapterFactories.add(oaf);
107: OAFRegistry.set(scid, oaf);
108: }
109:
110: // **************************************************
111: // Methods to find the subcontract side subcontract
112: // **************************************************
113:
114: // Note that both forms of getServerRequestDispatcher need to return
115: // the default server delegate if no other match is found.
116: // This is essential to proper handling of errors for
117: // malformed requests. In particular, a bad MAGIC will
118: // result in a lookup in the named key table (stringToServerSubcontract),
119: // which must return a valid ServerRequestDispatcher. A bad subcontract ID
120: // will similarly need to return the default ServerRequestDispatcher.
121:
122: public CorbaServerRequestDispatcher getServerRequestDispatcher(
123: int scid) {
124: CorbaServerRequestDispatcher sdel = (CorbaServerRequestDispatcher) (SDRegistry
125: .get(scid));
126: if (sdel == null)
127: sdel = (CorbaServerRequestDispatcher) (SDRegistry
128: .get(defaultId));
129:
130: return sdel;
131: }
132:
133: public CorbaServerRequestDispatcher getServerRequestDispatcher(
134: String name) {
135: CorbaServerRequestDispatcher sdel = (CorbaServerRequestDispatcher) stringToServerSubcontract
136: .get(name);
137:
138: if (sdel == null)
139: sdel = (CorbaServerRequestDispatcher) (SDRegistry
140: .get(defaultId));
141:
142: return sdel;
143: }
144:
145: public LocalClientRequestDispatcherFactory getLocalClientRequestDispatcherFactory(
146: int scid) {
147: LocalClientRequestDispatcherFactory factory = (LocalClientRequestDispatcherFactory) (LCSFRegistry
148: .get(scid));
149: if (factory == null) {
150: factory = (LocalClientRequestDispatcherFactory) (LCSFRegistry
151: .get(defaultId));
152: }
153:
154: return factory;
155: }
156:
157: public ClientRequestDispatcher getClientRequestDispatcher(int scid) {
158: ClientRequestDispatcher subcontract = (ClientRequestDispatcher) (CSRegistry
159: .get(scid));
160: if (subcontract == null) {
161: subcontract = (ClientRequestDispatcher) (CSRegistry
162: .get(defaultId));
163: }
164:
165: return subcontract;
166: }
167:
168: public ObjectAdapterFactory getObjectAdapterFactory(int scid) {
169: ObjectAdapterFactory oaf = (ObjectAdapterFactory) (OAFRegistry
170: .get(scid));
171: if (oaf == null)
172: oaf = (ObjectAdapterFactory) (OAFRegistry.get(defaultId));
173:
174: return oaf;
175: }
176:
177: public Set getObjectAdapterFactories() {
178: return objectAdapterFactoriesView;
179: }
180: }
|