KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > orb > ORBImpl


1 /* @(#)ORBImpl.java 1.68 06/01/03
2  *
3  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
4  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
5  */

6
7 package com.sun.corba.se.impl.orb ;
8
9 import java.applet.Applet JavaDoc;
10
11 import java.io.IOException JavaDoc ;
12
13 import java.lang.reflect.Constructor JavaDoc;
14 import java.lang.reflect.Field JavaDoc ;
15 import java.lang.reflect.Modifier JavaDoc ;
16 import java.lang.reflect.InvocationTargetException JavaDoc ;
17
18 import java.util.ArrayList JavaDoc ;
19 import java.util.Iterator JavaDoc ;
20 import java.util.Properties JavaDoc ;
21 import java.util.Vector JavaDoc ;
22 import java.util.Hashtable JavaDoc ;
23 import java.util.Map JavaDoc ;
24 import java.util.HashMap JavaDoc ;
25 import java.util.LinkedList JavaDoc ;
26 import java.util.Collection JavaDoc ;
27 import java.util.Collections JavaDoc ;
28 import java.util.StringTokenizer JavaDoc ;
29 import java.util.Enumeration JavaDoc ;
30 import java.util.WeakHashMap JavaDoc ;
31
32 import java.net.InetAddress JavaDoc ;
33
34 import java.security.PrivilegedAction JavaDoc;
35 import java.security.AccessController JavaDoc ;
36
37 import javax.rmi.CORBA.Util JavaDoc;
38 import javax.rmi.CORBA.ValueHandler JavaDoc;
39
40 import org.omg.CORBA.Context JavaDoc;
41 import org.omg.CORBA.ContextList JavaDoc;
42 import org.omg.CORBA.Environment JavaDoc;
43 import org.omg.CORBA.ExceptionList JavaDoc;
44 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
45 import org.omg.CORBA.NVList JavaDoc;
46 import org.omg.CORBA.TCKind JavaDoc;
47 import org.omg.CORBA.NamedValue JavaDoc;
48 import org.omg.CORBA.Request JavaDoc;
49 import org.omg.CORBA.SystemException JavaDoc;
50 import org.omg.CORBA.CompletionStatus JavaDoc;
51 import org.omg.CORBA.TypeCode JavaDoc;
52 import org.omg.CORBA.Any JavaDoc;
53 import org.omg.CORBA.StructMember JavaDoc;
54 import org.omg.CORBA.UnionMember JavaDoc;
55 import org.omg.CORBA.ValueMember JavaDoc;
56 import org.omg.CORBA.BAD_PARAM JavaDoc;
57 import org.omg.CORBA.MARSHAL JavaDoc;
58
59 import org.omg.CORBA.portable.ValueFactory JavaDoc;
60
61 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
62
63 import com.sun.org.omg.SendingContext.CodeBase;
64
65 import com.sun.corba.se.pept.broker.Broker;
66 import com.sun.corba.se.pept.protocol.ClientInvocationInfo ;
67 import com.sun.corba.se.pept.transport.ContactInfo;
68 import com.sun.corba.se.pept.transport.ConnectionCache;
69 import com.sun.corba.se.pept.transport.TransportManager;
70
71 import com.sun.corba.se.spi.ior.IOR;
72 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
73 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder;
74 import com.sun.corba.se.spi.ior.IORFactories ;
75 import com.sun.corba.se.spi.ior.ObjectKey ;
76 import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
77 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
78 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
79 import com.sun.corba.se.spi.oa.OAInvocationInfo;
80 import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
81 import com.sun.corba.se.spi.orb.DataCollector;
82 import com.sun.corba.se.spi.orb.Operation;
83 import com.sun.corba.se.spi.orb.ORBData;
84 import com.sun.corba.se.spi.orb.ORBConfigurator;
85 import com.sun.corba.se.spi.orb.ParserImplBase;
86 import com.sun.corba.se.spi.orb.PropertyParser;
87 import com.sun.corba.se.spi.orb.OperationFactory;
88 import com.sun.corba.se.spi.orb.ORBVersion;
89 import com.sun.corba.se.spi.orb.ORBVersionFactory;
90 import com.sun.corba.se.spi.orbutil.closure.ClosureFactory;
91 import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager;
92 import com.sun.corba.se.spi.protocol.ClientDelegateFactory;
93 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
94 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
95 import com.sun.corba.se.spi.protocol.RequestDispatcherDefault;
96 import com.sun.corba.se.spi.protocol.PIHandler;
97 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
98 import com.sun.corba.se.spi.protocol.ForwardException;
99 import com.sun.corba.se.spi.resolver.Resolver;
100 import com.sun.corba.se.spi.resolver.LocalResolver;
101 import com.sun.corba.se.spi.orb.StringPair;
102 import com.sun.corba.se.spi.orb.StringPair;
103 import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory;
104 import com.sun.corba.se.spi.transport.CorbaTransportManager;
105 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
106 import com.sun.corba.se.spi.copyobject.CopierManager ;
107 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ;
108 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ;
109 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
110 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry;
111
112 import com.sun.corba.se.impl.corba.TypeCodeFactory;
113 import com.sun.corba.se.impl.corba.TypeCodeImpl;
114 import com.sun.corba.se.impl.corba.NVListImpl;
115 import com.sun.corba.se.impl.corba.ExceptionListImpl;
116 import com.sun.corba.se.impl.corba.ContextListImpl;
117 import com.sun.corba.se.impl.corba.NamedValueImpl;
118 import com.sun.corba.se.impl.corba.EnvironmentImpl;
119 import com.sun.corba.se.impl.corba.AsynchInvoke;
120 import com.sun.corba.se.impl.corba.AnyImpl;
121 import com.sun.corba.se.impl.corba.RequestImpl;
122 import com.sun.corba.se.impl.dynamicany.DynAnyFactoryImpl;
123 import com.sun.corba.se.impl.encoding.EncapsOutputStream;
124 import com.sun.corba.se.impl.interceptors.PIHandlerImpl;
125 import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl;
126 import com.sun.corba.se.impl.ior.TaggedComponentFactoryFinderImpl;
127 import com.sun.corba.se.impl.ior.TaggedProfileFactoryFinderImpl;
128 import com.sun.corba.se.impl.ior.TaggedProfileTemplateFactoryFinderImpl;
129 import com.sun.corba.se.impl.oa.toa.TOAFactory;
130 import com.sun.corba.se.impl.oa.poa.BadServerIdHandler;
131 import com.sun.corba.se.impl.oa.poa.DelegateImpl;
132 import com.sun.corba.se.impl.oa.poa.POAFactory;
133 import com.sun.corba.se.impl.orbutil.ORBClassLoader;
134 import com.sun.corba.se.impl.orbutil.ORBConstants;
135 import com.sun.corba.se.impl.orbutil.ORBUtility;
136 import com.sun.corba.se.impl.orbutil.StackImpl;
137 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl;
138 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolManagerImpl;
139 import com.sun.corba.se.impl.protocol.RequestDispatcherRegistryImpl;
140 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo;
141 import com.sun.corba.se.impl.transport.CorbaTransportManagerImpl;
142 import com.sun.corba.se.impl.legacy.connection.LegacyServerSocketManagerImpl;
143 import com.sun.corba.se.impl.util.Utility;
144 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
145 import com.sun.corba.se.impl.copyobject.CopierManagerImpl;
146 import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl;
147              
148 /**
149  * The JavaIDL ORB implementation.
150  */

