KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > RequestDispatcherRegistryImpl


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
8 package com.sun.corba.se.impl.protocol;
9
10 import java.util.Set JavaDoc;
11 import java.util.HashSet JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import java.util.Collections JavaDoc;
15
16 import com.sun.corba.se.pept.protocol.ClientRequestDispatcher ;
17
18 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ;
19 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory ;
20 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
21 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
22
23 import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
24
25 import com.sun.corba.se.spi.orb.ORB ;
26
27 import com.sun.corba.se.impl.orbutil.ORBConstants ;
28 import com.sun.corba.se.impl.orbutil.DenseIntMapImpl ;
29
30 /**
31  * This is a registry of all subcontract ID dependent objects. This includes:
32  * LocalClientRequestDispatcherFactory, ClientRequestDispatcher, ServerSubcontract, and
33  * ObjectAdapterFactory.
34  */

35 public class RequestDispatcherRegistryImpl implements RequestDispatcherRegistry {
36     private ORB orb;
37
38     protected int defaultId; // The default subcontract ID to use if
39
// there is no more specific ID available.
40
// This happens when invoking a foreign IOR.
41
private DenseIntMapImpl SDRegistry ; // ServerRequestDispatcher registry
42
private DenseIntMapImpl CSRegistry ; // ClientRequestDispatcher registry
43
private DenseIntMapImpl OAFRegistry ; // ObjectAdapterFactory registry
44
private DenseIntMapImpl LCSFRegistry ; // LocalClientRequestDispatcherFactory registry
45
private Set JavaDoc objectAdapterFactories ; // Set of all ObjectAdapterFactory instances
46
private Set JavaDoc objectAdapterFactoriesView ; // Read-only view of oaf instances
47
private Map JavaDoc stringToServerSubcontract ; // Map from obect key string to
48
// ServerSubcontract
49
// for special bootstrap IORs
50

51     public RequestDispatcherRegistryImpl(ORB orb, int defaultId )
52     {
53     this.orb = orb;
54         this.defaultId = defaultId;
55         SDRegistry = new DenseIntMapImpl() ;
56         CSRegistry = new DenseIntMapImpl() ;
57     OAFRegistry = new DenseIntMapImpl() ;
58     LCSFRegistry = new DenseIntMapImpl() ;
59     objectAdapterFactories = new HashSet JavaDoc() ;
60     objectAdapterFactoriesView = Collections.unmodifiableSet( objectAdapterFactories ) ;
61     stringToServerSubcontract = new HashMap JavaDoc() ;
62     }
63
64     public synchronized void registerClientRequestDispatcher(
65     ClientRequestDispatcher csc, int scid)
66     {
67     CSRegistry.set( scid, csc ) ;
68     }
69
70     public synchronized void registerLocalClientRequestDispatcherFactory(
71     LocalClientRequestDispatcherFactory csc, int scid)
72     {
73     LCSFRegistry.set( scid, csc ) ;
74     }
75
76     public synchronized void registerServerRequestDispatcher(
77     CorbaServerRequestDispatcher ssc, int scid)
78     {
79     SDRegistry.set( scid, ssc ) ;
80     }
81
82     public synchronized void registerServerRequestDispatcher(
83     CorbaServerRequestDispatcher scc, String JavaDoc name )
84     {
85     stringToServerSubcontract.put( name, scc ) ;
86     }
87
88     public synchronized void registerObjectAdapterFactory(
89     ObjectAdapterFactory oaf, int scid)
90     {
91     objectAdapterFactories.add( oaf ) ;
92     OAFRegistry.set( scid, oaf ) ;
93     }
94
95     // **************************************************
96
// Methods to find the subcontract side subcontract
97
// **************************************************
98

99     // Note that both forms of getServerRequestDispatcher need to return
100
// the default server delegate if no other match is found.
101
// This is essential to proper handling of errors for
102
// malformed requests. In particular, a bad MAGIC will
103
// result in a lookup in the named key table (stringToServerSubcontract),
104
// which must return a valid ServerRequestDispatcher. A bad subcontract ID
105
// will similarly need to return the default ServerRequestDispatcher.
106

107     public CorbaServerRequestDispatcher getServerRequestDispatcher(int scid)
108     {
109     CorbaServerRequestDispatcher sdel =
110         (CorbaServerRequestDispatcher)(SDRegistry.get(scid)) ;
111     if ( sdel == null )
112             sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ;
113
114     return sdel;
115     }
116
117     public CorbaServerRequestDispatcher getServerRequestDispatcher( String JavaDoc name )
118     {
119     CorbaServerRequestDispatcher sdel =
120         (CorbaServerRequestDispatcher)stringToServerSubcontract.get( name ) ;
121
122     if ( sdel == null )
123             sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ;
124
125     return sdel;
126     }
127
128     public LocalClientRequestDispatcherFactory getLocalClientRequestDispatcherFactory(
129     int scid )
130     {
131     LocalClientRequestDispatcherFactory factory =
132         (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(scid)) ;
133     if (factory == null) {
134         factory = (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(defaultId)) ;
135     }
136
137     return factory ;
138     }
139
140     public ClientRequestDispatcher getClientRequestDispatcher( int scid )
141     {
142     ClientRequestDispatcher subcontract =
143         (ClientRequestDispatcher)(CSRegistry.get(scid)) ;
144     if (subcontract == null) {
145         subcontract = (ClientRequestDispatcher)(CSRegistry.get(defaultId)) ;
146     }
147
148     return subcontract ;
149     }
150
151     public ObjectAdapterFactory getObjectAdapterFactory( int scid )
152     {
153     ObjectAdapterFactory oaf =
154             (ObjectAdapterFactory)(OAFRegistry.get(scid)) ;
155     if ( oaf == null )
156             oaf = (ObjectAdapterFactory)(OAFRegistry.get(defaultId)) ;
157
158     return oaf;
159     }
160
161     public Set JavaDoc getObjectAdapterFactories()
162     {
163     return objectAdapterFactoriesView ;
164     }
165 }
166
Popular Tags