KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > orb > ORB


1 /*
2  * @(#)ORB.java 1.55 05/01/04
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.spi.orb;
9
10 import java.util.Map JavaDoc ;
11 import java.util.HashMap JavaDoc ;
12 import java.util.Properties JavaDoc ;
13 import java.util.concurrent.ConcurrentHashMap JavaDoc;
14 import java.util.logging.Logger JavaDoc ;
15
16 import java.security.AccessController JavaDoc ;
17 import java.security.PrivilegedAction JavaDoc ;
18
19 import org.omg.CORBA.TCKind JavaDoc ;
20
21 import com.sun.corba.se.pept.broker.Broker ;
22 import com.sun.corba.se.pept.transport.ByteBufferPool;
23
24 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
25 import com.sun.corba.se.spi.protocol.ClientDelegateFactory ;
26 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
27 import com.sun.corba.se.spi.protocol.CorbaMessageMediator ;
28 import com.sun.corba.se.spi.protocol.PIHandler ;
29 import com.sun.corba.se.spi.resolver.LocalResolver ;
30 import com.sun.corba.se.spi.resolver.Resolver ;
31 import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory ;
32 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
33 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
34 import com.sun.corba.se.spi.monitoring.MonitoringConstants;
35 import com.sun.corba.se.spi.monitoring.MonitoringManager;
36 import com.sun.corba.se.spi.monitoring.MonitoringManagerFactory;
37 import com.sun.corba.se.spi.monitoring.MonitoringFactories;
38
39 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
40 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder ;
41 import com.sun.corba.se.spi.ior.ObjectKey ;
42 import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
43 import com.sun.corba.se.spi.ior.IOR ;
44
45 import com.sun.corba.se.spi.orbutil.closure.Closure ;
46
47 import com.sun.corba.se.spi.orb.Operation ;
48 import com.sun.corba.se.spi.orb.ORBData ;
49 import com.sun.corba.se.spi.orb.ORBVersion ;
50 import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager;
51
52 import com.sun.corba.se.spi.oa.OAInvocationInfo ;
53 import com.sun.corba.se.spi.transport.CorbaTransportManager;
54
55 import com.sun.corba.se.spi.logging.LogWrapperFactory ;
56 import com.sun.corba.se.spi.logging.LogWrapperBase ;
57 import com.sun.corba.se.spi.logging.CORBALogDomains ;
58
59 import com.sun.corba.se.spi.copyobject.CopierManager ;
60
61 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ;
62 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ;
63
64 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry ;
65
66 // XXX needs an SPI or else it does not belong here
67
import com.sun.corba.se.impl.corba.TypeCodeImpl ;
68 import com.sun.corba.se.impl.corba.TypeCodeFactory ;
69
70 // XXX Should there be a SPI level constants ?
71
import com.sun.corba.se.impl.orbutil.ORBConstants ;
72
73 import com.sun.corba.se.impl.oa.poa.BadServerIdHandler ;
74
75 import com.sun.corba.se.impl.transport.ByteBufferPoolImpl;
76
77 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
78 import com.sun.corba.se.impl.logging.OMGSystemException ;
79
80 import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl ;
81
82 import com.sun.corba.se.impl.orbutil.ORBClassLoader ;
83
84 public abstract class ORB extends com.sun.corba.se.org.omg.CORBA.ORB
85     implements Broker, TypeCodeFactory
86 {
87     // As much as possible, this class should be stateless. However,
88
// there are a few reasons why it is not:
89
//
90
// 1. The ORB debug flags are defined here because they are accessed
91
// frequently, and we do not want a cast to the impl just for that.
92
// 2. typeCodeMap and primitiveTypeCodeConstants are here because they
93
// are needed in both ORBImpl and ORBSingleton.
94
// 3. Logging support is here so that we can avoid problems with
95
// incompletely initialized ORBs that need to perform logging.
96

97     // Flag set at compile time to debug flag processing: this can't
98
// be one of the xxxDebugFlags because it is used to debug the mechanism
99
// that sets the xxxDebugFlags!
100
public static boolean ORBInitDebug = false;
101
102     // Currently defined debug flags. Any additions must be called xxxDebugFlag.
103
// All debug flags must be public boolean types.
104
// These are set by passing the flag -ORBDebug x,y,z in the ORB init args.
105
// Note that x,y,z must not contain spaces.
106
public boolean transportDebugFlag = false ;
107     public boolean subcontractDebugFlag = false ;
108     public boolean poaDebugFlag = false ;
109     public boolean poaConcurrencyDebugFlag = false ;
110     public boolean poaFSMDebugFlag = false ;
111     public boolean orbdDebugFlag = false ;
112     public boolean namingDebugFlag = false ;
113     public boolean serviceContextDebugFlag = false ;
114     public boolean transientObjectManagerDebugFlag = false ;
115     public boolean giopVersionDebugFlag = false;
116     public boolean shutdownDebugFlag = false;
117     public boolean giopDebugFlag = false;
118     public boolean invocationTimingDebugFlag = false ;
119
120     // SystemException log wrappers. Protected so that they can be used in
121
// subclasses.
122
protected static ORBUtilSystemException staticWrapper ;
123     protected ORBUtilSystemException wrapper ;
124     protected OMGSystemException omgWrapper ;
125
126     // This map is needed for resolving recursive type code placeholders
127
// based on the unique repository id.
128
// XXX Should this be a WeakHashMap for GC?
129
private Map JavaDoc typeCodeMap ;
130
131     private TypeCodeImpl[] primitiveTypeCodeConstants ;
132
133     // ByteBufferPool - needed by both ORBImpl and ORBSingleton
134
ByteBufferPool byteBufferPool;
135
136     // Local testing
137
// XXX clean this up, probably remove these
138
public abstract boolean isLocalHost( String JavaDoc hostName ) ;
139     public abstract boolean isLocalServerId( int subcontractId, int serverId ) ;
140
141     // Invocation stack manipulation
142
public abstract OAInvocationInfo peekInvocationInfo() ;
143     public abstract void pushInvocationInfo( OAInvocationInfo info ) ;
144     public abstract OAInvocationInfo popInvocationInfo() ;
145
146     public abstract CorbaTransportManager getCorbaTransportManager();
147     public abstract LegacyServerSocketManager getLegacyServerSocketManager();
148
149     // wrapperMap maintains a table of LogWrapper instances used by
150
// different classes to log exceptions. The key is a StringPair
151
// representing LogDomain and ExceptionGroup.
152
private Map JavaDoc wrapperMap ;
153
154     private static Map JavaDoc staticWrapperMap = new ConcurrentHashMap JavaDoc();
155
156     private MonitoringManager monitoringManager;
157
158     // There is only one instance of the PresentationManager
159
// that is shared between all ORBs. This is necessary
160
// because RMI-IIOP requires the PresentationManager in
161
// places where no ORB is available, so the PresentationManager
162
// must be global. It is initialized here as well.
163
protected static PresentationManager globalPM = null ;
164
165     static {
166     staticWrapper = ORBUtilSystemException.get(
167         CORBALogDomains.RPC_PRESENTATION ) ;
168
169     boolean useDynamicStub =
170         ((Boolean JavaDoc)AccessController.doPrivileged(
171         new PrivilegedAction JavaDoc() {
172             public java.lang.Object JavaDoc run() {
173             return Boolean.valueOf( Boolean.getBoolean (
174                 ORBConstants.USE_DYNAMIC_STUB_PROPERTY ) ) ;
175             }
176         }
177         )).booleanValue() ;
178
179     PresentationManager.StubFactoryFactory dynamicStubFactoryFactory =
180         (PresentationManager.StubFactoryFactory)AccessController.doPrivileged(
181         new PrivilegedAction JavaDoc() {
182             public java.lang.Object JavaDoc run() {
183             PresentationManager.StubFactoryFactory sff =
184                 PresentationDefaults.getProxyStubFactoryFactory() ;
185
186             String JavaDoc className = System.getProperty(
187                 ORBConstants.DYNAMIC_STUB_FACTORY_FACTORY_CLASS,
188                 "com.sun.corba.se.impl.presentation.rmi.bcel.StubFactoryFactoryBCELImpl" ) ;
189
190             try {
191                 // First try the configured class name, if any
192
Class JavaDoc cls = ORBClassLoader.loadClass( className ) ;
193                 sff = (PresentationManager.StubFactoryFactory)cls.newInstance() ;
194             } catch (Exception JavaDoc exc) {
195                 // Use the default. Log the error as a warning.
196
staticWrapper.errorInSettingDynamicStubFactoryFactory(
197                 exc, className ) ;
198             }
199
200             return sff ;
201             }
202         }
203         ) ;
204
205     globalPM = new PresentationManagerImpl( useDynamicStub ) ;
206     globalPM.setStubFactoryFactory( false,
207         PresentationDefaults.getStaticStubFactoryFactory() ) ;
208     globalPM.setStubFactoryFactory( true, dynamicStubFactoryFactory ) ;
209     }
210
211     /** Get the single instance of the PresentationManager
212      */