151 public class ORBImpl extends com.sun.corba.se.spi.orb.ORB
152 {
153     protected TransportManager transportManager;
154     protected LegacyServerSocketManager legacyServerSocketManager;
155
156     private ThreadLocal JavaDoc OAInvocationInfoStack ;
157
158     private ThreadLocal JavaDoc clientInvocationInfoStack ;
159
160     // pure java orb, caching the servant IOR per ORB
161
private static IOR codeBaseIOR ;
162
163     // Vector holding deferred Requests
164
private Vector JavaDoc dynamicRequests ;
165     private SynchVariable svResponseReceived ;
166
167     private java.lang.Object JavaDoc runObj = new java.lang.Object JavaDoc();
168     private java.lang.Object JavaDoc shutdownObj = new java.lang.Object JavaDoc();
169     private java.lang.Object JavaDoc waitForCompletionObj = new java.lang.Object JavaDoc();
170     private static final byte STATUS_OPERATING = 1;
171     private static final byte STATUS_SHUTTING_DOWN = 2;
172     private static final byte STATUS_SHUTDOWN = 3;
173     private static final byte STATUS_DESTROYED = 4;
174     private byte status = STATUS_OPERATING;
175
176     // XXX Should we move invocation tracking to the first level server dispatcher?
177
private java.lang.Object JavaDoc invocationObj = new java.lang.Object JavaDoc();
178     private int numInvocations = 0;
179
180     // thread local variable to store a boolean to detect deadlock in
181
// ORB.shutdown(true).
182
private ThreadLocal JavaDoc isProcessingInvocation = new ThreadLocal JavaDoc () {
183         protected java.lang.Object JavaDoc initialValue() {
184             return Boolean.FALSE;
185         }
186     };
187
188     // This map is caching TypeCodes created for a certain class (key)
189
// and is used in Util.writeAny()
190
private Map JavaDoc typeCodeForClassMap ;
191
192     // Cache to hold ValueFactories (Helper classes) keyed on repository ids
193
private Hashtable JavaDoc valueFactoryCache = new Hashtable JavaDoc();
194
195     // thread local variable to store the current ORB version.
196
// default ORB version is the version of ORB with correct Rep-id
197
// changes
198
private ThreadLocal JavaDoc orbVersionThreadLocal ;
199
200     private RequestDispatcherRegistry requestDispatcherRegistry ;
201
202     private CopierManager copierManager ;
203
204     private int transientServerId ;
205
206     private ThreadGroup JavaDoc threadGroup ;
207
208     private ServiceContextRegistry serviceContextRegistry ;
209
210     // Needed here to implement connect/disconnect
211
private TOAFactory toaFactory ;
212
213     // Needed here for set_delegate
214
private POAFactory poaFactory ;
215
216     // The interceptor handler, which provides portable interceptor services for
217
// subcontracts and object adapters.
218
private PIHandler pihandler ;
219
220     private ORBData configData ;
221
222     private BadServerIdHandler badServerIdHandler ;
223
224     private ClientDelegateFactory clientDelegateFactory ;
225
226     private CorbaContactInfoListFactory corbaContactInfoListFactory ;
227
228     // All access to resolver, localResolver, and urlOperation must be protected using
229
// resolverLock. Do not hold the ORBImpl lock while accessing
230
// resolver, or deadlocks may occur.
231
private Object JavaDoc resolverLock ;
232
233     // Used for resolver_initial_references and list_initial_services
234
private Resolver resolver ;
235
236     // Used for register_initial_references
237
private LocalResolver localResolver ;
238
239     // Converts strings to object references for resolvers and string_to_object
240
private Operation urlOperation ;
241
242     private CorbaServerRequestDispatcher insNamingDelegate ;
243
244     private TaggedComponentFactoryFinder taggedComponentFactoryFinder ;
245
246     private IdentifiableFactoryFinder taggedProfileFactoryFinder ;
247
248     private IdentifiableFactoryFinder taggedProfileTemplateFactoryFinder ;
249
250     private ObjectKeyFactory objectKeyFactory ;
251
252     private ThreadPoolManager threadpoolMgr;
253
254     private void dprint( String JavaDoc msg )
255     {
256         ORBUtility.dprint( this, msg ) ;
257     }
258
259     ////////////////////////////////////////////////////
260
//
261
// NOTE:
262
//
263
// Methods that are synchronized MUST stay synchronized.
264
//
265
// Methods that are NOT synchronized must stay that way to avoid deadlock.
266
//
267
//
268
// REVISIT:
269
//
270
// checkShutDownState - lock on different object - and normalize usage.
271
// starting/FinishDispatch and Shutdown
272
//
273

274     public ORBData getORBData()
275     {
276     return configData ;
277     }
278  
279     public PIHandler getPIHandler()
280     {
281     return pihandler ;
282     }
283
284     /**
285      * Create a new ORB. Should be followed by the appropriate
286      * set_parameters() call.
287      */

288     public ORBImpl()
289     {
290     // All initialization is done through set_parameters().
291
}
292
293     public ORBVersion getORBVersion()
294     {
295         return (ORBVersion)(orbVersionThreadLocal.get()) ;
296     }
297
298     public void setORBVersion(ORBVersion verObj)
299     {
300         orbVersionThreadLocal.set(verObj);
301     }
302
303 /****************************************************************************
304  * The following methods are ORB initialization
305  ****************************************************************************/

306
307     // preInit initializes all non-pluggable ORB data that is independent
308
// of the property parsing.
309
private void preInit( String JavaDoc[] params, Properties JavaDoc props )
310     {
311         // Before ORBConfiguration we need to set a PINoOpHandlerImpl,
312
// because PersisentServer Initialization inside configurator will
313
// invoke orb.resolve_initial_references( ) which will result in a
314
// check on piHandler to invoke Interceptors. We do not want any
315
// Interceptors to be invoked before the complete ORB initialization.
316
// piHandler will be replaced by a real PIHandler implementation at the
317
// end of this method.
318
pihandler = new PINoOpHandlerImpl( );
319
320     // See bugs 4916766 and 4936203
321
// We intend to create new threads in a reliable thread group.
322
// This avoids problems if the application/applet
323
// creates a thread group, makes JavaIDL calls which create a new
324
// connection and ReaderThread, and then destroys the thread
325
// group. If our ReaderThreads were to be part of such destroyed thread
326
// group then it might get killed and cause other invoking threads
327
// sharing the same connection to get a non-restartable
328
// CommunicationFailure. We'd like to avoid that.
329
//
330
// Our solution is to create all of our threads in the highest thread
331
// group that we have access to, given our own security clearance.
332
//
333
try {
334         // try to get a thread group that's as high in the threadgroup
335
// parent-child hierarchy, as we can get to.
336
// this will prevent an ORB thread created during applet-init from
337
// being killed when an applet dies.
338
threadGroup = (ThreadGroup JavaDoc) AccessController.doPrivileged(
339         new PrivilegedAction JavaDoc() {
340             public Object JavaDoc run() {
341             ThreadGroup JavaDoc tg = Thread.currentThread().getThreadGroup() ;
342             ThreadGroup JavaDoc ptg = tg ;
343             try {
344                 while (ptg != null) {
345                 tg = ptg;
346                 ptg = tg.getParent();
347                 }
348             } catch (SecurityException JavaDoc se) {
349                 // Discontinue going higher on a security exception.
350
}
351             return new ThreadGroup JavaDoc(tg, "ORB ThreadGroup");
352             }
353         }
354         );
355     } catch (SecurityException JavaDoc e) {
356         // something wrong, we go back to the original code
357
threadGroup = Thread.currentThread().getThreadGroup();
358     }
359  
360     // This is the unique id of this server (JVM). Multiple incarnations
361
// of this server will get different ids.
362
// Compute transientServerId = milliseconds since Jan 1, 1970
363
// Note: transientServerId will wrap in about 2^32 / 86400000 = 49.7 days.
364
// If two ORBS are started at the same time then there is a possibility
365
// of having the same transientServerId. This may result in collision
366
// and may be a problem in ior.isLocal() check to see if the object
367
// belongs to the current ORB. This problem is taken care of by checking
368
// to see if the IOR port matches ORB server port in legacyIsLocalServerPort()
369
// method.
370
//
371
// XXX need to move server ID to a string for CORBA 3.0. At that point,
372
// make this more unique (possibly use java.rmi.server.UID).
373
transientServerId = (int)System.currentTimeMillis();
374
375     orbVersionThreadLocal = new ThreadLocal JavaDoc () {
376         protected java.lang.Object JavaDoc initialValue() {
377         // set default to version of the ORB with correct Rep-ids
378
return ORBVersionFactory.getORBVersion() ;
379         }
380     };
381
382     resolverLock = new java.lang.Object JavaDoc() ;
383
384     requestDispatcherRegistry = new RequestDispatcherRegistryImpl(
385         this, ORBConstants.DEFAULT_SCID);
386     copierManager = new CopierManagerImpl( this ) ;
387
388     taggedComponentFactoryFinder =
389         new TaggedComponentFactoryFinderImpl(this) ;
390     taggedProfileFactoryFinder =
391         new TaggedProfileFactoryFinderImpl(this) ;
392     taggedProfileTemplateFactoryFinder =
393         new TaggedProfileTemplateFactoryFinderImpl(this) ;
394
395     dynamicRequests = new Vector JavaDoc();
396     svResponseReceived = new SynchVariable();
397
398     OAInvocationInfoStack =
399         new ThreadLocal JavaDoc () {
400         protected java.lang.Object JavaDoc initialValue()
401         {
402             return new StackImpl();
403         }
404         };
405
406     clientInvocationInfoStack =
407         new ThreadLocal JavaDoc() {
408         protected java.lang.Object JavaDoc initialValue() {
409             return new StackImpl();
410         }
411         };
412
413     serviceContextRegistry = new ServiceContextRegistry( this ) ;
414     }
415
416     protected void setDebugFlags( String JavaDoc[] args )
417     {
418     for (int ctr=0; ctr<args.length; ctr++ ) {
419             String JavaDoc token = args[ctr] ;
420
421             // If there is a public boolean data member in this class
422
// named token + "DebugFlag", set it to true.
423
try {
424                 Field JavaDoc fld = this.getClass().getField( token + "DebugFlag" ) ;
425                 int mod = fld.getModifiers() ;
426                 if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
427                     if (fld.getType() == boolean.class)
428                         fld.setBoolean( this, true ) ;
429             } catch (Exception JavaDoc exc) {
430                 // ignore it XXX log this as info
431
}
432         }
433     }
434
435     // Class that defines a parser that gets the name of the
436
// ORBConfigurator class.
437
private static class ConfigParser extends ParserImplBase {
438     // The default here is the ORBConfiguratorImpl that we define,
439
// but this can be replaced.
440
public Class JavaDoc configurator = ORBConfiguratorImpl.class ;
441
442     public PropertyParser makeParser()
443     {
444         PropertyParser parser = new PropertyParser() ;
445         parser.add( ORBConstants.SUN_PREFIX + "ORBConfigurator",
446         OperationFactory.classAction(), "configurator" ) ;
447         return parser ;
448     }
449     }
450
451     private void postInit( String JavaDoc[] params, DataCollector dataCollector )
452     {
453     // First, create the standard ORB config data.
454
// This must be initialized before the ORBConfigurator
455
// is executed.
456
configData = new ORBDataParserImpl( this, dataCollector) ;
457
458     // Set the debug flags early so they can be used by other
459
// parts of the initialization.
460
setDebugFlags( configData.getORBDebugFlags() ) ;
461
462     // REVISIT: this should go away after more transport init cleanup
463
// and going to ORT based ORBD.
464
getTransportManager();
465     getLegacyServerSocketManager();
466
467     // Create a parser to get the configured ORBConfigurator.
468
ConfigParser parser = new ConfigParser() ;
469     parser.init( dataCollector ) ;
470
471     ORBConfigurator configurator = null ;
472     try {
473         configurator =
474         (ORBConfigurator)(parser.configurator.newInstance()) ;
475     } catch (Exception JavaDoc iexc) {
476         throw wrapper.badOrbConfigurator( iexc, parser.configurator.getName() ) ;
477     }
478
479     // Finally, run the configurator. Note that the default implementation allows
480
// other configurators with their own parsers to run,
481
// using the same DataCollector.
482
try {
483         configurator.configure( dataCollector, this ) ;
484     } catch (Exception JavaDoc exc) {
485         throw wrapper.orbConfiguratorError( exc ) ;
486     }
487
488     // Last of all, create the PIHandler and run the ORB initializers.
489
pihandler = new PIHandlerImpl( this, params) ;
490     pihandler.initialize() ;
491
492         // Initialize the thread manager pool and byte buffer pool
493
// so they may be initialized & accessed without synchronization
494
getThreadPoolManager();
495
496         super.getByteBufferPool();
497     }
498
499     private synchronized POAFactory getPOAFactory()
500     {
501     if (poaFactory == null) {
502         poaFactory = (POAFactory)requestDispatcherRegistry.getObjectAdapterFactory(
503         ORBConstants.TRANSIENT_SCID ) ;
504     }
505
506     return poaFactory ;
507     }
508
509     private synchronized TOAFactory getTOAFactory()
510     {
511     if (toaFactory == null) {
512         toaFactory = (TOAFactory)requestDispatcherRegistry.getObjectAdapterFactory(
513         ORBConstants.TOA_SCID ) ;
514     }
515
516     return toaFactory ;
517     }
518
519     public void set_parameters( Properties JavaDoc props )
520     {
521     preInit( null, props ) ;
522     DataCollector dataCollector =
523         DataCollectorFactory.create( props, getLocalHostName() ) ;
524     postInit( null, dataCollector ) ;
525     }
526
527     protected void set_parameters(Applet JavaDoc app, Properties JavaDoc props)
528     {
529     preInit( null, props ) ;
530     DataCollector dataCollector =
531         DataCollectorFactory.create( app, props, getLocalHostName() ) ;
532     postInit( null, dataCollector ) ;
533     }
534
535     protected void set_parameters (String JavaDoc[] params, Properties JavaDoc props)
536     {
537     preInit( params, props ) ;
538     DataCollector dataCollector =
539         DataCollectorFactory.create( params, props, getLocalHostName() ) ;
540     postInit( params, dataCollector ) ;
541     }
542
543 /****************************************************************************
544  * The following methods are standard public CORBA ORB APIs
545  ****************************************************************************/

546
547     public synchronized org.omg.CORBA.portable.OutputStream JavaDoc create_output_stream()
548     {
549         checkShutdownState();
550         return new EncapsOutputStream(this);
551     }
552
553     /**
554      * Get a Current pseudo-object.
555      * The Current interface is used to manage thread-specific
556      * information for use by the transactions, security and other
557      * services. This method is deprecated,
558      * and replaced by ORB.resolve_initial_references("NameOfCurrentObject");
559      *
560      * @return a Current pseudo-object.
561      * @deprecated
562      */

563     public synchronized org.omg.CORBA.Current JavaDoc get_current()
564     {
565         checkShutdownState();
566
567         /* _REVISIT_
568            The implementation of get_current is not clear. How would
569            ORB know whether the caller wants a Current for transactions
570            or security ?? Or is it assumed that there is just one
571            implementation for both ? If Current is thread-specific,
572            then it should not be instantiated; so where does the
573            ORB get a Current ?
574        
575        This should probably be deprecated. */

576
577     throw wrapper.genericNoImpl() ;
578     }
579
580     /**
581      * Create an NVList
582      *
583      * @param count size of list to create
584      * @result NVList created
585      *
586      * @see NVList
587      */

588     public synchronized NVList JavaDoc create_list(int count)
589     {
590         checkShutdownState();
591         return new NVListImpl(this, count);
592     }
593
594     /**
595      * Create an NVList corresponding to an OperationDef
596      *
597      * @param oper operation def to use to create list
598      * @result NVList created
599      *
600      * @see NVList
601      */

602     public synchronized NVList JavaDoc create_operation_list(org.omg.CORBA.Object JavaDoc oper)
603     {
604         checkShutdownState();
605     throw wrapper.genericNoImpl() ;
606     }
607
608     /**
609      * Create a NamedValue
610      *
611      * @result NamedValue created
612      */

613     public synchronized NamedValue JavaDoc create_named_value(String JavaDoc s, Any JavaDoc any, int flags)
614     {
615         checkShutdownState();
616         return new NamedValueImpl(this, s, any, flags);
617     }
618
619     /**
620      * Create an ExceptionList
621      *
622      * @result ExceptionList created
623      */

624     public synchronized org.omg.CORBA.ExceptionList JavaDoc create_exception_list()
625     {
626         checkShutdownState();
627         return new ExceptionListImpl();
628     }
629
630     /**
631      * Create a ContextList
632      *
633      * @result ContextList created
634      */

635     public synchronized org.omg.CORBA.ContextList JavaDoc create_context_list()
636     {
637         checkShutdownState();
638         return new ContextListImpl(this);
639     }
640
641     /**
642      * Get the default Context object
643      *
644      * @result the default Context object
645      */

646     public synchronized org.omg.CORBA.Context JavaDoc get_default_context()
647     {
648         checkShutdownState();
649     throw wrapper.genericNoImpl() ;
650     }
651
652     /**
653      * Create an Environment
654      *
655      * @result Environment created
656      */

657     public synchronized org.omg.CORBA.Environment JavaDoc create_environment()
658     {
659         checkShutdownState();
660         return new EnvironmentImpl();
661     }
662
663     public synchronized void send_multiple_requests_oneway(Request JavaDoc[] req)
664     {
665         checkShutdownState();
666
667         // Invoke the send_oneway on each new Request
668
for (int i = 0; i < req.length; i++) {
669             req[i].send_oneway();
670         }
671     }
672
673     /**
674      * Send multiple dynamic requests asynchronously.
675      *
676      * @param req an array of request objects.
677      */

678     public synchronized void send_multiple_requests_deferred(Request JavaDoc[] req)
679     {
680         checkShutdownState();
681
682         // add the new Requests to pending dynamic Requests
683
for (int i = 0; i < req.length; i++) {
684             dynamicRequests.addElement(req[i]);
685         }
686
687         // Invoke the send_deferred on each new Request
688
for (int i = 0; i < req.length; i++) {
689             AsynchInvoke invokeObject = new AsynchInvoke( this,
690         (com.sun.corba.se.impl.corba.RequestImpl)req[i], true);
691             new Thread JavaDoc(invokeObject).start();
692         }
693     }
694
695     /**
696      * Find out if any of the deferred invocations have a response yet.
697      */

698     public synchronized boolean poll_next_response()
699     {
700         checkShutdownState();
701
702         Request JavaDoc currRequest;
703
704         // poll on each pending request
705
Enumeration JavaDoc ve = dynamicRequests.elements();
706         while (ve.hasMoreElements() == true) {
707             currRequest = (Request JavaDoc)ve.nextElement();
708             if (currRequest.poll_response() == true) {
709                 return true;
710             }
711         }
712         return false;
713     }
714
715     /**
716      * Get the next request that has gotten a response.
717      *
718      * @result the next request ready with a response.
719      */

720     public org.omg.CORBA.Request JavaDoc get_next_response()
721         throws org.omg.CORBA.WrongTransaction JavaDoc
722     {
723     synchronized( this ) {
724         checkShutdownState();
725     }
726
727         while (true) {
728             // check if there already is a response
729
synchronized ( dynamicRequests ) {
730                 Enumeration JavaDoc elems = dynamicRequests.elements();
731                 while ( elems.hasMoreElements() ) {
732                     Request JavaDoc currRequest = (Request JavaDoc)elems.nextElement();
733                     if ( currRequest.poll_response() ) {
734                         // get the response for this successfully polled Request
735
currRequest.get_response();
736                         dynamicRequests.removeElement(currRequest);
737                         return currRequest;
738                     }
739                 }
740             }
741
742             // wait for a response
743
synchronized(this.svResponseReceived) {
744                 while (!this.svResponseReceived.value()) {
745                     try {
746                         this.svResponseReceived.wait();
747                     } catch(java.lang.InterruptedException JavaDoc ex) {
748             // NO-OP
749
}
750                 }
751                 // reinitialize the response flag
752
this.svResponseReceived.reset();
753             }
754         }
755     }
756
757     /**
758      * Notify response to ORB for get_next_response
759      */

760     public void notifyORB()
761     {
762     synchronized (this.svResponseReceived) {
763         this.svResponseReceived.set();
764         this.svResponseReceived.notify();
765     }
766     }
767
768     /**
769      * Convert an object ref to a string.
770      * @param obj The object to stringify.
771      * @return A stringified object reference.
772      */

773     public synchronized String JavaDoc object_to_string(org.omg.CORBA.Object JavaDoc obj)
774     {
775         checkShutdownState();
776
777         // Handle the null objref case
778
if (obj == null) {
779         IOR nullIOR = IORFactories.makeIOR( this ) ;
780             return nullIOR.stringify();
781     }
782
783     IOR ior = null ;
784
785     try {
786         ior = ORBUtility.connectAndGetIOR( this, obj ) ;
787     } catch (BAD_PARAM JavaDoc bp) {
788         // Throw MARSHAL instead if this is a LOCAL_OBJECT_NOT_ALLOWED error.
789
if (bp.minor == ORBUtilSystemException.LOCAL_OBJECT_NOT_ALLOWED) {
790         throw omgWrapper.notAnObjectImpl( bp ) ;
791         } else
792         // Not a local object problem: just rethrow the exception.
793
// Do not wrap and log this, since it was already logged at its
794
// point of origin.
795
throw bp ;
796     }
797
798     return ior.stringify() ;
799     }
800
801     /**
802      * Convert a stringified object reference to the object it represents.
803      * @param str The stringified object reference.
804      * @return The unstringified object reference.
805      */

806     public org.omg.CORBA.Object JavaDoc string_to_object(String JavaDoc str)
807     {
808     Operation op ;
809
810     synchronized (this) {
811         checkShutdownState();
812         op = urlOperation ;
813     }
814
815     if (str == null)
816         throw wrapper.nullParam() ;
817
818     synchronized (resolverLock) {
819         org.omg.CORBA.Object JavaDoc obj = (org.omg.CORBA.Object JavaDoc)op.operate( str ) ;
820         return obj ;
821     }
822     }
823
824     // pure java orb support, moved this method from FVDCodeBaseImpl.
825
// Note that we connect this if we have not already done so.
826
public synchronized IOR getFVDCodeBaseIOR()
827     {
828         if (codeBaseIOR != null) // i.e. We are already connected to it
829
return codeBaseIOR;
830
831         // backward compatability 4365188
832
CodeBase cb;
833
834         ValueHandler JavaDoc vh = ORBUtility.createValueHandler(this);
835
836         cb = (CodeBase)vh.getRunTimeCodeBase();
837     return ORBUtility.connectAndGetIOR( this, cb ) ;
838     }
839
840     /**
841      * Get the TypeCode for a primitive type.
842      *
843      * @param tcKind the integer kind for the primitive type
844      * @return the requested TypeCode
845      */

846     public synchronized TypeCode JavaDoc get_primitive_tc(TCKind JavaDoc tcKind)
847     {
848         checkShutdownState();
849     return get_primitive_tc( tcKind.value() ) ;
850     }
851
852     /**
853      * Create a TypeCode for a structure.
854      *
855      * @param id the logical id for the typecode.
856      * @param name the name for the typecode.
857      * @param members an array describing the members of the TypeCode.
858      * @return the requested TypeCode.
859      */

860     public synchronized TypeCode JavaDoc create_struct_tc(String JavaDoc id,
861                                      String JavaDoc name,
862                                      StructMember JavaDoc[] members)
863     {
864         checkShutdownState();
865         return new TypeCodeImpl(this, TCKind._tk_struct, id, name, members);
866     }
867
868     /**
869      * Create a TypeCode for a union.
870      *
871      * @param id the logical id for the typecode.
872      * @param name the name for the typecode.
873      * @param discriminator_type
874      * the type of the union discriminator.
875      * @param members an array describing the members of the TypeCode.
876      * @return the requested TypeCode.
877      */

878     public synchronized TypeCode JavaDoc create_union_tc(String JavaDoc id,
879                                     String JavaDoc name,
880                                     TypeCode JavaDoc discriminator_type,
881                                     UnionMember JavaDoc[] members)
882     {
883         checkShutdownState();
884         return new TypeCodeImpl(this,
885                                 TCKind._tk_union,
886                                 id,
887                                 name,
888                                 discriminator_type,
889                                 members);
890     }
891
892     /**
893      * Create a TypeCode for an enum.
894      *
895      * @param id the logical id for the typecode.
896      * @param name the name for the typecode.
897      * @param members an array describing the members of the TypeCode.
898      * @return the requested TypeCode.
899      */

900     public synchronized TypeCode JavaDoc create_enum_tc(String JavaDoc id,
901                                    String JavaDoc name,
902                                    String JavaDoc[] members)
903     {
904         checkShutdownState();
905         return new TypeCodeImpl(this, TCKind._tk_enum, id, name, members);
906     }
907
908     /**
909      * Create a TypeCode for an alias.
910      *
911      * @param id the logical id for the typecode.
912      * @param name the name for the typecode.
913      * @param original_type
914      * the type this is an alias for.
915      * @return the requested TypeCode.
916      */

917     public synchronized TypeCode JavaDoc create_alias_tc(String JavaDoc id,
918                                     String JavaDoc name,
919                                     TypeCode JavaDoc original_type)
920     {
921         checkShutdownState();
922         return new TypeCodeImpl(this, TCKind._tk_alias, id, name, original_type);
923     }
924
925     /**
926      * Create a TypeCode for an exception.
927      *
928      * @param id the logical id for the typecode.
929      * @param name the name for the typecode.
930      * @param members an array describing the members of the TypeCode.
931      * @return the requested TypeCode.
932      */

933     public synchronized TypeCode JavaDoc create_exception_tc(String JavaDoc id,
934                                         String JavaDoc name,
935                                         StructMember JavaDoc[] members)
936     {
937         checkShutdownState();
938         return new TypeCodeImpl(this, TCKind._tk_except, id, name, members);
939     }
940
941     /**
942      * Create a TypeCode for an interface.
943      *
944      * @param id the logical id for the typecode.
945      * @param name the name for the typecode.
946      * @return the requested TypeCode.
947      */

948     public synchronized TypeCode JavaDoc create_interface_tc(String JavaDoc id,
949                                         String JavaDoc name)
950     {
951         checkShutdownState();
952         return new TypeCodeImpl(this, TCKind._tk_objref, id, name);
953     }
954
955     /**
956      * Create a TypeCode for a string.
957      *
958      * @param bound the bound for the string.
959      * @return the requested TypeCode.
960      */

961     public synchronized TypeCode JavaDoc create_string_tc(int bound)
962     {
963         checkShutdownState();
964         return new TypeCodeImpl(this, TCKind._tk_string, bound);
965     }
966
967     /**
968      * Create a TypeCode for a wide string.
969      *
970      * @param bound the bound for the string.
971      * @return the requested TypeCode.
972      */

973     public synchronized TypeCode JavaDoc create_wstring_tc(int bound)
974     {
975         checkShutdownState();
976         return new TypeCodeImpl(this, TCKind._tk_wstring, bound);
977     }
978
979     /**
980      * Create a TypeCode for a sequence.
981      *
982      * @param bound the bound for the sequence.
983      * @param element_type
984      * the type of elements of the sequence.
985      * @return the requested TypeCode.
986      */

987     public synchronized TypeCode JavaDoc create_sequence_tc(int bound,
988                                        TypeCode JavaDoc element_type)
989     {
990         checkShutdownState();
991         return new TypeCodeImpl(this, TCKind._tk_sequence, bound, element_type);
992     }
993
994
995     /**
996      * Create a recursive TypeCode in a sequence.
997      *
998      * @param bound the bound for the sequence.
999      * @param offset the index to the enclosing TypeCode that is
1000     * being referenced.
1001     * @return the requested TypeCode.
1002     */

1003    public synchronized TypeCode JavaDoc create_recursive_sequence_tc(int bound,
1004                                                 int offset)
1005    {
1006        checkShutdownState();
1007        return new TypeCodeImpl(this, TCKind._tk_sequence, bound, offset);
1008    }
1009
1010
1011    /**
1012     * Create a TypeCode for an array.
1013     *
1014     * @param length the length of the array.
1015     * @param element_type
1016     * the type of elements of the array.
1017     * @return the requested TypeCode.
1018     */

1019    public synchronized TypeCode JavaDoc create_array_tc(int length,
1020                                    TypeCode JavaDoc element_type)
1021    {
1022        checkShutdownState();
1023        return new TypeCodeImpl(this, TCKind._tk_array, length, element_type);
1024    }
1025
1026
1027    public synchronized org.omg.CORBA.TypeCode JavaDoc create_native_tc(String JavaDoc id,
1028                                                   String JavaDoc name)
1029    {
1030        checkShutdownState();
1031        return new TypeCodeImpl(this, TCKind._tk_native, id, name);
1032    }
1033
1034    public synchronized org.omg.CORBA.TypeCode JavaDoc create_abstract_interface_tc(
1035                                                               String JavaDoc id,
1036                                                               String JavaDoc name)
1037    {
1038        checkShutdownState();
1039        return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name);
1040    }
1041
1042    public synchronized org.omg.CORBA.TypeCode JavaDoc create_fixed_tc(short digits, short scale)
1043    {
1044        checkShutdownState();
1045        return new TypeCodeImpl(this, TCKind._tk_fixed, digits, scale);
1046    }
1047
1048    public synchronized org.omg.CORBA.TypeCode JavaDoc create_value_tc(String JavaDoc id,
1049                                                  String JavaDoc name,
1050                                                  short type_modifier,
1051                                                  TypeCode JavaDoc concrete_base,
1052                                                  ValueMember JavaDoc[] members)
1053    {
1054        checkShutdownState();
1055        return new TypeCodeImpl(this, TCKind._tk_value, id, name,
1056                                type_modifier, concrete_base, members);
1057    }
1058
1059    public synchronized org.omg.CORBA.TypeCode JavaDoc create_recursive_tc(String JavaDoc id) {
1060        checkShutdownState();
1061        return new TypeCodeImpl(this, id);
1062    }
1063
1064    public synchronized org.omg.CORBA.TypeCode JavaDoc create_value_box_tc(String JavaDoc id,
1065                                                      String JavaDoc name,
1066                                                      TypeCode JavaDoc boxed_type)
1067    {
1068        checkShutdownState();
1069        return new TypeCodeImpl(this, TCKind._tk_value_box, id, name,
1070        boxed_type);
1071    }
1072
1073    /**
1074     * Create a new Any
1075     *
1076     * @return the new Any created.
1077     */

