Mon, 28 May 2018 10:29:43 +0800
Merge
1 /*
2 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.corba.se.impl.orb;
28 import java.applet.Applet;
30 import java.io.IOException;
32 import java.lang.reflect.Constructor;
33 import java.lang.reflect.Field;
34 import java.lang.reflect.Modifier;
36 import java.util.Set;
37 import java.util.HashSet;
38 import java.util.Properties;
39 import java.util.Vector;
40 import java.util.Hashtable;
41 import java.util.Map;
42 import java.util.Collections;
43 import java.util.Enumeration;
44 import java.util.WeakHashMap;
46 import java.net.InetAddress;
48 import java.security.PrivilegedAction;
49 import java.security.Security;
50 import java.security.AccessController;
52 import javax.rmi.CORBA.ValueHandler;
54 import org.omg.CORBA.NVList;
55 import org.omg.CORBA.TCKind;
56 import org.omg.CORBA.NamedValue;
57 import org.omg.CORBA.Request;
58 import org.omg.CORBA.SystemException;
59 import org.omg.CORBA.CompletionStatus;
60 import org.omg.CORBA.TypeCode;
61 import org.omg.CORBA.Any;
62 import org.omg.CORBA.StructMember;
63 import org.omg.CORBA.UnionMember;
64 import org.omg.CORBA.ValueMember;
65 import org.omg.CORBA.BAD_PARAM;
67 import org.omg.CORBA.portable.ValueFactory;
69 import org.omg.CORBA.ORBPackage.InvalidName;
71 import com.sun.org.omg.SendingContext.CodeBase;
73 import com.sun.corba.se.pept.protocol.ClientInvocationInfo;
74 import com.sun.corba.se.pept.transport.TransportManager;
76 import com.sun.corba.se.spi.ior.IOR;
77 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder;
78 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder;
79 import com.sun.corba.se.spi.ior.IORFactories;
80 import com.sun.corba.se.spi.ior.ObjectKey;
81 import com.sun.corba.se.spi.ior.ObjectKeyFactory;
82 import com.sun.corba.se.spi.oa.OAInvocationInfo;
83 import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
84 import com.sun.corba.se.spi.orb.DataCollector;
85 import com.sun.corba.se.spi.orb.Operation;
86 import com.sun.corba.se.spi.orb.ORBData;
87 import com.sun.corba.se.spi.orb.ORBConfigurator;
88 import com.sun.corba.se.spi.orb.ParserImplBase;
89 import com.sun.corba.se.spi.orb.PropertyParser;
90 import com.sun.corba.se.spi.orb.OperationFactory;
91 import com.sun.corba.se.spi.orb.ORBVersion;
92 import com.sun.corba.se.spi.orb.ORBVersionFactory;
93 import com.sun.corba.se.spi.orbutil.closure.ClosureFactory;
94 import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager;
95 import com.sun.corba.se.spi.protocol.ClientDelegateFactory;
96 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
97 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
98 import com.sun.corba.se.spi.protocol.PIHandler;
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.transport.CorbaContactInfoListFactory;
102 import com.sun.corba.se.spi.transport.CorbaTransportManager;
103 import com.sun.corba.se.spi.ior.IORTypeCheckRegistry;
104 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
105 import com.sun.corba.se.spi.logging.CORBALogDomains;
106 import com.sun.corba.se.spi.copyobject.CopierManager;
107 import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
108 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry;
110 import com.sun.corba.se.impl.corba.TypeCodeImpl;
111 import com.sun.corba.se.impl.corba.NVListImpl;
112 import com.sun.corba.se.impl.corba.ExceptionListImpl;
113 import com.sun.corba.se.impl.corba.ContextListImpl;
114 import com.sun.corba.se.impl.corba.NamedValueImpl;
115 import com.sun.corba.se.impl.corba.EnvironmentImpl;
116 import com.sun.corba.se.impl.corba.AsynchInvoke;
117 import com.sun.corba.se.impl.corba.AnyImpl;
118 import com.sun.corba.se.impl.encoding.CachedCodeBase;
119 import com.sun.corba.se.impl.interceptors.PIHandlerImpl;
120 import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl;
121 import com.sun.corba.se.impl.ior.TaggedComponentFactoryFinderImpl;
122 import com.sun.corba.se.impl.ior.TaggedProfileFactoryFinderImpl;
123 import com.sun.corba.se.impl.ior.TaggedProfileTemplateFactoryFinderImpl;
124 import com.sun.corba.se.impl.oa.toa.TOAFactory;
125 import com.sun.corba.se.impl.oa.poa.BadServerIdHandler;
126 import com.sun.corba.se.impl.oa.poa.POAFactory;
127 import com.sun.corba.se.impl.orbutil.ORBConstants;
128 import com.sun.corba.se.impl.orbutil.ORBUtility;
129 import com.sun.corba.se.impl.orbutil.StackImpl;
130 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolManagerImpl;
131 import com.sun.corba.se.impl.protocol.RequestDispatcherRegistryImpl;
132 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo;
133 import com.sun.corba.se.impl.transport.CorbaTransportManagerImpl;
134 import com.sun.corba.se.impl.legacy.connection.LegacyServerSocketManagerImpl;
135 import com.sun.corba.se.impl.util.Utility;
136 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
137 import com.sun.corba.se.impl.copyobject.CopierManagerImpl;
138 import com.sun.corba.se.impl.ior.IORTypeCheckRegistryImpl;
140 /**
141 * The JavaIDL ORB implementation.
142 */
143 public class ORBImpl extends com.sun.corba.se.spi.orb.ORB
144 {
145 protected TransportManager transportManager;
146 protected LegacyServerSocketManager legacyServerSocketManager;
148 private ThreadLocal OAInvocationInfoStack ;
150 private ThreadLocal clientInvocationInfoStack ;
152 // pure java orb, caching the servant IOR per ORB
153 private static IOR codeBaseIOR ;
155 // Vector holding deferred Requests
156 private Vector dynamicRequests ;
157 private SynchVariable svResponseReceived ;
159 private java.lang.Object runObj = new java.lang.Object();
160 private java.lang.Object shutdownObj = new java.lang.Object();
161 private java.lang.Object waitForCompletionObj = new java.lang.Object();
162 private static final byte STATUS_OPERATING = 1;
163 private static final byte STATUS_SHUTTING_DOWN = 2;
164 private static final byte STATUS_SHUTDOWN = 3;
165 private static final byte STATUS_DESTROYED = 4;
166 private byte status = STATUS_OPERATING;
168 // XXX Should we move invocation tracking to the first level server dispatcher?
169 private java.lang.Object invocationObj = new java.lang.Object();
170 private int numInvocations = 0;
172 // thread local variable to store a boolean to detect deadlock in
173 // ORB.shutdown(true).
174 private ThreadLocal isProcessingInvocation = new ThreadLocal () {
175 protected java.lang.Object initialValue() {
176 return Boolean.FALSE;
177 }
178 };
180 // This map is caching TypeCodes created for a certain class (key)
181 // and is used in Util.writeAny()
182 private Map typeCodeForClassMap ;
184 // Cache to hold ValueFactories (Helper classes) keyed on repository ids
185 private Hashtable valueFactoryCache = new Hashtable();
187 // thread local variable to store the current ORB version.
188 // default ORB version is the version of ORB with correct Rep-id
189 // changes
190 private ThreadLocal orbVersionThreadLocal ;
192 private RequestDispatcherRegistry requestDispatcherRegistry ;
194 private CopierManager copierManager ;
196 private int transientServerId ;
198 private ServiceContextRegistry serviceContextRegistry ;
200 private IORTypeCheckRegistry iorTypeCheckRegistry;
202 // Needed here to implement connect/disconnect
203 private TOAFactory toaFactory ;
205 // Needed here for set_delegate
206 private POAFactory poaFactory ;
208 // The interceptor handler, which provides portable interceptor services for
209 // subcontracts and object adapters.
210 private PIHandler pihandler ;
212 private ORBData configData ;
214 private BadServerIdHandler badServerIdHandler ;
216 private ClientDelegateFactory clientDelegateFactory ;
218 private CorbaContactInfoListFactory corbaContactInfoListFactory ;
220 // All access to resolver, localResolver, and urlOperation must be protected using
221 // resolverLock. Do not hold the ORBImpl lock while accessing
222 // resolver, or deadlocks may occur.
223 // Note that we now have separate locks for each resolver type. This is due
224 // to bug 6980681 and 6238477, which was caused by a deadlock while resolving a
225 // corbaname: URL that contained a reference to the same ORB as the
226 // ORB making the call to string_to_object. This caused a deadlock between the
227 // client thread holding the single lock for access to the urlOperation,
228 // and the server thread handling the client is_a request waiting on the
229 // same lock to access the localResolver.
232 // Used for resolver_initial_references and list_initial_services
233 private Resolver resolver ;
235 // Used for register_initial_references
236 private LocalResolver localResolver ;
238 // Converts strings to object references for resolvers and string_to_object
239 private Operation urlOperation ;
240 private final Object urlOperationLock = new java.lang.Object() ;
242 private CorbaServerRequestDispatcher insNamingDelegate ;
244 // resolverLock must be used for all access to either resolver or
245 // localResolver, since it is possible for the resolver to indirectly
246 // refer to the localResolver. Also used to protect access to
247 // insNamingDelegate.
248 private final Object resolverLock = new Object() ;
250 private static final String IORTYPECHECKREGISTRY_FILTER_PROPNAME = "com.sun.CORBA.ORBIorTypeCheckRegistryFilter";
252 private TaggedComponentFactoryFinder taggedComponentFactoryFinder ;
254 private IdentifiableFactoryFinder taggedProfileFactoryFinder ;
256 private IdentifiableFactoryFinder taggedProfileTemplateFactoryFinder ;
258 private ObjectKeyFactory objectKeyFactory ;
260 private boolean orbOwnsThreadPoolManager = false ;
262 private ThreadPoolManager threadpoolMgr;
264 private void dprint( String msg )
265 {
266 ORBUtility.dprint( this, msg ) ;
267 }
269 ////////////////////////////////////////////////////
270 //
271 // NOTE:
272 //
273 // Methods that are synchronized MUST stay synchronized.
274 //
275 // Methods that are NOT synchronized must stay that way to avoid deadlock.
276 //
277 //
278 // REVISIT:
279 //
280 // checkShutDownState - lock on different object - and normalize usage.
281 // starting/FinishDispatch and Shutdown
282 //
284 public ORBData getORBData()
285 {
286 return configData ;
287 }
289 public PIHandler getPIHandler()
290 {
291 return pihandler ;
292 }
294 /**
295 * Create a new ORB. Should be followed by the appropriate
296 * set_parameters() call.
297 */
298 public ORBImpl()
299 {
300 // All initialization is done through set_parameters().
301 }
303 public ORBVersion getORBVersion()
304 {
305 synchronized (this) {
306 checkShutdownState();
307 }
308 return (ORBVersion)(orbVersionThreadLocal.get()) ;
309 }
311 public void setORBVersion(ORBVersion verObj)
312 {
313 synchronized (this) {
314 checkShutdownState();
315 }
316 orbVersionThreadLocal.set(verObj);
317 }
319 /****************************************************************************
320 * The following methods are ORB initialization
321 ****************************************************************************/
323 // preInit initializes all non-pluggable ORB data that is independent
324 // of the property parsing.
325 private void preInit( String[] params, Properties props )
326 {
327 // Before ORBConfiguration we need to set a PINoOpHandlerImpl,
328 // because PersisentServer Initialization inside configurator will
329 // invoke orb.resolve_initial_references( ) which will result in a
330 // check on piHandler to invoke Interceptors. We do not want any
331 // Interceptors to be invoked before the complete ORB initialization.
332 // piHandler will be replaced by a real PIHandler implementation at the
333 // end of this method.
334 pihandler = new PINoOpHandlerImpl( );
336 // This is the unique id of this server (JVM). Multiple incarnations
337 // of this server will get different ids.
338 // Compute transientServerId = milliseconds since Jan 1, 1970
339 // Note: transientServerId will wrap in about 2^32 / 86400000 = 49.7 days.
340 // If two ORBS are started at the same time then there is a possibility
341 // of having the same transientServerId. This may result in collision
342 // and may be a problem in ior.isLocal() check to see if the object
343 // belongs to the current ORB. This problem is taken care of by checking
344 // to see if the IOR port matches ORB server port in legacyIsLocalServerPort()
345 // method.
346 //
347 // XXX need to move server ID to a string for CORBA 3.0. At that point,
348 // make this more unique (possibly use java.rmi.server.UID).
349 transientServerId = (int)System.currentTimeMillis();
351 orbVersionThreadLocal = new ThreadLocal () {
352 protected java.lang.Object initialValue() {
353 // set default to version of the ORB with correct Rep-ids
354 return ORBVersionFactory.getORBVersion() ;
355 }
356 };
359 requestDispatcherRegistry = new RequestDispatcherRegistryImpl(
360 this, ORBConstants.DEFAULT_SCID);
361 copierManager = new CopierManagerImpl( this ) ;
363 taggedComponentFactoryFinder =
364 new TaggedComponentFactoryFinderImpl(this) ;
365 taggedProfileFactoryFinder =
366 new TaggedProfileFactoryFinderImpl(this) ;
367 taggedProfileTemplateFactoryFinder =
368 new TaggedProfileTemplateFactoryFinderImpl(this) ;
370 dynamicRequests = new Vector();
371 svResponseReceived = new SynchVariable();
373 OAInvocationInfoStack =
374 new ThreadLocal () {
375 protected java.lang.Object initialValue()
376 {
377 return new StackImpl();
378 }
379 };
381 clientInvocationInfoStack =
382 new ThreadLocal() {
383 protected java.lang.Object initialValue() {
384 return new StackImpl();
385 }
386 };
388 serviceContextRegistry = new ServiceContextRegistry( this ) ;
389 }
391 private void initIORTypeCheckRegistry() {
392 String filterProps = AccessController
393 .doPrivileged(new PrivilegedAction<String>() {
394 public String run() {
395 String props = System
396 .getProperty(IORTYPECHECKREGISTRY_FILTER_PROPNAME);
397 if (props == null) {
398 props = Security
399 .getProperty(IORTYPECHECKREGISTRY_FILTER_PROPNAME);
400 }
401 return props;
402 }
403 });
404 if (filterProps != null) {
405 try {
406 iorTypeCheckRegistry = new IORTypeCheckRegistryImpl(filterProps, this);
407 } catch (Exception ex) {
408 throw wrapper.bootstrapException(ex);
409 }
411 if (this.orbInitDebugFlag) {
412 dprint(".initIORTypeCheckRegistry, IORTypeCheckRegistryImpl created for properties == "
413 + filterProps);
414 }
415 } else {
416 if (this.orbInitDebugFlag) {
417 dprint(".initIORTypeCheckRegistry, IORTypeCheckRegistryImpl NOT created for properties == ");
418 }
419 }
420 }
422 protected void setDebugFlags( String[] args )
423 {
424 for (int ctr=0; ctr<args.length; ctr++ ) {
425 String token = args[ctr] ;
427 // If there is a public boolean data member in this class
428 // named token + "DebugFlag", set it to true.
429 try {
430 Field fld = this.getClass().getField( token + "DebugFlag" ) ;
431 int mod = fld.getModifiers() ;
432 if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
433 if (fld.getType() == boolean.class)
434 fld.setBoolean( this, true ) ;
435 } catch (Exception exc) {
436 // ignore it XXX log this as info
437 }
438 }
439 }
441 // Class that defines a parser that gets the name of the
442 // ORBConfigurator class.
443 private static class ConfigParser extends ParserImplBase {
444 // The default here is the ORBConfiguratorImpl that we define,
445 // but this can be replaced.
446 public Class configurator = ORBConfiguratorImpl.class ;
448 public PropertyParser makeParser()
449 {
450 PropertyParser parser = new PropertyParser() ;
451 parser.add( ORBConstants.SUN_PREFIX + "ORBConfigurator",
452 OperationFactory.classAction(), "configurator" ) ;
453 return parser ;
454 }
455 }
457 private void postInit( String[] params, DataCollector dataCollector )
458 {
459 // First, create the standard ORB config data.
460 // This must be initialized before the ORBConfigurator
461 // is executed.
462 configData = new ORBDataParserImpl( this, dataCollector) ;
464 // Set the debug flags early so they can be used by other
465 // parts of the initialization.
466 setDebugFlags( configData.getORBDebugFlags() ) ;
468 // REVISIT: this should go away after more transport init cleanup
469 // and going to ORT based ORBD.
470 getTransportManager();
471 getLegacyServerSocketManager();
473 // Create a parser to get the configured ORBConfigurator.
474 ConfigParser parser = new ConfigParser() ;
475 parser.init( dataCollector ) ;
477 ORBConfigurator configurator = null ;
478 try {
479 configurator =
480 (ORBConfigurator)(parser.configurator.newInstance()) ;
481 } catch (Exception iexc) {
482 throw wrapper.badOrbConfigurator( iexc, parser.configurator.getName() ) ;
483 }
485 // Finally, run the configurator. Note that the default implementation allows
486 // other configurators with their own parsers to run,
487 // using the same DataCollector.
488 try {
489 configurator.configure( dataCollector, this ) ;
490 } catch (Exception exc) {
491 throw wrapper.orbConfiguratorError( exc ) ;
492 }
494 // Last of all, create the PIHandler and run the ORB initializers.
495 pihandler = new PIHandlerImpl( this, params) ;
496 pihandler.initialize() ;
498 // Initialize the thread manager pool and byte buffer pool
499 // so they may be initialized & accessed without synchronization
500 getThreadPoolManager();
502 super.getByteBufferPool();
504 initIORTypeCheckRegistry();
505 }
507 private synchronized POAFactory getPOAFactory()
508 {
509 if (poaFactory == null) {
510 poaFactory = (POAFactory)requestDispatcherRegistry.getObjectAdapterFactory(
511 ORBConstants.TRANSIENT_SCID ) ;
512 }
514 return poaFactory ;
515 }
517 private synchronized TOAFactory getTOAFactory()
518 {
519 if (toaFactory == null) {
520 toaFactory = (TOAFactory)requestDispatcherRegistry.getObjectAdapterFactory(
521 ORBConstants.TOA_SCID ) ;
522 }
524 return toaFactory ;
525 }
527 public void set_parameters( Properties props )
528 {
529 synchronized (this) {
530 checkShutdownState();
531 }
532 preInit( null, props ) ;
533 DataCollector dataCollector =
534 DataCollectorFactory.create( props, getLocalHostName() ) ;
535 postInit( null, dataCollector ) ;
536 }
538 protected void set_parameters(Applet app, Properties props)
539 {
540 preInit( null, props ) ;
541 DataCollector dataCollector =
542 DataCollectorFactory.create( app, props, getLocalHostName() ) ;
543 postInit( null, dataCollector ) ;
544 }
546 protected void set_parameters (String[] params, Properties props)
547 {
548 preInit( params, props ) ;
549 DataCollector dataCollector =
550 DataCollectorFactory.create( params, props, getLocalHostName() ) ;
551 postInit( params, dataCollector ) ;
552 }
554 /****************************************************************************
555 * The following methods are standard public CORBA ORB APIs
556 ****************************************************************************/
558 public synchronized org.omg.CORBA.portable.OutputStream create_output_stream()
559 {
560 checkShutdownState();
561 return sun.corba.OutputStreamFactory.newEncapsOutputStream(this);
562 }
564 /**
565 * Get a Current pseudo-object.
566 * The Current interface is used to manage thread-specific
567 * information for use by the transactions, security and other
568 * services. This method is deprecated,
569 * and replaced by ORB.resolve_initial_references("NameOfCurrentObject");
570 *
571 * @return a Current pseudo-object.
572 * @deprecated
573 */
574 public synchronized org.omg.CORBA.Current get_current()
575 {
576 checkShutdownState();
578 /* _REVISIT_
579 The implementation of get_current is not clear. How would
580 ORB know whether the caller wants a Current for transactions
581 or security ?? Or is it assumed that there is just one
582 implementation for both ? If Current is thread-specific,
583 then it should not be instantiated; so where does the
584 ORB get a Current ?
586 This should probably be deprecated. */
588 throw wrapper.genericNoImpl() ;
589 }
591 /**
592 * Create an NVList
593 *
594 * @param count size of list to create
595 * @result NVList created
596 *
597 * @see NVList
598 */
599 public synchronized NVList create_list(int count)
600 {
601 checkShutdownState();
602 return new NVListImpl(this, count);
603 }
605 /**
606 * Create an NVList corresponding to an OperationDef
607 *
608 * @param oper operation def to use to create list
609 * @result NVList created
610 *
611 * @see NVList
612 */
613 public synchronized NVList create_operation_list(org.omg.CORBA.Object oper)
614 {
615 checkShutdownState();
616 throw wrapper.genericNoImpl() ;
617 }
619 /**
620 * Create a NamedValue
621 *
622 * @result NamedValue created
623 */
624 public synchronized NamedValue create_named_value(String s, Any any, int flags)
625 {
626 checkShutdownState();
627 return new NamedValueImpl(this, s, any, flags);
628 }
630 /**
631 * Create an ExceptionList
632 *
633 * @result ExceptionList created
634 */
635 public synchronized org.omg.CORBA.ExceptionList create_exception_list()
636 {
637 checkShutdownState();
638 return new ExceptionListImpl();
639 }
641 /**
642 * Create a ContextList
643 *
644 * @result ContextList created
645 */
646 public synchronized org.omg.CORBA.ContextList create_context_list()
647 {
648 checkShutdownState();
649 return new ContextListImpl(this);
650 }
652 /**
653 * Get the default Context object
654 *
655 * @result the default Context object
656 */
657 public synchronized org.omg.CORBA.Context get_default_context()
658 {
659 checkShutdownState();
660 throw wrapper.genericNoImpl() ;
661 }
663 /**
664 * Create an Environment
665 *
666 * @result Environment created
667 */
668 public synchronized org.omg.CORBA.Environment create_environment()
669 {
670 checkShutdownState();
671 return new EnvironmentImpl();
672 }
674 public synchronized void send_multiple_requests_oneway(Request[] req)
675 {
676 checkShutdownState();
678 // Invoke the send_oneway on each new Request
679 for (int i = 0; i < req.length; i++) {
680 req[i].send_oneway();
681 }
682 }
684 /**
685 * Send multiple dynamic requests asynchronously.
686 *
687 * @param req an array of request objects.
688 */
689 public synchronized void send_multiple_requests_deferred(Request[] req)
690 {
691 checkShutdownState();
693 // add the new Requests to pending dynamic Requests
694 for (int i = 0; i < req.length; i++) {
695 dynamicRequests.addElement(req[i]);
696 }
698 // Invoke the send_deferred on each new Request
699 for (int i = 0; i < req.length; i++) {
700 AsynchInvoke invokeObject = new AsynchInvoke( this,
701 (com.sun.corba.se.impl.corba.RequestImpl)req[i], true);
702 new Thread(invokeObject).start();
703 }
704 }
706 /**
707 * Find out if any of the deferred invocations have a response yet.
708 */
709 public synchronized boolean poll_next_response()
710 {
711 checkShutdownState();
713 Request currRequest;
715 // poll on each pending request
716 Enumeration ve = dynamicRequests.elements();
717 while (ve.hasMoreElements() == true) {
718 currRequest = (Request)ve.nextElement();
719 if (currRequest.poll_response() == true) {
720 return true;
721 }
722 }
723 return false;
724 }
726 /**
727 * Get the next request that has gotten a response.
728 *
729 * @result the next request ready with a response.
730 */
731 public org.omg.CORBA.Request get_next_response()
732 throws org.omg.CORBA.WrongTransaction
733 {
734 synchronized( this ) {
735 checkShutdownState();
736 }
738 while (true) {
739 // check if there already is a response
740 synchronized ( dynamicRequests ) {
741 Enumeration elems = dynamicRequests.elements();
742 while ( elems.hasMoreElements() ) {
743 Request currRequest = (Request)elems.nextElement();
744 if ( currRequest.poll_response() ) {
745 // get the response for this successfully polled Request
746 currRequest.get_response();
747 dynamicRequests.removeElement(currRequest);
748 return currRequest;
749 }
750 }
751 }
753 // wait for a response
754 synchronized(this.svResponseReceived) {
755 while (!this.svResponseReceived.value()) {
756 try {
757 this.svResponseReceived.wait();
758 } catch(java.lang.InterruptedException ex) {
759 // NO-OP
760 }
761 }
762 // reinitialize the response flag
763 this.svResponseReceived.reset();
764 }
765 }
766 }
768 /**
769 * Notify response to ORB for get_next_response
770 */
771 public void notifyORB()
772 {
773 synchronized (this) {
774 checkShutdownState();
775 }
776 synchronized (this.svResponseReceived) {
777 this.svResponseReceived.set();
778 this.svResponseReceived.notify();
779 }
780 }
782 /**
783 * Convert an object ref to a string.
784 * @param obj The object to stringify.
785 * @return A stringified object reference.
786 */
787 public synchronized String object_to_string(org.omg.CORBA.Object obj)
788 {
789 checkShutdownState();
791 // Handle the null objref case
792 if (obj == null) {
793 IOR nullIOR = IORFactories.makeIOR( this ) ;
794 return nullIOR.stringify();
795 }
797 IOR ior = null ;
799 try {
800 ior = ORBUtility.connectAndGetIOR( this, obj ) ;
801 } catch (BAD_PARAM bp) {
802 // Throw MARSHAL instead if this is a LOCAL_OBJECT_NOT_ALLOWED error.
803 if (bp.minor == ORBUtilSystemException.LOCAL_OBJECT_NOT_ALLOWED) {
804 throw omgWrapper.notAnObjectImpl( bp ) ;
805 } else
806 // Not a local object problem: just rethrow the exception.
807 // Do not wrap and log this, since it was already logged at its
808 // point of origin.
809 throw bp ;
810 }
812 return ior.stringify() ;
813 }
815 /**
816 * Convert a stringified object reference to the object it represents.
817 * @param str The stringified object reference.
818 * @return The unstringified object reference.
819 */
820 public org.omg.CORBA.Object string_to_object(String str)
821 {
822 Operation op ;
824 synchronized (this) {
825 checkShutdownState();
826 op = urlOperation ;
827 }
829 if (str == null)
830 throw wrapper.nullParam() ;
832 synchronized (urlOperationLock) {
833 org.omg.CORBA.Object obj = (org.omg.CORBA.Object)op.operate( str ) ;
834 return obj ;
835 }
836 }
838 // pure java orb support, moved this method from FVDCodeBaseImpl.
839 // Note that we connect this if we have not already done so.
840 public synchronized IOR getFVDCodeBaseIOR()
841 {
842 checkShutdownState();
844 if (codeBaseIOR != null) // i.e. We are already connected to it
845 return codeBaseIOR;
847 // backward compatability 4365188
848 CodeBase cb;
850 ValueHandler vh = ORBUtility.createValueHandler();
852 cb = (CodeBase)vh.getRunTimeCodeBase();
853 return ORBUtility.connectAndGetIOR( this, cb ) ;
854 }
856 /**
857 * Get the TypeCode for a primitive type.
858 *
859 * @param tcKind the integer kind for the primitive type
860 * @return the requested TypeCode
861 */
862 public synchronized TypeCode get_primitive_tc(TCKind tcKind)
863 {
864 checkShutdownState();
865 return get_primitive_tc( tcKind.value() ) ;
866 }
868 /**
869 * Create a TypeCode for a structure.
870 *
871 * @param id the logical id for the typecode.
872 * @param name the name for the typecode.
873 * @param members an array describing the members of the TypeCode.
874 * @return the requested TypeCode.
875 */
876 public synchronized TypeCode create_struct_tc(String id,
877 String name,
878 StructMember[] members)
879 {
880 checkShutdownState();
881 return new TypeCodeImpl(this, TCKind._tk_struct, id, name, members);
882 }
884 /**
885 * Create a TypeCode for a union.
886 *
887 * @param id the logical id for the typecode.
888 * @param name the name for the typecode.
889 * @param discriminator_type
890 * the type of the union discriminator.
891 * @param members an array describing the members of the TypeCode.
892 * @return the requested TypeCode.
893 */
894 public synchronized TypeCode create_union_tc(String id,
895 String name,
896 TypeCode discriminator_type,
897 UnionMember[] members)
898 {
899 checkShutdownState();
900 return new TypeCodeImpl(this,
901 TCKind._tk_union,
902 id,
903 name,
904 discriminator_type,
905 members);
906 }
908 /**
909 * Create a TypeCode for an enum.
910 *
911 * @param id the logical id for the typecode.
912 * @param name the name for the typecode.
913 * @param members an array describing the members of the TypeCode.
914 * @return the requested TypeCode.
915 */
916 public synchronized TypeCode create_enum_tc(String id,
917 String name,
918 String[] members)
919 {
920 checkShutdownState();
921 return new TypeCodeImpl(this, TCKind._tk_enum, id, name, members);
922 }
924 /**
925 * Create a TypeCode for an alias.
926 *
927 * @param id the logical id for the typecode.
928 * @param name the name for the typecode.
929 * @param original_type
930 * the type this is an alias for.
931 * @return the requested TypeCode.
932 */
933 public synchronized TypeCode create_alias_tc(String id,
934 String name,
935 TypeCode original_type)
936 {
937 checkShutdownState();
938 return new TypeCodeImpl(this, TCKind._tk_alias, id, name, original_type);
939 }
941 /**
942 * Create a TypeCode for an exception.
943 *
944 * @param id the logical id for the typecode.
945 * @param name the name for the typecode.
946 * @param members an array describing the members of the TypeCode.
947 * @return the requested TypeCode.
948 */
949 public synchronized TypeCode create_exception_tc(String id,
950 String name,
951 StructMember[] members)
952 {
953 checkShutdownState();
954 return new TypeCodeImpl(this, TCKind._tk_except, id, name, members);
955 }
957 /**
958 * Create a TypeCode for an interface.
959 *
960 * @param id the logical id for the typecode.
961 * @param name the name for the typecode.
962 * @return the requested TypeCode.
963 */
964 public synchronized TypeCode create_interface_tc(String id,
965 String name)
966 {
967 checkShutdownState();
968 return new TypeCodeImpl(this, TCKind._tk_objref, id, name);
969 }
971 /**
972 * Create a TypeCode for a string.
973 *
974 * @param bound the bound for the string.
975 * @return the requested TypeCode.
976 */
977 public synchronized TypeCode create_string_tc(int bound)
978 {
979 checkShutdownState();
980 return new TypeCodeImpl(this, TCKind._tk_string, bound);
981 }
983 /**
984 * Create a TypeCode for a wide string.
985 *
986 * @param bound the bound for the string.
987 * @return the requested TypeCode.
988 */
989 public synchronized TypeCode create_wstring_tc(int bound)
990 {
991 checkShutdownState();
992 return new TypeCodeImpl(this, TCKind._tk_wstring, bound);
993 }
995 /**
996 * Create a TypeCode for a sequence.
997 *
998 * @param bound the bound for the sequence.
999 * @param element_type
1000 * the type of elements of the sequence.
1001 * @return the requested TypeCode.
1002 */
1003 public synchronized TypeCode create_sequence_tc(int bound,
1004 TypeCode element_type)
1005 {
1006 checkShutdownState();
1007 return new TypeCodeImpl(this, TCKind._tk_sequence, bound, element_type);
1008 }
1011 /**
1012 * Create a recursive TypeCode in a sequence.
1013 *
1014 * @param bound the bound for the sequence.
1015 * @param offset the index to the enclosing TypeCode that is
1016 * being referenced.
1017 * @return the requested TypeCode.
1018 */
1019 public synchronized TypeCode create_recursive_sequence_tc(int bound,
1020 int offset)
1021 {
1022 checkShutdownState();
1023 return new TypeCodeImpl(this, TCKind._tk_sequence, bound, offset);
1024 }
1027 /**
1028 * Create a TypeCode for an array.
1029 *
1030 * @param length the length of the array.
1031 * @param element_type
1032 * the type of elements of the array.
1033 * @return the requested TypeCode.
1034 */
1035 public synchronized TypeCode create_array_tc(int length,
1036 TypeCode element_type)
1037 {
1038 checkShutdownState();
1039 return new TypeCodeImpl(this, TCKind._tk_array, length, element_type);
1040 }
1043 public synchronized org.omg.CORBA.TypeCode create_native_tc(String id,
1044 String name)
1045 {
1046 checkShutdownState();
1047 return new TypeCodeImpl(this, TCKind._tk_native, id, name);
1048 }
1050 public synchronized org.omg.CORBA.TypeCode create_abstract_interface_tc(
1051 String id,
1052 String name)
1053 {
1054 checkShutdownState();
1055 return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name);
1056 }
1058 public synchronized org.omg.CORBA.TypeCode create_fixed_tc(short digits, short scale)
1059 {
1060 checkShutdownState();
1061 return new TypeCodeImpl(this, TCKind._tk_fixed, digits, scale);
1062 }
1064 public synchronized org.omg.CORBA.TypeCode create_value_tc(String id,
1065 String name,
1066 short type_modifier,
1067 TypeCode concrete_base,
1068 ValueMember[] members)
1069 {
1070 checkShutdownState();
1071 return new TypeCodeImpl(this, TCKind._tk_value, id, name,
1072 type_modifier, concrete_base, members);
1073 }
1075 public synchronized org.omg.CORBA.TypeCode create_recursive_tc(String id) {
1076 checkShutdownState();
1077 return new TypeCodeImpl(this, id);
1078 }
1080 public synchronized org.omg.CORBA.TypeCode create_value_box_tc(String id,
1081 String name,
1082 TypeCode boxed_type)
1083 {
1084 checkShutdownState();
1085 return new TypeCodeImpl(this, TCKind._tk_value_box, id, name,
1086 boxed_type);
1087 }
1089 /**
1090 * Create a new Any
1091 *
1092 * @return the new Any created.
1093 */
1094 public synchronized Any create_any()
1095 {
1096 checkShutdownState();
1097 return new AnyImpl(this);
1098 }
1100 // TypeCodeFactory interface methods.
1101 // Keeping track of type codes by repository id.
1103 // Keeping a cache of TypeCodes associated with the class
1104 // they got created from in Util.writeAny().
1106 public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci)
1107 {
1108 checkShutdownState();
1110 if (typeCodeForClassMap == null)
1111 typeCodeForClassMap = Collections.synchronizedMap(
1112 new WeakHashMap(64));
1113 // Store only one TypeCode per class.
1114 if ( ! typeCodeForClassMap.containsKey(c))
1115 typeCodeForClassMap.put(c, tci);
1116 }
1118 public synchronized TypeCodeImpl getTypeCodeForClass(Class c)
1119 {
1120 checkShutdownState();
1122 if (typeCodeForClassMap == null)
1123 return null;
1124 return (TypeCodeImpl)typeCodeForClassMap.get(c);
1125 }
1127 /****************************************************************************
1128 * The following methods deal with listing and resolving the initial
1129 * (bootstrap) object references such as "NameService".
1130 ****************************************************************************/
1132 /**
1133 * Get a list of the initially available CORBA services.
1134 * This does not work unless an ORBInitialHost is specified during
1135 * initialization (or unless there is an ORB running on the AppletHost)
1136 * since the localhostname
1137 * is inaccessible to applets. If a service properties URL was specified,
1138 * then it is used, otherwise the bootstrapping protocol is used.
1139 * @return A list of the initial services available.
1140 */
1141 public String[] list_initial_services()
1142 {
1143 Resolver res ;
1145 synchronized( this ) {
1146 checkShutdownState();
1147 res = resolver ;
1148 }
1150 synchronized (resolverLock) {
1151 java.util.Set keys = res.list() ;
1152 return (String[])keys.toArray( new String[keys.size()] ) ;
1153 }
1154 }
1156 /**
1157 * Resolve the stringified reference of one of the initially
1158 * available CORBA services.
1159 * @param identifier The stringified object reference of the
1160 * desired service.
1161 * @return An object reference for the desired service.
1162 * @exception InvalidName The supplied identifier is not associated
1163 * with a known service.
1164 * @exception SystemException One of a fixed set of Corba system exceptions.
1165 */
1166 public org.omg.CORBA.Object resolve_initial_references(
1167 String identifier) throws InvalidName
1168 {
1169 Resolver res ;
1171 synchronized( this ) {
1172 checkShutdownState();
1173 res = resolver ;
1174 }
1176 synchronized (resolverLock) {
1177 org.omg.CORBA.Object result = res.resolve( identifier ) ;
1179 if (result == null)
1180 throw new InvalidName() ;
1181 else
1182 return result ;
1183 }
1184 }
1186 /**
1187 * If this operation is called with an id, <code>"Y"</code>, and an
1188 * object, <code>YY</code>, then a subsequent call to
1189 * <code>ORB.resolve_initial_references( "Y" )</code> will
1190 * return object <code>YY</code>.
1191 *
1192 * @param id The ID by which the initial reference will be known.
1193 * @param obj The initial reference itself.
1194 * @throws InvalidName if this operation is called with an empty string id
1195 * or this operation is called with an id that is already registered,
1196 * including the default names defined by OMG.
1197 * @throws BAD_PARAM if the obj parameter is null.
1198 */
1199 public void register_initial_reference(
1200 String id, org.omg.CORBA.Object obj ) throws InvalidName
1201 {
1202 CorbaServerRequestDispatcher insnd ;
1204 synchronized (this) {
1205 checkShutdownState();
1206 }
1208 if ((id == null) || (id.length() == 0))
1209 throw new InvalidName() ;
1211 synchronized (this) {
1212 checkShutdownState();
1213 }
1215 synchronized (resolverLock) {
1216 insnd = insNamingDelegate ;
1218 java.lang.Object obj2 = localResolver.resolve( id ) ;
1219 if (obj2 != null)
1220 throw new InvalidName(id + " already registered") ;
1222 localResolver.register( id, ClosureFactory.makeConstant( obj )) ;
1223 }
1225 synchronized (this) {
1226 if (StubAdapter.isStub(obj))
1227 // Make all remote object references available for INS.
1228 requestDispatcherRegistry.registerServerRequestDispatcher(
1229 insnd, id ) ;
1230 }
1231 }
1233 /****************************************************************************
1234 * The following methods (introduced in POA / CORBA2.1) deal with
1235 * shutdown / single threading.
1236 ****************************************************************************/
1238 public void run()
1239 {
1240 synchronized (this) {
1241 checkShutdownState();
1242 }
1244 synchronized (runObj) {
1245 try {
1246 runObj.wait();
1247 } catch ( InterruptedException ex ) {}
1248 }
1249 }
1251 public void shutdown(boolean wait_for_completion) {
1252 boolean wait = false;
1254 synchronized (this) {
1255 checkShutdownState();
1257 // This is to avoid deadlock: don't allow a thread that is
1258 // processing a request to call shutdown( true ), because
1259 // the shutdown would block waiting for the request to complete,
1260 // while the request would block waiting for shutdown to complete.
1261 if (wait_for_completion &&
1262 isProcessingInvocation.get() == Boolean.TRUE) {
1263 throw omgWrapper.shutdownWaitForCompletionDeadlock();
1264 }
1266 if (status == STATUS_SHUTTING_DOWN) {
1267 if (wait_for_completion) {
1268 wait = true;
1269 } else {
1270 return;
1271 }
1272 }
1274 status = STATUS_SHUTTING_DOWN;
1275 }
1277 // Avoid more than one thread performing shutdown at a time.
1278 synchronized (shutdownObj) {
1279 // At this point, the ORB status is certainly STATUS_SHUTTING_DOWN.
1280 // If wait is true, another thread already called shutdown( true ),
1281 // and so we wait for completion
1282 if (wait) {
1283 while (true) {
1284 synchronized (this) {
1285 if (status == STATUS_SHUTDOWN)
1286 break;
1287 }
1289 try {
1290 shutdownObj.wait();
1291 } catch (InterruptedException exc) {
1292 // NOP: just loop and wait until state is changed
1293 }
1294 }
1295 } else {
1296 // perform the actual shutdown
1297 shutdownServants(wait_for_completion);
1299 if (wait_for_completion) {
1300 synchronized ( waitForCompletionObj ) {
1301 while (numInvocations > 0) {
1302 try {
1303 waitForCompletionObj.wait();
1304 } catch (InterruptedException ex) {}
1305 }
1306 }
1307 }
1309 synchronized (runObj) {
1310 runObj.notifyAll();
1311 }
1313 status = STATUS_SHUTDOWN;
1315 shutdownObj.notifyAll();
1316 }
1317 }
1318 }
1320 // Cause all ObjectAdapaterFactories to clean up all of their internal state, which
1321 // may include activated objects that have associated state and callbacks that must
1322 // complete in order to shutdown. This will cause new request to be rejected.
1323 protected void shutdownServants(boolean wait_for_completion) {
1324 Set<ObjectAdapterFactory> oaset;
1325 synchronized (this) {
1326 oaset = new HashSet<>(requestDispatcherRegistry.getObjectAdapterFactories());
1327 }
1329 for (ObjectAdapterFactory oaf : oaset)
1330 oaf.shutdown(wait_for_completion);
1331 }
1333 // Note that the caller must hold the ORBImpl lock.
1334 public void checkShutdownState()
1335 {
1336 if (status == STATUS_DESTROYED) {
1337 throw wrapper.orbDestroyed() ;
1338 }
1340 if (status == STATUS_SHUTDOWN) {
1341 throw omgWrapper.badOperationAfterShutdown() ;
1342 }
1343 }
1345 public boolean isDuringDispatch()
1346 {
1347 synchronized (this) {
1348 checkShutdownState();
1349 }
1350 Boolean value = (Boolean)(isProcessingInvocation.get()) ;
1351 return value.booleanValue() ;
1352 }
1354 public void startingDispatch()
1355 {
1356 synchronized (this) {
1357 checkShutdownState();
1358 }
1359 synchronized (invocationObj) {
1360 isProcessingInvocation.set(Boolean.TRUE);
1361 numInvocations++;
1362 }
1363 }
1365 public void finishedDispatch()
1366 {
1367 synchronized (this) {
1368 checkShutdownState();
1369 }
1370 synchronized (invocationObj) {
1371 numInvocations--;
1372 isProcessingInvocation.set(false);
1373 if (numInvocations == 0) {
1374 synchronized (waitForCompletionObj) {
1375 waitForCompletionObj.notifyAll();
1376 }
1377 } else if (numInvocations < 0) {
1378 throw wrapper.numInvocationsAlreadyZero(
1379 CompletionStatus.COMPLETED_YES);
1380 }
1381 }
1382 }
1384 /**
1385 * formal/99-10-07 p 159: "If destroy is called on an ORB that has
1386 * not been shut down, it will start the shutdown process and block until
1387 * the ORB has shut down before it destroys the ORB."
1388 */
1389 public void destroy()
1390 {
1391 boolean shutdownFirst = false;
1393 synchronized (this) {
1394 shutdownFirst = (status == STATUS_OPERATING);
1395 }
1397 if (shutdownFirst) {
1398 shutdown(true);
1399 }
1401 synchronized (this) {
1402 if (status < STATUS_DESTROYED) {
1403 getCorbaTransportManager().close();
1404 getPIHandler().destroyInterceptors();
1405 status = STATUS_DESTROYED;
1406 }
1407 }
1408 synchronized (threadPoolManagerAccessLock) {
1409 if (orbOwnsThreadPoolManager) {
1410 try {
1411 threadpoolMgr.close();
1412 threadpoolMgr = null;
1413 } catch (IOException exc) {
1414 wrapper.ioExceptionOnClose(exc);
1415 }
1416 }
1417 }
1419 try {
1420 monitoringManager.close();
1421 monitoringManager = null;
1422 } catch (IOException exc) {
1423 wrapper.ioExceptionOnClose(exc);
1424 }
1426 CachedCodeBase.cleanCache(this);
1427 try {
1428 pihandler.close();
1429 } catch (IOException exc) {
1430 wrapper.ioExceptionOnClose(exc);
1431 }
1433 super.destroy();
1435 badServerIdHandlerAccessLock = null;
1436 clientDelegateFactoryAccessorLock = null;
1437 corbaContactInfoListFactoryAccessLock = null;
1439 objectKeyFactoryAccessLock = null;
1440 legacyServerSocketManagerAccessLock = null;
1441 threadPoolManagerAccessLock = null;
1442 transportManager = null;
1443 legacyServerSocketManager = null;
1444 OAInvocationInfoStack = null;
1445 clientInvocationInfoStack = null;
1446 codeBaseIOR = null;
1447 dynamicRequests = null;
1448 svResponseReceived = null;
1449 runObj = null;
1450 shutdownObj = null;
1451 waitForCompletionObj = null;
1452 invocationObj = null;
1453 isProcessingInvocation = null;
1454 typeCodeForClassMap = null;
1455 valueFactoryCache = null;
1456 orbVersionThreadLocal = null;
1457 requestDispatcherRegistry = null;
1458 copierManager = null;
1459 toaFactory = null;
1460 poaFactory = null;
1461 pihandler = null;
1462 configData = null;
1463 badServerIdHandler = null;
1464 clientDelegateFactory = null;
1465 corbaContactInfoListFactory = null;
1466 resolver = null;
1467 localResolver = null;
1468 insNamingDelegate = null;
1469 urlOperation = null;
1470 taggedComponentFactoryFinder = null;
1471 taggedProfileFactoryFinder = null;
1472 taggedProfileTemplateFactoryFinder = null;
1473 objectKeyFactory = null;
1474 }
1476 /**
1477 * Registers a value factory for a particular repository ID.
1478 *
1479 * @param repositoryID the repository ID.
1480 * @param factory the factory.
1481 * @return the previously registered factory for the given repository ID,
1482 * or null if no such factory was previously registered.
1483 * @exception org.omg.CORBA.BAD_PARAM if the registration fails.
1484 **/
1485 public synchronized ValueFactory register_value_factory(String repositoryID,
1486 ValueFactory factory)
1487 {
1488 checkShutdownState();
1490 if ((repositoryID == null) || (factory == null))
1491 throw omgWrapper.unableRegisterValueFactory() ;
1493 return (ValueFactory)valueFactoryCache.put(repositoryID, factory);
1494 }
1496 /**
1497 * Unregisters a value factory for a particular repository ID.
1498 *
1499 * @param repositoryID the repository ID.
1500 **/
1501 public synchronized void unregister_value_factory(String repositoryID)
1502 {
1503 checkShutdownState();
1505 if (valueFactoryCache.remove(repositoryID) == null)
1506 throw wrapper.nullParam() ;
1507 }
1509 /**
1510 * Finds and returns a value factory for the given repository ID.
1511 * The value factory returned was previously registered by a call to
1512 * {@link #register_value_factory} or is the default factory.
1513 *
1514 * @param repositoryID the repository ID.
1515 * @return the value factory.
1516 * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
1517 **/
1518 public synchronized ValueFactory lookup_value_factory(String repositoryID)
1519 {
1520 checkShutdownState();
1522 ValueFactory factory =
1523 (ValueFactory)valueFactoryCache.get(repositoryID);
1525 if (factory == null) {
1526 try {
1527 factory = Utility.getFactory(null, null, null, repositoryID);
1528 } catch(org.omg.CORBA.MARSHAL ex) {
1529 throw wrapper.unableFindValueFactory( ex ) ;
1530 }
1531 }
1533 return factory ;
1534 }
1536 public OAInvocationInfo peekInvocationInfo()
1537 {
1538 synchronized (this) {
1539 checkShutdownState();
1540 }
1541 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
1542 return (OAInvocationInfo)(stack.peek()) ;
1543 }
1545 public void pushInvocationInfo( OAInvocationInfo info )
1546 {
1547 synchronized (this) {
1548 checkShutdownState();
1549 }
1550 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
1551 stack.push( info ) ;
1552 }
1554 public OAInvocationInfo popInvocationInfo()
1555 {
1556 synchronized (this) {
1557 checkShutdownState();
1558 }
1559 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
1560 return (OAInvocationInfo)(stack.pop()) ;
1561 }
1563 /**
1564 * The bad server id handler is used by the Locator to
1565 * send back the location of a persistant server to the client.
1566 */
1568 private Object badServerIdHandlerAccessLock = new Object();
1570 public void initBadServerIdHandler()
1571 {
1572 synchronized (this) {
1573 checkShutdownState();
1574 }
1575 synchronized (badServerIdHandlerAccessLock) {
1576 Class cls = configData.getBadServerIdHandler() ;
1577 if (cls != null) {
1578 try {
1579 Class[] params = new Class[] { org.omg.CORBA.ORB.class };
1580 java.lang.Object[] args = new java.lang.Object[]{this};
1581 Constructor cons = cls.getConstructor(params);
1582 badServerIdHandler =
1583 (BadServerIdHandler) cons.newInstance(args);
1584 } catch (Exception e) {
1585 throw wrapper.errorInitBadserveridhandler( e ) ;
1586 }
1587 }
1588 }
1589 }
1591 public void setBadServerIdHandler( BadServerIdHandler handler )
1592 {
1593 synchronized (this) {
1594 checkShutdownState();
1595 }
1596 synchronized (badServerIdHandlerAccessLock) {
1597 badServerIdHandler = handler;
1598 }
1599 }
1601 public void handleBadServerId( ObjectKey okey )
1602 {
1603 synchronized (this) {
1604 checkShutdownState();
1605 }
1606 synchronized (badServerIdHandlerAccessLock) {
1607 if (badServerIdHandler == null)
1608 throw wrapper.badServerId() ;
1609 else
1610 badServerIdHandler.handle( okey ) ;
1611 }
1612 }
1614 public synchronized org.omg.CORBA.Policy create_policy( int type,
1615 org.omg.CORBA.Any val ) throws org.omg.CORBA.PolicyError
1616 {
1617 checkShutdownState() ;
1619 return pihandler.create_policy( type, val ) ;
1620 }
1622 /** This is the implementation of the public API used to connect
1623 * a servant-skeleton to the ORB.
1624 */
1625 public synchronized void connect(org.omg.CORBA.Object servant)
1626 {
1627 checkShutdownState();
1628 if (getTOAFactory() == null)
1629 throw wrapper.noToa() ;
1631 try {
1632 String codebase = javax.rmi.CORBA.Util.getCodebase( servant.getClass() ) ;
1633 getTOAFactory().getTOA( codebase ).connect( servant ) ;
1634 } catch ( Exception ex ) {
1635 throw wrapper.orbConnectError( ex ) ;
1636 }
1637 }
1639 public synchronized void disconnect(org.omg.CORBA.Object obj)
1640 {
1641 checkShutdownState();
1642 if (getTOAFactory() == null)
1643 throw wrapper.noToa() ;
1645 try {
1646 getTOAFactory().getTOA().disconnect( obj ) ;
1647 } catch ( Exception ex ) {
1648 throw wrapper.orbConnectError( ex ) ;
1649 }
1650 }
1652 public int getTransientServerId()
1653 {
1654 synchronized (this) {
1655 checkShutdownState();
1656 }
1657 if( configData.getORBServerIdPropertySpecified( ) ) {
1658 // ORBServerId is specified then use that value
1659 return configData.getPersistentServerId( );
1660 }
1661 return transientServerId;
1662 }
1664 public RequestDispatcherRegistry getRequestDispatcherRegistry()
1665 {
1666 synchronized (this) {
1667 checkShutdownState();
1668 }
1669 return requestDispatcherRegistry;
1670 }
1672 public ServiceContextRegistry getServiceContextRegistry()
1673 {
1674 synchronized (this) {
1675 checkShutdownState();
1676 }
1677 return serviceContextRegistry ;
1678 }
1680 // XXX All of the isLocalXXX checking needs to be revisited.
1681 // First of all, all three of these methods are called from
1682 // only one place in impl.ior.IORImpl. Second, we have problems
1683 // both with multi-homed hosts and with multi-profile IORs.
1684 // A possible strategy: like the LocalClientRequestDispatcher, we need
1685 // to determine this more abstractly at the ContactInfo level.
1686 // This level should probably just get the CorbaContactInfoList from
1687 // the IOR, then iterator over ContactInfo. If any ContactInfo is
1688 // local, the IOR is local, and we can pick one to create the
1689 // LocalClientRequestDispatcher as well. Bottom line: this code needs to move.
1691 // XXX What about multi-homed host?
1692 public boolean isLocalHost( String hostName )
1693 {
1694 synchronized (this) {
1695 checkShutdownState();
1696 }
1697 return hostName.equals( configData.getORBServerHost() ) ||
1698 hostName.equals( getLocalHostName() ) ;
1699 }
1701 public boolean isLocalServerId( int subcontractId, int serverId )
1702 {
1703 synchronized (this) {
1704 checkShutdownState();
1705 }
1706 if ((subcontractId < ORBConstants.FIRST_POA_SCID) ||
1707 (subcontractId > ORBConstants.MAX_POA_SCID))
1708 return serverId == getTransientServerId( ) ;
1710 // XXX isTransient info should be stored in subcontract registry
1711 if (ORBConstants.isTransient( subcontractId ))
1712 return (serverId == getTransientServerId()) ;
1713 else if (configData.getPersistentServerIdInitialized())
1714 return (serverId == configData.getPersistentServerId()) ;
1715 else
1716 return false ;
1717 }
1719 /*************************************************************************
1720 * The following public methods are for ORB shutdown.
1721 *************************************************************************/
1723 private String getHostName(String host)
1724 throws java.net.UnknownHostException
1725 {
1726 return InetAddress.getByName( host ).getHostAddress();
1727 }
1729 /* keeping a copy of the getLocalHostName so that it can only be called
1730 * internally and the unauthorized clients cannot have access to the
1731 * localHost information, originally, the above code was calling
1732 * getLocalHostName from Connection.java. If the hostname is cached in
1733 * Connection.java, then
1734 * it is a security hole, since any unauthorized client has access to
1735 * the host information. With this change it is used internally so the
1736 * security problem is resolved. Also in Connection.java, the
1737 * getLocalHost() implementation has changed to always call the
1738 * InetAddress.getLocalHost().getHostAddress()
1739 * The above mentioned method has been removed from the connection class
1740 */
1742 private static String localHostString = null;
1744 private synchronized String getLocalHostName()
1745 {
1746 if (localHostString == null) {
1747 try {
1748 localHostString = InetAddress.getLocalHost().getHostAddress();
1749 } catch (Exception ex) {
1750 throw wrapper.getLocalHostFailed( ex ) ;
1751 }
1752 }
1753 return localHostString ;
1754 }
1756 /******************************************************************************
1757 * The following public methods are for ORB shutdown.
1758 *
1759 ******************************************************************************/
1761 /** This method always returns false because the ORB never needs the
1762 * main thread to do work.
1763 */
1764 public synchronized boolean work_pending()
1765 {
1766 checkShutdownState();
1767 throw wrapper.genericNoImpl() ;
1768 }
1770 /** This method does nothing. It is not required by the spec to do anything!
1771 */
1772 public synchronized void perform_work()
1773 {
1774 checkShutdownState();
1775 throw wrapper.genericNoImpl() ;
1776 }
1778 public synchronized void set_delegate(java.lang.Object servant){
1779 checkShutdownState();
1781 POAFactory poaFactory = getPOAFactory() ;
1782 if (poaFactory != null)
1783 ((org.omg.PortableServer.Servant)servant)
1784 ._set_delegate( poaFactory.getDelegateImpl() ) ;
1785 else
1786 throw wrapper.noPoa() ;
1787 }
1789 ////////////////////////////////////////////////////
1790 //
1791 // pept.broker.Broker
1792 //
1794 public ClientInvocationInfo createOrIncrementInvocationInfo()
1795 {
1796 synchronized (this) {
1797 checkShutdownState();
1798 }
1799 StackImpl invocationInfoStack =
1800 (StackImpl) clientInvocationInfoStack.get();
1801 ClientInvocationInfo clientInvocationInfo = null;
1802 if (!invocationInfoStack.empty()) {
1803 clientInvocationInfo =
1804 (ClientInvocationInfo) invocationInfoStack.peek();
1805 }
1806 if ((clientInvocationInfo == null) ||
1807 (!clientInvocationInfo.isRetryInvocation()))
1808 {
1809 // This is a new call - not a retry.
1810 clientInvocationInfo = new CorbaInvocationInfo(this);
1811 startingDispatch();
1812 invocationInfoStack.push(clientInvocationInfo);
1813 }
1814 // Reset retry so recursive calls will get a new info object.
1815 clientInvocationInfo.setIsRetryInvocation(false);
1816 clientInvocationInfo.incrementEntryCount();
1817 return clientInvocationInfo;
1818 }
1820 public void releaseOrDecrementInvocationInfo()
1821 {
1822 synchronized (this) {
1823 checkShutdownState();
1824 }
1825 int entryCount = -1;
1826 ClientInvocationInfo clientInvocationInfo = null;
1827 StackImpl invocationInfoStack =
1828 (StackImpl)clientInvocationInfoStack.get();
1829 if (!invocationInfoStack.empty()) {
1830 clientInvocationInfo =
1831 (ClientInvocationInfo)invocationInfoStack.peek();
1832 } else {
1833 throw wrapper.invocationInfoStackEmpty() ;
1834 }
1835 clientInvocationInfo.decrementEntryCount();
1836 entryCount = clientInvocationInfo.getEntryCount();
1837 if (clientInvocationInfo.getEntryCount() == 0) {
1838 // 6763340: don't pop if this is a retry!
1839 if (!clientInvocationInfo.isRetryInvocation()) {
1840 invocationInfoStack.pop();
1841 }
1842 finishedDispatch();
1843 }
1844 }
1846 public ClientInvocationInfo getInvocationInfo()
1847 {
1848 synchronized (this) {
1849 checkShutdownState();
1850 }
1851 StackImpl invocationInfoStack =
1852 (StackImpl) clientInvocationInfoStack.get();
1853 return (ClientInvocationInfo) invocationInfoStack.peek();
1854 }
1856 ////////////////////////////////////////////////////
1857 //
1858 //
1859 //
1861 private Object clientDelegateFactoryAccessorLock = new Object();
1863 public void setClientDelegateFactory( ClientDelegateFactory factory )
1864 {
1865 synchronized (this) {
1866 checkShutdownState();
1867 }
1868 synchronized (clientDelegateFactoryAccessorLock) {
1869 clientDelegateFactory = factory ;
1870 }
1871 }
1873 public ClientDelegateFactory getClientDelegateFactory()
1874 {
1875 synchronized (this) {
1876 checkShutdownState();
1877 }
1878 synchronized (clientDelegateFactoryAccessorLock) {
1879 return clientDelegateFactory ;
1880 }
1881 }
1883 private Object corbaContactInfoListFactoryAccessLock = new Object();
1885 public void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory )
1886 {
1887 synchronized (this) {
1888 checkShutdownState();
1889 }
1890 synchronized (corbaContactInfoListFactoryAccessLock) {
1891 corbaContactInfoListFactory = factory ;
1892 }
1893 }
1895 public synchronized CorbaContactInfoListFactory getCorbaContactInfoListFactory()
1896 {
1897 checkShutdownState();
1898 return corbaContactInfoListFactory ;
1899 }
1901 /** Set the resolver used in this ORB. This resolver will be used for list_initial_services
1902 * and resolve_initial_references.
1903 */
1904 public void setResolver( Resolver resolver )
1905 {
1906 synchronized (this) {
1907 checkShutdownState();
1908 }
1909 synchronized (resolverLock) {
1910 this.resolver = resolver ;
1911 }
1912 }
1914 /** Get the resolver used in this ORB. This resolver will be used for list_initial_services
1915 * and resolve_initial_references.
1916 */
1917 public Resolver getResolver()
1918 {
1919 synchronized (this) {
1920 checkShutdownState();
1921 }
1922 synchronized (resolverLock) {
1923 return resolver ;
1924 }
1925 }
1927 /** Set the LocalResolver used in this ORB. This LocalResolver is used for
1928 * register_initial_reference only.
1929 */
1930 public void setLocalResolver( LocalResolver resolver )
1931 {
1932 synchronized (this) {
1933 checkShutdownState();
1934 }
1935 synchronized (resolverLock) {
1936 this.localResolver = resolver ;
1937 }
1938 }
1940 /** Get the LocalResolver used in this ORB. This LocalResolver is used for
1941 * register_initial_reference only.
1942 */
1943 public LocalResolver getLocalResolver()
1944 {
1945 synchronized (this) {
1946 checkShutdownState();
1947 }
1948 synchronized (resolverLock) {
1949 return localResolver ;
1950 }
1951 }
1953 /** Set the operation used in string_to_object calls. The Operation must expect a
1954 * String and return an org.omg.CORBA.Object.
1955 */
1956 public void setURLOperation( Operation stringToObject )
1957 {
1958 synchronized (this) {
1959 checkShutdownState();
1960 }
1961 synchronized (urlOperationLock) {
1962 urlOperation = stringToObject ;
1963 }
1964 }
1966 /** Get the operation used in string_to_object calls. The Operation must expect a
1967 * String and return an org.omg.CORBA.Object.
1968 */
1969 public Operation getURLOperation()
1970 {
1971 synchronized (this) {
1972 checkShutdownState();
1973 }
1974 synchronized (urlOperationLock) {
1975 return urlOperation ;
1976 }
1977 }
1979 public void setINSDelegate( CorbaServerRequestDispatcher sdel )
1980 {
1981 synchronized (this) {
1982 checkShutdownState();
1983 }
1984 synchronized (resolverLock) {
1985 insNamingDelegate = sdel ;
1986 }
1987 }
1989 public TaggedComponentFactoryFinder getTaggedComponentFactoryFinder()
1990 {
1991 synchronized (this) {
1992 checkShutdownState();
1993 }
1994 return taggedComponentFactoryFinder ;
1995 }
1997 public IdentifiableFactoryFinder getTaggedProfileFactoryFinder()
1998 {
1999 synchronized (this) {
2000 checkShutdownState();
2001 }
2002 return taggedProfileFactoryFinder ;
2003 }
2005 public IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder()
2006 {
2007 synchronized (this) {
2008 checkShutdownState();
2009 }
2010 return taggedProfileTemplateFactoryFinder ;
2011 }
2013 private Object objectKeyFactoryAccessLock = new Object();
2015 public ObjectKeyFactory getObjectKeyFactory()
2016 {
2017 synchronized (this) {
2018 checkShutdownState();
2019 }
2020 synchronized (objectKeyFactoryAccessLock) {
2021 return objectKeyFactory ;
2022 }
2023 }
2025 public void setObjectKeyFactory( ObjectKeyFactory factory )
2026 {
2027 synchronized (this) {
2028 checkShutdownState();
2029 }
2030 synchronized (objectKeyFactoryAccessLock) {
2031 objectKeyFactory = factory ;
2032 }
2033 }
2035 private Object transportManagerAccessorLock = new Object();
2037 public TransportManager getTransportManager()
2038 {
2039 synchronized (transportManagerAccessorLock) {
2040 if (transportManager == null) {
2041 transportManager = new CorbaTransportManagerImpl(this);
2042 }
2043 return transportManager;
2044 }
2045 }
2047 public CorbaTransportManager getCorbaTransportManager()
2048 {
2049 return (CorbaTransportManager) getTransportManager();
2050 }
2052 private Object legacyServerSocketManagerAccessLock = new Object();
2054 public LegacyServerSocketManager getLegacyServerSocketManager()
2055 {
2056 synchronized (this) {
2057 checkShutdownState();
2058 }
2059 synchronized (legacyServerSocketManagerAccessLock) {
2060 if (legacyServerSocketManager == null) {
2061 legacyServerSocketManager = new LegacyServerSocketManagerImpl(this);
2062 }
2063 return legacyServerSocketManager;
2064 }
2065 }
2067 private Object threadPoolManagerAccessLock = new Object();
2069 public void setThreadPoolManager(ThreadPoolManager mgr)
2070 {
2071 synchronized (this) {
2072 checkShutdownState();
2073 }
2074 synchronized (threadPoolManagerAccessLock) {
2075 threadpoolMgr = mgr;
2076 }
2077 }
2079 public ThreadPoolManager getThreadPoolManager()
2080 {
2081 synchronized (this) {
2082 checkShutdownState();
2083 }
2084 synchronized (threadPoolManagerAccessLock) {
2085 if (threadpoolMgr == null) {
2086 threadpoolMgr = new ThreadPoolManagerImpl();
2087 orbOwnsThreadPoolManager = true;
2088 }
2089 return threadpoolMgr;
2090 }
2091 }
2093 public CopierManager getCopierManager()
2094 {
2095 synchronized (this) {
2096 checkShutdownState();
2097 }
2098 return copierManager ;
2099 }
2101 @Override
2102 public void validateIORClass(String iorClassName) {
2103 if (iorTypeCheckRegistry != null) {
2104 if (!iorTypeCheckRegistry.isValidIORType(iorClassName)) {
2105 throw ORBUtilSystemException.get( this,
2106 CORBALogDomains.OA_IOR ).badStringifiedIor();
2107 }
2108 }
2109 }
2111 } // Class ORBImpl
2113 ////////////////////////////////////////////////////////////////////////
2114 /// Helper class for a Synchronization Variable
2115 ////////////////////////////////////////////////////////////////////////
2117 class SynchVariable
2118 {
2119 // Synchronization Variable
2120 public boolean _flag;
2122 // Constructor
2123 SynchVariable()
2124 {
2125 _flag = false;
2126 }
2128 // set Flag to true
2129 public void set()
2130 {
2131 _flag = true;
2132 }
2134 // get value
2135 public boolean value()
2136 {
2137 return _flag;
2138 }
2140 // reset Flag to true
2141 public void reset()
2142 {
2143 _flag = false;
2144 }
2145 }
2147 // End of file.