213     public static PresentationManager getPresentationManager()
214     {
215     return globalPM ;
216     }
217
218     /** Get the appropriate StubFactoryFactory. This
219      * will be dynamic or static depending on whether
220      * com.sun.CORBA.ORBUseDynamicStub is true or false.
221      */

222     public static PresentationManager.StubFactoryFactory
223     getStubFactoryFactory()
224     {
225     boolean useDynamicStubs = globalPM.useDynamicStubs() ;
226     return globalPM.getStubFactoryFactory( useDynamicStubs ) ;
227     }
228
229     protected ORB()
230     {
231     // Initialize logging first, since it is needed nearly
232
// everywhere (for example, in TypeCodeImpl).
233
wrapperMap = new ConcurrentHashMap JavaDoc();
234     wrapper = ORBUtilSystemException.get( this,
235         CORBALogDomains.RPC_PRESENTATION ) ;
236     omgWrapper = OMGSystemException.get( this,
237         CORBALogDomains.RPC_PRESENTATION ) ;
238
239     typeCodeMap = new HashMap JavaDoc();
240
241     primitiveTypeCodeConstants = new TypeCodeImpl[] {
242         new TypeCodeImpl(this, TCKind._tk_null),
243         new TypeCodeImpl(this, TCKind._tk_void),
244         new TypeCodeImpl(this, TCKind._tk_short),
245         new TypeCodeImpl(this, TCKind._tk_long),
246         new TypeCodeImpl(this, TCKind._tk_ushort),
247         new TypeCodeImpl(this, TCKind._tk_ulong),
248         new TypeCodeImpl(this, TCKind._tk_float),
249         new TypeCodeImpl(this, TCKind._tk_double),
250         new TypeCodeImpl(this, TCKind._tk_boolean),
251         new TypeCodeImpl(this, TCKind._tk_char),
252         new TypeCodeImpl(this, TCKind._tk_octet),
253         new TypeCodeImpl(this, TCKind._tk_any),
254         new TypeCodeImpl(this, TCKind._tk_TypeCode),
255         new TypeCodeImpl(this, TCKind._tk_Principal),
256         new TypeCodeImpl(this, TCKind._tk_objref),
257         null, // tk_struct
258
null, // tk_union
259
null, // tk_enum
260
new TypeCodeImpl(this, TCKind._tk_string),
261         null, // tk_sequence
262
null, // tk_array
263
null, // tk_alias
264
null, // tk_except
265
new TypeCodeImpl(this, TCKind._tk_longlong),
266         new TypeCodeImpl(this, TCKind._tk_ulonglong),
267         new TypeCodeImpl(this, TCKind._tk_longdouble),
268         new TypeCodeImpl(this, TCKind._tk_wchar),
269         new TypeCodeImpl(this, TCKind._tk_wstring),
270         new TypeCodeImpl(this, TCKind._tk_fixed),
271         new TypeCodeImpl(this, TCKind._tk_value),
272         new TypeCodeImpl(this, TCKind._tk_value_box),
273         new TypeCodeImpl(this, TCKind._tk_native),
274         new TypeCodeImpl(this, TCKind._tk_abstract_interface)
275     } ;
276
277         monitoringManager =
278             MonitoringFactories.getMonitoringManagerFactory( ).
279         createMonitoringManager(
280                 MonitoringConstants.DEFAULT_MONITORING_ROOT,
281         MonitoringConstants.DEFAULT_MONITORING_ROOT_DESCRIPTION);
282     }
283
284     // Typecode support: needed in both ORBImpl and ORBSingleton
285
public TypeCodeImpl get_primitive_tc(int kind)
286     {
287     try {
288         return primitiveTypeCodeConstants[kind] ;
289     } catch (Throwable JavaDoc t) {
290         throw wrapper.invalidTypecodeKind( t, new Integer JavaDoc(kind) ) ;
291     }
292     }
293
294     public synchronized void setTypeCode(String JavaDoc id, TypeCodeImpl code)
295     {
296         typeCodeMap.put(id, code);
297     }
298
299     public synchronized TypeCodeImpl getTypeCode(String JavaDoc id)
300     {
301         return (TypeCodeImpl)typeCodeMap.get(id);
302     }
303
304     public MonitoringManager getMonitoringManager( ) {
305         return monitoringManager;
306     }
307     
308     // Special non-standard set_parameters method for
309
// creating a precisely controlled ORB instance.
310
// An ORB created by this call is affected only by
311
// those properties passes explicitly in props, not by
312
// the system properties and orb.properties files as
313
// with the standard ORB.init methods.
314
public abstract void set_parameters( Properties JavaDoc props ) ;
315
316     // ORB versioning
317
public abstract ORBVersion getORBVersion() ;
318     public abstract void setORBVersion( ORBVersion version ) ;
319
320     // XXX This needs a better name
321
public abstract IOR getFVDCodeBaseIOR() ;
322
323     /**
324      * Handle a bad server id for the given object key. This should
325      * always through an exception: either a ForwardException to
326      * allow another server to handle the request, or else an error
327      * indication. XXX Remove after ORT for ORBD work is integrated.
328      */