1078    public synchronized Any JavaDoc create_any()
1079    {
1080        checkShutdownState();
1081        return new AnyImpl(this);
1082    }
1083
1084    // TypeCodeFactory interface methods.
1085
// Keeping track of type codes by repository id.
1086

1087    // Keeping a cache of TypeCodes associated with the class
1088
// they got created from in Util.writeAny().
1089

1090    public synchronized void setTypeCodeForClass(Class JavaDoc c, TypeCodeImpl tci)
1091    {
1092        if (typeCodeForClassMap == null)
1093            typeCodeForClassMap = Collections.synchronizedMap(
1094        new WeakHashMap JavaDoc(64));
1095        // Store only one TypeCode per class.
1096
if ( ! typeCodeForClassMap.containsKey(c))
1097            typeCodeForClassMap.put(c, tci);
1098    }
1099
1100    public synchronized TypeCodeImpl getTypeCodeForClass(Class JavaDoc c)
1101    {
1102        if (typeCodeForClassMap == null)
1103            return null;
1104        return (TypeCodeImpl)typeCodeForClassMap.get(c);
1105    }
1106
1107/****************************************************************************
1108 * The following methods deal with listing and resolving the initial
1109 * (bootstrap) object references such as "NameService".
1110 ****************************************************************************/

1111
1112    /**
1113     * Get a list of the initially available CORBA services.
1114     * This does not work unless an ORBInitialHost is specified during
1115     * initialization (or unless there is an ORB running on the AppletHost)
1116     * since the localhostname
1117     * is inaccessible to applets. If a service properties URL was specified,
1118     * then it is used, otherwise the bootstrapping protocol is used.
1119     * @return A list of the initial services available.
1120     */