329     public abstract void handleBadServerId( ObjectKey okey ) ;
330     public abstract void setBadServerIdHandler( BadServerIdHandler handler ) ;
331     public abstract void initBadServerIdHandler() ;
332     
333     public abstract void notifyORB() ;
334
335     public abstract PIHandler getPIHandler() ;
336
337     public abstract void checkShutdownState();
338
339     // Dispatch support: in the ORB because it is needed for shutdown.
340
// This is used by the first level server side subcontract.
341
public abstract boolean isDuringDispatch() ;
342     public abstract void startingDispatch();
343     public abstract void finishedDispatch();
344
345     /** Return this ORB's transient server ID. This is needed for
346      * initializing object adapters.
347      */

348     public abstract int getTransientServerId();
349
350     public abstract ServiceContextRegistry getServiceContextRegistry() ;
351
352     public abstract RequestDispatcherRegistry getRequestDispatcherRegistry();
353
354     public abstract ORBData getORBData() ;
355
356     public abstract void setClientDelegateFactory( ClientDelegateFactory factory ) ;
357
358     public abstract ClientDelegateFactory getClientDelegateFactory() ;
359
360     public abstract void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory ) ;
361
362     public abstract CorbaContactInfoListFactory getCorbaContactInfoListFactory() ;
363
364     // XXX These next 7 methods should be moved to a ResolverManager.
365