1121    public String JavaDoc[] list_initial_services()
1122    {
1123    Resolver res ;
1124
1125    synchronized( this ) {
1126        checkShutdownState();
1127        res = resolver ;
1128    }
1129
1130    synchronized (resolverLock) {
1131        java.util.Set JavaDoc keys = res.list() ;
1132        return (String JavaDoc[])keys.toArray( new String JavaDoc[keys.size()] ) ;
1133    }
1134    }
1135
1136    /**
1137     * Resolve the stringified reference of one of the initially
1138     * available CORBA services.
1139     * @param identifier The stringified object reference of the
1140     * desired service.
1141     * @return An object reference for the desired service.
1142     * @exception InvalidName The supplied identifier is not associated
1143     * with a known service.
1144     * @exception SystemException One of a fixed set of Corba system exceptions.
1145     */

1146    public org.omg.CORBA.Object JavaDoc resolve_initial_references(
1147        String JavaDoc identifier) throws InvalidName JavaDoc
1148    {
1149    Resolver res ;
1150
1151    synchronized( this ) {
1152        checkShutdownState();
1153        res = resolver ;
1154    }
1155
1156    synchronized (resolverLock) {
1157        org.omg.CORBA.Object JavaDoc result = res.resolve( identifier ) ;
1158
1159        if (result == null)
1160        throw new InvalidName JavaDoc() ;
1161        else
1162        return result ;
1163    }
1164    }
1165
1166    /**
1167     * If this operation is called with an id, <code>"Y"</code>, and an
1168     * object, <code>YY</code>, then a subsequent call to
1169     * <code>ORB.resolve_initial_references( "Y" )</code> will
1170     * return object <code>YY</code>.
1171     *
1172     * @param id The ID by which the initial reference will be known.
1173     * @param obj The initial reference itself.
1174     * @throws InvalidName if this operation is called with an empty string id
1175     * or this operation is called with an id that is already registered,
1176     * including the default names defined by OMG.
1177     * @throws BAD_PARAM if the obj parameter is null.
1178     */

1179    public void register_initial_reference(
1180        String JavaDoc id, org.omg.CORBA.Object JavaDoc obj ) throws InvalidName JavaDoc
1181    {
1182    CorbaServerRequestDispatcher insnd ;
1183
1184        if ((id == null) || (id.length() == 0))
1185            throw new InvalidName JavaDoc() ;
1186
1187    synchronized (this) {
1188        checkShutdownState();
1189    }
1190
1191    synchronized (resolverLock) {
1192        insnd = insNamingDelegate ;
1193
1194        java.lang.Object JavaDoc obj2 = localResolver.resolve( id ) ;
1195        if (obj2 != null)
1196        throw new InvalidName JavaDoc(id + " already registered") ;
1197
1198        localResolver.register( id, ClosureFactory.makeConstant( obj )) ;
1199    }
1200      
1201    synchronized (this) {
1202        if (StubAdapter.isStub(obj))
1203        // Make all remote object references available for INS.
1204
requestDispatcherRegistry.registerServerRequestDispatcher(
1205            insnd, id ) ;
1206    }
1207    }
1208
1209/****************************************************************************
1210 * The following methods (introduced in POA / CORBA2.1) deal with
1211 * shutdown / single threading.
1212 ****************************************************************************/

1213
1214    public void run()
1215    {
1216    synchronized (this) {
1217        checkShutdownState();
1218    }
1219
1220        synchronized (runObj) {
1221            try {
1222                runObj.wait();
1223            } catch ( InterruptedException JavaDoc ex ) {}
1224        }
1225    }
1226
1227    public void shutdown(boolean wait_for_completion)
1228    {
1229    synchronized (this) {
1230        checkShutdownState();
1231    }
1232
1233        // Avoid more than one thread performing shutdown at a time.
1234
synchronized (shutdownObj) {
1235            checkShutdownState();
1236            // This is to avoid deadlock
1237
if (wait_for_completion &&
1238        isProcessingInvocation.get() == Boolean.TRUE) {
1239        throw omgWrapper.shutdownWaitForCompletionDeadlock() ;
1240            }
1241
1242            status = STATUS_SHUTTING_DOWN;
1243        // XXX access to requestDispatcherRegistry should be protected
1244
// by the ORBImpl instance monitor, but is not here in the
1245
// shutdownServants call.
1246
shutdownServants(wait_for_completion);
1247            if (wait_for_completion) {
1248                synchronized ( waitForCompletionObj ) {
1249                    while (numInvocations > 0) {
1250                        try {
1251                            waitForCompletionObj.wait();
1252                        } catch (InterruptedException JavaDoc ex) {}
1253                    }
1254                }
1255            }
1256            synchronized ( runObj ) {
1257                runObj.notifyAll();
1258            }
1259            status = STATUS_SHUTDOWN;
1260        }
1261    }
1262
1263    /** This method shuts down the ORB and causes orb.run() to return.
1264     * It will cause all POAManagers to be deactivated, which in turn
1265     * will cause all POAs to be deactivated.
1266     */