366     /** Set the resolver used in this ORB. This resolver will be used for list_initial_services
367      * and resolve_initial_references.
368      */

369     public abstract void setResolver( Resolver resolver ) ;
370
371     /** Get the resolver used in this ORB. This resolver will be used for list_initial_services
372      * and resolve_initial_references.
373      */

374     public abstract Resolver getResolver() ;
375
376     /** Set the LocalResolver used in this ORB. This LocalResolver is used for
377      * register_initial_reference only.
378      */

379     public abstract void setLocalResolver( LocalResolver resolver ) ;
380
381     /** Get the LocalResolver used in this ORB. This LocalResolver is used for
382      * register_initial_reference only.
383      */

384     public abstract LocalResolver getLocalResolver() ;
385
386     /** Set the operation used in string_to_object calls. The Operation must expect a
387      * String and return an org.omg.CORBA.Object.
388      */

389     public abstract void setURLOperation( Operation stringToObject ) ;
390
391     /** Get the operation used in string_to_object calls. The Operation must expect a
392      * String and return an org.omg.CORBA.Object.
393      */

394     public abstract Operation getURLOperation() ;
395
396     /** Set the ServerRequestDispatcher that should be used for handling INS requests.
397      */

398     public abstract void setINSDelegate( CorbaServerRequestDispatcher insDelegate ) ;
399
400     // XXX The next 5 operations should be moved to an IORManager.
401

402     /** Factory finders for the various parts of the IOR: tagged components, tagged
403      * profiles, and tagged profile templates.
404      */