1267    protected void shutdownServants(boolean wait_for_completion) {
1268    Iterator JavaDoc iter = requestDispatcherRegistry.getObjectAdapterFactories().iterator() ;
1269    while (iter.hasNext()) {
1270        ObjectAdapterFactory oaf = (ObjectAdapterFactory)iter.next() ;
1271        oaf.shutdown( wait_for_completion ) ;
1272    }
1273    }
1274
1275    // REVISIT: was protected - made public for framework
1276
// Note that the caller must hold the ORBImpl lock.
1277
public void checkShutdownState()
1278    {
1279        if (status == STATUS_DESTROYED) {
1280        throw wrapper.orbDestroyed() ;
1281        }
1282
1283        if (status == STATUS_SHUTDOWN) {
1284        throw omgWrapper.badOperationAfterShutdown() ;
1285        }
1286    }
1287
1288    public boolean isDuringDispatch()
1289    {
1290    Boolean JavaDoc value = (Boolean JavaDoc)(isProcessingInvocation.get()) ;
1291    return value.booleanValue() ;
1292    }
1293
1294    public void startingDispatch()
1295    {
1296        synchronized (invocationObj) {
1297            isProcessingInvocation.set(Boolean.TRUE);
1298            numInvocations++;
1299        }
1300    }
1301
1302    public void finishedDispatch()
1303    {
1304        synchronized (invocationObj) {
1305            numInvocations--;
1306            isProcessingInvocation.set(Boolean.FALSE);
1307            if (numInvocations == 0) {
1308                synchronized (waitForCompletionObj) {
1309                    waitForCompletionObj.notifyAll();
1310                }
1311            } else if (numInvocations < 0) {
1312        throw wrapper.numInvocationsAlreadyZero(
1313            CompletionStatus.COMPLETED_YES ) ;
1314            }
1315        }
1316    }
1317
1318    /**
1319     * formal/99-10-07 p 159: "If destroy is called on an ORB that has
1320     * not been shut down, it will start the shutdown process and block until
1321     * the ORB has shut down before it destroys the ORB."
1322     */

1323    public synchronized void destroy()
1324    {
1325        if (status == STATUS_OPERATING) {
1326            shutdown(true);
1327        }
1328        getCorbaTransportManager().close();
1329    getPIHandler().destroyInterceptors() ;
1330        status = STATUS_DESTROYED;
1331    }
1332
1333    /**
1334     * Registers a value factory for a particular repository ID.
1335     *
1336     * @param repositoryID the repository ID.
1337     * @param factory the factory.
1338     * @return the previously registered factory for the given repository ID,
1339     * or null if no such factory was previously registered.
1340     * @exception org.omg.CORBA.BAD_PARAM if the registration fails.
1341     **/

1342    public synchronized ValueFactory JavaDoc register_value_factory(String JavaDoc repositoryID,
1343    ValueFactory JavaDoc factory)
1344    {
1345        checkShutdownState();
1346
1347        if ((repositoryID == null) || (factory == null))
1348        throw omgWrapper.unableRegisterValueFactory() ;
1349
1350        return (ValueFactory JavaDoc)valueFactoryCache.put(repositoryID, factory);
1351    }
1352
1353    /**
1354     * Unregisters a value factory for a particular repository ID.
1355     *
1356     * @param repositoryID the repository ID.
1357     **/

1358    public synchronized void unregister_value_factory(String JavaDoc repositoryID)
1359    {
1360        checkShutdownState();
1361
1362        if (valueFactoryCache.remove(repositoryID) == null)
1363        throw wrapper.nullParam() ;
1364    }
1365
1366    /**
1367     * Finds and returns a value factory for the given repository ID.
1368     * The value factory returned was previously registered by a call to
1369     * {@link #register_value_factory} or is the default factory.
1370     *
1371     * @param repositoryID the repository ID.
1372     * @return the value factory.
1373     * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
1374     **/

1375    public synchronized ValueFactory JavaDoc lookup_value_factory(String JavaDoc repositoryID)
1376    {
1377        checkShutdownState();
1378
1379        ValueFactory JavaDoc factory =
1380        (ValueFactory JavaDoc)valueFactoryCache.get(repositoryID);
1381
1382        if (factory == null) {
1383            try {
1384                factory = Utility.getFactory(null, null, null, repositoryID);
1385            } catch(org.omg.CORBA.MARSHAL JavaDoc ex) {
1386        throw wrapper.unableFindValueFactory( ex ) ;
1387            }
1388        }
1389
1390    return factory ;
1391    }
1392
1393    public OAInvocationInfo peekInvocationInfo()
1394    {
1395    StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
1396    return (OAInvocationInfo)(stack.peek()) ;
1397    }
1398
1399    public void pushInvocationInfo( OAInvocationInfo info )
1400    {
1401    StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
1402    stack.push( info ) ;
1403    }
1404
1405    public OAInvocationInfo popInvocationInfo()
1406    {
1407    StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
1408    return (OAInvocationInfo)(stack.pop()) ;
1409    }
1410
1411    /**
1412     * The bad server id handler is used by the Locator to
1413     * send back the location of a persistant server to the client.
1414     */

1415
1416    private Object JavaDoc badServerIdHandlerAccessLock = new Object JavaDoc();
1417
1418    public void initBadServerIdHandler()
1419    {
1420    synchronized (badServerIdHandlerAccessLock) {
1421        Class JavaDoc cls = configData.getBadServerIdHandler() ;
1422        if (cls != null) {
1423        try {
1424            Class JavaDoc[] params = new Class JavaDoc[] { org.omg.CORBA.ORB JavaDoc.class };
1425            java.lang.Object JavaDoc[] args = new java.lang.Object JavaDoc[]{this};
1426            Constructor JavaDoc cons = cls.getConstructor(params);
1427            badServerIdHandler =
1428            (BadServerIdHandler) cons.newInstance(args);
1429        } catch (Exception JavaDoc e) {
1430            throw wrapper.errorInitBadserveridhandler( e ) ;
1431        }
1432        }
1433    }
1434    }
1435
1436    public void setBadServerIdHandler( BadServerIdHandler handler )
1437    {
1438    synchronized (badServerIdHandlerAccessLock) {
1439        badServerIdHandler = handler;
1440    }
1441    }
1442
1443    public void handleBadServerId( ObjectKey okey )
1444    {
1445    synchronized (badServerIdHandlerAccessLock) {
1446        if (badServerIdHandler == null)
1447        throw wrapper.badServerId() ;
1448        else
1449        badServerIdHandler.handle( okey ) ;
1450    }
1451    }
1452
1453    public synchronized org.omg.CORBA.Policy JavaDoc create_policy( int type,
1454    org.omg.CORBA.Any JavaDoc val ) throws org.omg.CORBA.PolicyError JavaDoc
1455    {
1456    checkShutdownState() ;
1457
1458    return pihandler.create_policy( type, val ) ;
1459    }
1460
1461    /** This is the implementation of the public API used to connect
1462     * a servant-skeleton to the ORB.
1463     */

1464    public synchronized void connect(org.omg.CORBA.Object JavaDoc servant)
1465    {
1466        checkShutdownState();
1467    if (getTOAFactory() == null)
1468        throw wrapper.noToa() ;
1469
1470        try {
1471        String JavaDoc codebase = javax.rmi.CORBA.Util.getCodebase( servant.getClass() ) ;
1472        getTOAFactory().getTOA( codebase ).connect( servant ) ;
1473        } catch ( Exception JavaDoc ex ) {
1474        throw wrapper.orbConnectError( ex ) ;
1475        }
1476    }
1477
1478    public synchronized void disconnect(org.omg.CORBA.Object JavaDoc obj)
1479    {
1480        checkShutdownState();
1481    if (getTOAFactory() == null)
1482        throw wrapper.noToa() ;
1483
1484        try {
1485        getTOAFactory().getTOA().disconnect( obj ) ;
1486        } catch ( Exception JavaDoc ex ) {
1487        throw wrapper.orbConnectError( ex ) ;
1488        }
1489    }
1490
1491    public int getTransientServerId()
1492    {
1493        if( configData.getORBServerIdPropertySpecified( ) ) {
1494            // ORBServerId is specified then use that value
1495
return configData.getPersistentServerId( );
1496        }
1497        return transientServerId;
1498    }
1499
1500    public RequestDispatcherRegistry getRequestDispatcherRegistry()
1501    {
1502        return requestDispatcherRegistry;
1503    }
1504
1505    public ServiceContextRegistry getServiceContextRegistry()
1506    {
1507    return serviceContextRegistry ;
1508    }
1509
1510    // XXX All of the isLocalXXX checking needs to be revisited.
1511
// First of all, all three of these methods are called from
1512
// only one place in impl.ior.IORImpl. Second, we have problems
1513
// both with multi-homed hosts and with multi-profile IORs.
1514
// A possible strategy: like the LocalClientRequestDispatcher, we need
1515
// to determine this more abstractly at the ContactInfo level.
1516
// This level should probably just get the CorbaContactInfoList from
1517
// the IOR, then iterator over ContactInfo. If any ContactInfo is
1518
// local, the IOR is local, and we can pick one to create the
1519
// LocalClientRequestDispatcher as well. Bottom line: this code needs to move.
1520

1521    // XXX What about multi-homed host?
1522
public boolean isLocalHost( String JavaDoc hostName )
1523    {
1524    return hostName.equals( configData.getORBServerHost() ) ||
1525        hostName.equals( getLocalHostName() ) ;
1526    }
1527
1528    public boolean isLocalServerId( int subcontractId, int serverId )
1529    {
1530    if ((subcontractId < ORBConstants.FIRST_POA_SCID) ||
1531        (subcontractId > ORBConstants.MAX_POA_SCID))
1532        return serverId == getTransientServerId( ) ;
1533        
1534    // XXX isTransient info should be stored in subcontract registry
1535
if (ORBConstants.isTransient( subcontractId ))
1536        return (serverId == getTransientServerId()) ;
1537    else if (configData.getPersistentServerIdInitialized())
1538        return (serverId == configData.getPersistentServerId()) ;
1539    else
1540        return false ;
1541    }
1542
1543    /*************************************************************************
1544     * The following public methods are for ORB shutdown.
1545     *************************************************************************/

1546
1547    private String JavaDoc getHostName(String JavaDoc host)
1548    throws java.net.UnknownHostException JavaDoc
1549    {
1550        return InetAddress.getByName( host ).getHostAddress();
1551    }
1552
1553    /* keeping a copy of the getLocalHostName so that it can only be called
1554     * internally and the unauthorized clients cannot have access to the
1555     * localHost information, originally, the above code was calling
1556     * getLocalHostName from Connection.java. If the hostname is cached in
1557     * Connection.java, then
1558     * it is a security hole, since any unauthorized client has access to
1559     * the host information. With this change it is used internally so the
1560     * security problem is resolved. Also in Connection.java, the
1561     * getLocalHost() implementation has changed to always call the
1562     * InetAddress.getLocalHost().getHostAddress()
1563     * The above mentioned method has been removed from the connection class
1564     */

1565
1566    private static String JavaDoc localHostString = null;
1567
1568    private synchronized String JavaDoc getLocalHostName()
1569    {
1570        if (localHostString == null) {
1571            try {
1572        localHostString = InetAddress.getLocalHost().getHostAddress();
1573            } catch (Exception JavaDoc ex) {
1574        throw wrapper.getLocalHostFailed( ex ) ;
1575            }
1576    }
1577    return localHostString ;
1578    }
1579
1580 /******************************************************************************
1581 * The following public methods are for ORB shutdown.
1582 *
1583 ******************************************************************************/

1584
1585    /** This method always returns false because the ORB never needs the
1586     * main thread to do work.
1587     */

1588    public synchronized boolean work_pending()
1589    {
1590        checkShutdownState();
1591    throw wrapper.genericNoImpl() ;
1592    }
1593  
1594    /** This method does nothing. It is not required by the spec to do anything!
1595     */

1596    public synchronized void perform_work()
1597    {
1598        checkShutdownState();
1599    throw wrapper.genericNoImpl() ;
1600    }
1601
1602    public synchronized void set_delegate(java.lang.Object JavaDoc servant){
1603        checkShutdownState();
1604
1605    POAFactory poaFactory = getPOAFactory() ;
1606    if (poaFactory != null)
1607        ((org.omg.PortableServer.Servant JavaDoc)servant)
1608        ._set_delegate( poaFactory.getDelegateImpl() ) ;
1609    else
1610        throw wrapper.noPoa() ;
1611    }
1612
1613    ////////////////////////////////////////////////////
1614
//
1615
// pept.broker.Broker
1616
//
1617