405     public abstract TaggedComponentFactoryFinder getTaggedComponentFactoryFinder() ;
406     public abstract IdentifiableFactoryFinder getTaggedProfileFactoryFinder() ;
407     public abstract IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder() ;
408
409     public abstract ObjectKeyFactory getObjectKeyFactory() ;
410     public abstract void setObjectKeyFactory( ObjectKeyFactory factory ) ;
411
412     // Logging SPI
413

414     /**
415      * Returns the logger based on the category.
416      */

417     public Logger JavaDoc getLogger( String JavaDoc domain )
418     {
419     ORBData odata = getORBData() ;
420
421     // Determine the correct ORBId. There are 3 cases:
422
// 1. odata is null, which happens if we are getting a logger before
423
// ORB initialization is complete. In this case we cannot determine
424
// the ORB ID (it's not known yet), so we set the ORBId to
425
// _INITIALIZING_.
426
// 2. odata is not null, so initialization is complete, but ORBId is set to
427
// the default "". To avoid a ".." in
428
// the log domain, we simply use _DEFAULT_ in this case.
429
// 3. odata is not null, ORBId is not "": just use the ORBId.
430
String JavaDoc ORBId ;
431     if (odata == null)
432         ORBId = "_INITIALIZING_" ;
433     else {
434         ORBId = odata.getORBId() ;
435         if (ORBId.equals(""))
436         ORBId = "_DEFAULT_" ;
437     }
438
439     return getCORBALogger( ORBId, domain ) ;
440     }
441
442     public static Logger JavaDoc staticGetLogger( String JavaDoc domain )
443     {
444     return getCORBALogger( "_CORBA_", domain ) ;
445     }
446     
447     private static Logger JavaDoc getCORBALogger( String JavaDoc ORBId, String JavaDoc domain )
448     {
449         String JavaDoc fqLogDomain = CORBALogDomains.TOP_LEVEL_DOMAIN + "." +
450         ORBId + "." + domain;
451
452         return Logger.getLogger( fqLogDomain, ORBConstants.LOG_RESOURCE_FILE );
453     }
454
455     /** get the log wrapper class (its type is dependent on the exceptionGroup) for the
456      * given log domain and exception group in this ORB instance.
457      */

458     public LogWrapperBase getLogWrapper( String JavaDoc logDomain,
459         String JavaDoc exceptionGroup, LogWrapperFactory factory )
460     {
461         StringPair key = new StringPair( logDomain, exceptionGroup ) ;
462
463         LogWrapperBase logWrapper = (LogWrapperBase)wrapperMap.get( key );
464         if (logWrapper == null) {
465             logWrapper = factory.create( getLogger( logDomain ) );
466             wrapperMap.put( key, logWrapper );
467         }
468
469         return logWrapper;
470     }
471
472     /** get the log wrapper class (its type is dependent on the exceptionGroup) for the
473      * given log domain and exception group in this ORB instance.
474      */

475     public static LogWrapperBase staticGetLogWrapper( String JavaDoc logDomain,
476         String JavaDoc exceptionGroup, LogWrapperFactory factory )
477     {
478         StringPair key = new StringPair( logDomain, exceptionGroup ) ;
479
480         LogWrapperBase logWrapper = (LogWrapperBase)staticWrapperMap.get( key );
481         if (logWrapper == null) {
482             logWrapper = factory.create( staticGetLogger( logDomain ) );
483             staticWrapperMap.put( key, logWrapper );
484         }
485
486         return logWrapper;
487     }
488
489     // get a reference to a ByteBufferPool, a pool of NIO ByteBuffers
490
// NOTE: ByteBuffer pool must be unique per ORB, not per process.
491
// There can be more than one ORB per process.
492
// This method must also be inherited by both ORB and ORBSingleton.
493
public ByteBufferPool getByteBufferPool()
494     {
495         if (byteBufferPool == null)
496             byteBufferPool = new ByteBufferPoolImpl(this);
497
498         return byteBufferPool;
499     }
500
501     public abstract void setThreadPoolManager(ThreadPoolManager mgr);
502
503     public abstract ThreadPoolManager getThreadPoolManager();
504
505     public abstract CopierManager getCopierManager() ;
506 }
507
508 // End of file.
509

510
Popular Tags