1618    public ClientInvocationInfo createOrIncrementInvocationInfo()
1619    {
1620    StackImpl invocationInfoStack =
1621        (StackImpl) clientInvocationInfoStack.get();
1622    ClientInvocationInfo clientInvocationInfo = null;
1623    if (!invocationInfoStack.empty()) {
1624        clientInvocationInfo =
1625        (ClientInvocationInfo) invocationInfoStack.peek();
1626    }
1627    if ((clientInvocationInfo == null) ||
1628        (!clientInvocationInfo.isRetryInvocation()))
1629    {
1630        // This is a new call - not a retry.
1631
clientInvocationInfo = new CorbaInvocationInfo(this);
1632        startingDispatch();
1633        invocationInfoStack.push(clientInvocationInfo);
1634    }
1635    // Reset retry so recursive calls will get a new info object.
1636
clientInvocationInfo.setIsRetryInvocation(false);
1637    clientInvocationInfo.incrementEntryCount();
1638    return clientInvocationInfo;
1639    }
1640    
1641    public void releaseOrDecrementInvocationInfo()
1642    {
1643    StackImpl invocationInfoStack =
1644        (StackImpl)clientInvocationInfoStack.get();
1645    ClientInvocationInfo clientInvocationInfo = null;
1646    if (!invocationInfoStack.empty()) {
1647        clientInvocationInfo =
1648        (ClientInvocationInfo)invocationInfoStack.peek();
1649    } else {
1650        throw wrapper.invocationInfoStackEmpty() ;
1651    }
1652    clientInvocationInfo.decrementEntryCount();
1653    if (clientInvocationInfo.getEntryCount() == 0) {
1654        invocationInfoStack.pop();
1655        finishedDispatch();
1656    }
1657    }
1658    
1659    public ClientInvocationInfo getInvocationInfo()
1660    {
1661    StackImpl invocationInfoStack =
1662        (StackImpl) clientInvocationInfoStack.get();
1663    return (ClientInvocationInfo) invocationInfoStack.peek();
1664    }
1665
1666    ////////////////////////////////////////////////////
1667
//
1668
//
1669
//
1670

1671    private Object JavaDoc clientDelegateFactoryAccessorLock = new Object JavaDoc();
1672
1673    public void setClientDelegateFactory( ClientDelegateFactory factory )
1674    {
1675    synchronized (clientDelegateFactoryAccessorLock) {
1676        clientDelegateFactory = factory ;
1677    }
1678    }
1679
1680    public ClientDelegateFactory getClientDelegateFactory()
1681    {
1682    synchronized (clientDelegateFactoryAccessorLock) {
1683        return clientDelegateFactory ;
1684    }
1685    }
1686
1687    private Object JavaDoc corbaContactInfoListFactoryAccessLock = new Object JavaDoc();
1688
1689    public void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory )
1690    {
1691    synchronized (corbaContactInfoListFactoryAccessLock) {
1692        corbaContactInfoListFactory = factory ;
1693    }
1694    }
1695
1696    public synchronized CorbaContactInfoListFactory getCorbaContactInfoListFactory()
1697    {
1698    return corbaContactInfoListFactory ;
1699    }
1700
1701    /** Set the resolver used in this ORB. This resolver will be used for list_initial_services
1702     * and resolve_initial_references.
1703     */

1704    public void setResolver( Resolver resolver )
1705    {
1706    synchronized (resolverLock) {
1707        this.resolver = resolver ;
1708    }
1709    }
1710
1711    /** Get the resolver used in this ORB. This resolver will be used for list_initial_services
1712     * and resolve_initial_references.
1713     */

1714    public Resolver getResolver()
1715    {
1716    synchronized (resolverLock) {
1717        return resolver ;
1718    }
1719    }
1720
1721    /** Set the LocalResolver used in this ORB. This LocalResolver is used for
1722     * register_initial_reference only.
1723     */

1724    public void setLocalResolver( LocalResolver resolver )
1725    {
1726    synchronized (resolverLock) {
1727        this.localResolver = resolver ;
1728    }
1729    }
1730
1731    /** Get the LocalResolver used in this ORB. This LocalResolver is used for
1732     * register_initial_reference only.
1733     */

1734    public LocalResolver getLocalResolver()
1735    {
1736    synchronized (resolverLock) {
1737        return localResolver ;
1738    }
1739    }
1740
1741    /** Set the operation used in string_to_object calls. The Operation must expect a
1742     * String and return an org.omg.CORBA.Object.
1743     */

1744    public void setURLOperation( Operation stringToObject )
1745    {
1746    synchronized (resolverLock) {
1747        urlOperation = stringToObject ;
1748    }
1749    }
1750
1751    /** Get the operation used in string_to_object calls. The Operation must expect a
1752     * String and return an org.omg.CORBA.Object.
1753     */

1754    public Operation getURLOperation()
1755    {
1756    synchronized (resolverLock) {
1757        return urlOperation ;
1758    }
1759    }
1760
1761    public void setINSDelegate( CorbaServerRequestDispatcher sdel )
1762    {
1763    synchronized (resolverLock) {
1764        insNamingDelegate = sdel ;
1765    }
1766    }
1767
1768    public TaggedComponentFactoryFinder getTaggedComponentFactoryFinder()
1769    {
1770    return taggedComponentFactoryFinder ;
1771    }
1772
1773    public IdentifiableFactoryFinder getTaggedProfileFactoryFinder()
1774    {
1775    return taggedProfileFactoryFinder ;
1776    }
1777
1778    public IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder()
1779    {
1780    return taggedProfileTemplateFactoryFinder ;
1781    }
1782
1783    private Object JavaDoc objectKeyFactoryAccessLock = new Object JavaDoc();
1784
1785    public ObjectKeyFactory getObjectKeyFactory()
1786    {
1787    synchronized (objectKeyFactoryAccessLock) {
1788        return objectKeyFactory ;
1789    }
1790    }
1791
1792    public void setObjectKeyFactory( ObjectKeyFactory factory )
1793    {
1794    synchronized (objectKeyFactoryAccessLock) {
1795        objectKeyFactory = factory ;
1796    }
1797    }
1798
1799    private Object JavaDoc transportManagerAccessorLock = new Object JavaDoc();
1800
1801    public TransportManager getTransportManager()
1802    {
1803    synchronized (transportManagerAccessorLock) {
1804        if (transportManager == null) {
1805        transportManager = new CorbaTransportManagerImpl(this);
1806        }
1807        return transportManager;
1808    }
1809    }
1810
1811    public CorbaTransportManager getCorbaTransportManager()
1812    {
1813    return (CorbaTransportManager) getTransportManager();
1814    }
1815
1816    private Object JavaDoc legacyServerSocketManagerAccessLock = new Object JavaDoc();
1817
1818    public LegacyServerSocketManager getLegacyServerSocketManager()
1819    {
1820    synchronized (legacyServerSocketManagerAccessLock) {
1821        if (legacyServerSocketManager == null) {
1822        legacyServerSocketManager = new LegacyServerSocketManagerImpl(this);
1823        }
1824        return legacyServerSocketManager;
1825    }
1826    }
1827
1828    private Object JavaDoc threadPoolManagerAccessLock = new Object JavaDoc();
1829
1830    public void setThreadPoolManager(ThreadPoolManager mgr)
1831    {
1832    synchronized (threadPoolManagerAccessLock) {
1833        threadpoolMgr = mgr;
1834    }
1835    }
1836
1837    public ThreadPoolManager getThreadPoolManager()
1838    {
1839    synchronized (threadPoolManagerAccessLock) {
1840        if (threadpoolMgr == null) {
1841        threadpoolMgr = new ThreadPoolManagerImpl( threadGroup );
1842        }
1843        return threadpoolMgr;
1844    }
1845    }
1846
1847    public CopierManager getCopierManager()
1848    {
1849    return copierManager ;
1850    }
1851} // Class ORBImpl
1852

1853////////////////////////////////////////////////////////////////////////
1854
/// Helper class for a Synchronization Variable
1855
////////////////////////////////////////////////////////////////////////
1856

1857class SynchVariable
1858{
1859    // Synchronization Variable
1860
public boolean _flag;
1861
1862    // Constructor
1863
SynchVariable()
1864    {
1865        _flag = false;
1866    }
1867
1868    // set Flag to true
1869
public void set()
1870    {
1871        _flag = true;
1872    }
1873
1874        // get value
1875
public boolean value()
1876    {
1877        return _flag;
1878    }
1879
1880    // reset Flag to true
1881
public void reset()
1882    {
1883        _flag = false;
1884    }
1885}
1886
1887// End of file.
1888

1889
1890
Popular Tags