1. /* @(#)ORBImpl.java 1.67 04/06/21
  2. *
  3. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  4. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  5. */
  6. package com.sun.corba.se.impl.orb ;
  7. import java.applet.Applet;
  8. import java.io.IOException ;
  9. import java.lang.reflect.Constructor;
  10. import java.lang.reflect.Field ;
  11. import java.lang.reflect.Modifier ;
  12. import java.lang.reflect.InvocationTargetException ;
  13. import java.util.ArrayList ;
  14. import java.util.Iterator ;
  15. import java.util.Properties ;
  16. import java.util.Vector ;
  17. import java.util.Hashtable ;
  18. import java.util.Map ;
  19. import java.util.HashMap ;
  20. import java.util.LinkedList ;
  21. import java.util.Collection ;
  22. import java.util.Collections ;
  23. import java.util.StringTokenizer ;
  24. import java.util.Enumeration ;
  25. import java.util.WeakHashMap ;
  26. import java.net.InetAddress ;
  27. import java.security.PrivilegedAction;
  28. import java.security.AccessController ;
  29. import javax.rmi.CORBA.Util;
  30. import javax.rmi.CORBA.ValueHandler;
  31. import org.omg.CORBA.Context;
  32. import org.omg.CORBA.ContextList;
  33. import org.omg.CORBA.Environment;
  34. import org.omg.CORBA.ExceptionList;
  35. import org.omg.CORBA.ORBPackage.InvalidName;
  36. import org.omg.CORBA.NVList;
  37. import org.omg.CORBA.TCKind;
  38. import org.omg.CORBA.NamedValue;
  39. import org.omg.CORBA.Request;
  40. import org.omg.CORBA.SystemException;
  41. import org.omg.CORBA.CompletionStatus;
  42. import org.omg.CORBA.TypeCode;
  43. import org.omg.CORBA.Any;
  44. import org.omg.CORBA.StructMember;
  45. import org.omg.CORBA.UnionMember;
  46. import org.omg.CORBA.ValueMember;
  47. import org.omg.CORBA.BAD_PARAM;
  48. import org.omg.CORBA.MARSHAL;
  49. import org.omg.CORBA.portable.ValueFactory;
  50. import org.omg.CORBA.ORBPackage.InvalidName;
  51. import com.sun.org.omg.SendingContext.CodeBase;
  52. import com.sun.corba.se.pept.broker.Broker;
  53. import com.sun.corba.se.pept.protocol.ClientInvocationInfo ;
  54. import com.sun.corba.se.pept.transport.ContactInfo;
  55. import com.sun.corba.se.pept.transport.ConnectionCache;
  56. import com.sun.corba.se.pept.transport.TransportManager;
  57. import com.sun.corba.se.spi.ior.IOR;
  58. import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
  59. import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder;
  60. import com.sun.corba.se.spi.ior.IORFactories ;
  61. import com.sun.corba.se.spi.ior.ObjectKey ;
  62. import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
  63. import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
  64. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  65. import com.sun.corba.se.spi.oa.OAInvocationInfo;
  66. import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
  67. import com.sun.corba.se.spi.orb.DataCollector;
  68. import com.sun.corba.se.spi.orb.Operation;
  69. import com.sun.corba.se.spi.orb.ORBData;
  70. import com.sun.corba.se.spi.orb.ORBConfigurator;
  71. import com.sun.corba.se.spi.orb.ParserImplBase;
  72. import com.sun.corba.se.spi.orb.PropertyParser;
  73. import com.sun.corba.se.spi.orb.OperationFactory;
  74. import com.sun.corba.se.spi.orb.ORBVersion;
  75. import com.sun.corba.se.spi.orb.ORBVersionFactory;
  76. import com.sun.corba.se.spi.orbutil.closure.ClosureFactory;
  77. import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager;
  78. import com.sun.corba.se.spi.protocol.ClientDelegateFactory;
  79. import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
  80. import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
  81. import com.sun.corba.se.spi.protocol.RequestDispatcherDefault;
  82. import com.sun.corba.se.spi.protocol.PIHandler;
  83. import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
  84. import com.sun.corba.se.spi.protocol.ForwardException;
  85. import com.sun.corba.se.spi.resolver.Resolver;
  86. import com.sun.corba.se.spi.resolver.LocalResolver;
  87. import com.sun.corba.se.spi.orb.StringPair;
  88. import com.sun.corba.se.spi.orb.StringPair;
  89. import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory;
  90. import com.sun.corba.se.spi.transport.CorbaTransportManager;
  91. import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
  92. import com.sun.corba.se.spi.copyobject.CopierManager ;
  93. import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ;
  94. import com.sun.corba.se.spi.presentation.rmi.PresentationManager ;
  95. import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
  96. import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry;
  97. import com.sun.corba.se.impl.corba.TypeCodeFactory;
  98. import com.sun.corba.se.impl.corba.TypeCodeImpl;
  99. import com.sun.corba.se.impl.corba.NVListImpl;
  100. import com.sun.corba.se.impl.corba.ExceptionListImpl;
  101. import com.sun.corba.se.impl.corba.ContextListImpl;
  102. import com.sun.corba.se.impl.corba.NamedValueImpl;
  103. import com.sun.corba.se.impl.corba.EnvironmentImpl;
  104. import com.sun.corba.se.impl.corba.AsynchInvoke;
  105. import com.sun.corba.se.impl.corba.AnyImpl;
  106. import com.sun.corba.se.impl.corba.RequestImpl;
  107. import com.sun.corba.se.impl.dynamicany.DynAnyFactoryImpl;
  108. import com.sun.corba.se.impl.encoding.EncapsOutputStream;
  109. import com.sun.corba.se.impl.interceptors.PIHandlerImpl;
  110. import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl;
  111. import com.sun.corba.se.impl.ior.TaggedComponentFactoryFinderImpl;
  112. import com.sun.corba.se.impl.ior.TaggedProfileFactoryFinderImpl;
  113. import com.sun.corba.se.impl.ior.TaggedProfileTemplateFactoryFinderImpl;
  114. import com.sun.corba.se.impl.oa.toa.TOAFactory;
  115. import com.sun.corba.se.impl.oa.poa.BadServerIdHandler;
  116. import com.sun.corba.se.impl.oa.poa.DelegateImpl;
  117. import com.sun.corba.se.impl.oa.poa.POAFactory;
  118. import com.sun.corba.se.impl.orbutil.ORBClassLoader;
  119. import com.sun.corba.se.impl.orbutil.ORBConstants;
  120. import com.sun.corba.se.impl.orbutil.ORBUtility;
  121. import com.sun.corba.se.impl.orbutil.StackImpl;
  122. import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl;
  123. import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolManagerImpl;
  124. import com.sun.corba.se.impl.protocol.RequestDispatcherRegistryImpl;
  125. import com.sun.corba.se.impl.protocol.CorbaInvocationInfo;
  126. import com.sun.corba.se.impl.transport.CorbaTransportManagerImpl;
  127. import com.sun.corba.se.impl.legacy.connection.LegacyServerSocketManagerImpl;
  128. import com.sun.corba.se.impl.util.Utility;
  129. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  130. import com.sun.corba.se.impl.copyobject.CopierManagerImpl;
  131. import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl;
  132. /**
  133. * The JavaIDL ORB implementation.
  134. */
  135. public class ORBImpl extends com.sun.corba.se.spi.orb.ORB
  136. {
  137. protected TransportManager transportManager;
  138. protected LegacyServerSocketManager legacyServerSocketManager;
  139. private ThreadLocal OAInvocationInfoStack ;
  140. private ThreadLocal clientInvocationInfoStack ;
  141. // pure java orb, caching the servant IOR per ORB
  142. private static IOR codeBaseIOR ;
  143. // Vector holding deferred Requests
  144. private Vector dynamicRequests ;
  145. private SynchVariable svResponseReceived ;
  146. private java.lang.Object runObj = new java.lang.Object();
  147. private java.lang.Object shutdownObj = new java.lang.Object();
  148. private java.lang.Object waitForCompletionObj = new java.lang.Object();
  149. private static final byte STATUS_OPERATING = 1;
  150. private static final byte STATUS_SHUTTING_DOWN = 2;
  151. private static final byte STATUS_SHUTDOWN = 3;
  152. private static final byte STATUS_DESTROYED = 4;
  153. private byte status = STATUS_OPERATING;
  154. // XXX Should we move invocation tracking to the first level server dispatcher?
  155. private java.lang.Object invocationObj = new java.lang.Object();
  156. private int numInvocations = 0;
  157. // thread local variable to store a boolean to detect deadlock in
  158. // ORB.shutdown(true).
  159. private ThreadLocal isProcessingInvocation = new ThreadLocal () {
  160. protected java.lang.Object initialValue() {
  161. return Boolean.FALSE;
  162. }
  163. };
  164. // This map is caching TypeCodes created for a certain class (key)
  165. // and is used in Util.writeAny()
  166. private Map typeCodeForClassMap ;
  167. // Cache to hold ValueFactories (Helper classes) keyed on repository ids
  168. private Hashtable valueFactoryCache = new Hashtable();
  169. // thread local variable to store the current ORB version.
  170. // default ORB version is the version of ORB with correct Rep-id
  171. // changes
  172. private ThreadLocal orbVersionThreadLocal ;
  173. private RequestDispatcherRegistry requestDispatcherRegistry ;
  174. private CopierManager copierManager ;
  175. private int transientServerId ;
  176. private ThreadGroup threadGroup ;
  177. private ServiceContextRegistry serviceContextRegistry ;
  178. // Needed here to implement connect/disconnect
  179. private TOAFactory toaFactory ;
  180. // Needed here for set_delegate
  181. private POAFactory poaFactory ;
  182. // The interceptor handler, which provides portable interceptor services for
  183. // subcontracts and object adapters.
  184. private PIHandler pihandler ;
  185. private ORBData configData ;
  186. private BadServerIdHandler badServerIdHandler ;
  187. private ClientDelegateFactory clientDelegateFactory ;
  188. private CorbaContactInfoListFactory corbaContactInfoListFactory ;
  189. // All access to resolver, localResolver, and urlOperation must be protected using
  190. // resolverLock. Do not hold the ORBImpl lock while accessing
  191. // resolver, or deadlocks may occur.
  192. private Object resolverLock ;
  193. // Used for resolver_initial_references and list_initial_services
  194. private Resolver resolver ;
  195. // Used for register_initial_references
  196. private LocalResolver localResolver ;
  197. // Converts strings to object references for resolvers and string_to_object
  198. private Operation urlOperation ;
  199. private CorbaServerRequestDispatcher insNamingDelegate ;
  200. private TaggedComponentFactoryFinder taggedComponentFactoryFinder ;
  201. private IdentifiableFactoryFinder taggedProfileFactoryFinder ;
  202. private IdentifiableFactoryFinder taggedProfileTemplateFactoryFinder ;
  203. private ObjectKeyFactory objectKeyFactory ;
  204. private ThreadPoolManager threadpoolMgr;
  205. private void dprint( String msg )
  206. {
  207. ORBUtility.dprint( this, msg ) ;
  208. }
  209. ////////////////////////////////////////////////////
  210. //
  211. // NOTE:
  212. //
  213. // Methods that are synchronized MUST stay synchronized.
  214. //
  215. // Methods that are NOT synchronized must stay that way to avoid deadlock.
  216. //
  217. //
  218. // REVISIT:
  219. //
  220. // checkShutDownState - lock on different object - and normalize usage.
  221. // starting/FinishDispatch and Shutdown
  222. //
  223. public ORBData getORBData()
  224. {
  225. return configData ;
  226. }
  227. public PIHandler getPIHandler()
  228. {
  229. return pihandler ;
  230. }
  231. /**
  232. * Create a new ORB. Should be followed by the appropriate
  233. * set_parameters() call.
  234. */
  235. public ORBImpl()
  236. {
  237. // All initialization is done through set_parameters().
  238. }
  239. public ORBVersion getORBVersion()
  240. {
  241. return (ORBVersion)(orbVersionThreadLocal.get()) ;
  242. }
  243. public void setORBVersion(ORBVersion verObj)
  244. {
  245. orbVersionThreadLocal.set(verObj);
  246. }
  247. /****************************************************************************
  248. * The following methods are ORB initialization
  249. ****************************************************************************/
  250. // preInit initializes all non-pluggable ORB data that is independent
  251. // of the property parsing.
  252. private void preInit( String[] params, Properties props )
  253. {
  254. // Before ORBConfiguration we need to set a PINoOpHandlerImpl,
  255. // because PersisentServer Initialization inside configurator will
  256. // invoke orb.resolve_initial_references( ) which will result in a
  257. // check on piHandler to invoke Interceptors. We do not want any
  258. // Interceptors to be invoked before the complete ORB initialization.
  259. // piHandler will be replaced by a real PIHandler implementation at the
  260. // end of this method.
  261. pihandler = new PINoOpHandlerImpl( );
  262. // See bugs 4916766 and 4936203
  263. // We intend to create new threads in a reliable thread group.
  264. // This avoids problems if the application/applet
  265. // creates a thread group, makes JavaIDL calls which create a new
  266. // connection and ReaderThread, and then destroys the thread
  267. // group. If our ReaderThreads were to be part of such destroyed thread
  268. // group then it might get killed and cause other invoking threads
  269. // sharing the same connection to get a non-restartable
  270. // CommunicationFailure. We'd like to avoid that.
  271. //
  272. // Our solution is to create all of our threads in the highest thread
  273. // group that we have access to, given our own security clearance.
  274. //
  275. try {
  276. // try to get a thread group that's as high in the threadgroup
  277. // parent-child hierarchy, as we can get to.
  278. // this will prevent an ORB thread created during applet-init from
  279. // being killed when an applet dies.
  280. threadGroup = (ThreadGroup) AccessController.doPrivileged(
  281. new PrivilegedAction() {
  282. public Object run() {
  283. ThreadGroup tg = Thread.currentThread().getThreadGroup() ;
  284. ThreadGroup ptg = tg ;
  285. try {
  286. while (ptg != null) {
  287. tg = ptg;
  288. ptg = tg.getParent();
  289. }
  290. } catch (SecurityException se) {
  291. // Discontinue going higher on a security exception.
  292. }
  293. return new ThreadGroup(tg, "ORB ThreadGroup");
  294. }
  295. }
  296. );
  297. } catch (SecurityException e) {
  298. // something wrong, we go back to the original code
  299. threadGroup = Thread.currentThread().getThreadGroup();
  300. }
  301. // This is the unique id of this server (JVM). Multiple incarnations
  302. // of this server will get different ids.
  303. // Compute transientServerId = milliseconds since Jan 1, 1970
  304. // Note: transientServerId will wrap in about 2^32 / 86400000 = 49.7 days.
  305. // If two ORBS are started at the same time then there is a possibility
  306. // of having the same transientServerId. This may result in collision
  307. // and may be a problem in ior.isLocal() check to see if the object
  308. // belongs to the current ORB. This problem is taken care of by checking
  309. // to see if the IOR port matches ORB server port in legacyIsLocalServerPort()
  310. // method.
  311. //
  312. // XXX need to move server ID to a string for CORBA 3.0. At that point,
  313. // make this more unique (possibly use java.rmi.server.UID).
  314. transientServerId = (int)System.currentTimeMillis();
  315. orbVersionThreadLocal = new ThreadLocal () {
  316. protected java.lang.Object initialValue() {
  317. // set default to version of the ORB with correct Rep-ids
  318. return ORBVersionFactory.getORBVersion() ;
  319. }
  320. };
  321. resolverLock = new java.lang.Object() ;
  322. requestDispatcherRegistry = new RequestDispatcherRegistryImpl(
  323. this, ORBConstants.DEFAULT_SCID);
  324. copierManager = new CopierManagerImpl( this ) ;
  325. taggedComponentFactoryFinder =
  326. new TaggedComponentFactoryFinderImpl(this) ;
  327. taggedProfileFactoryFinder =
  328. new TaggedProfileFactoryFinderImpl(this) ;
  329. taggedProfileTemplateFactoryFinder =
  330. new TaggedProfileTemplateFactoryFinderImpl(this) ;
  331. dynamicRequests = new Vector();
  332. svResponseReceived = new SynchVariable();
  333. OAInvocationInfoStack =
  334. new ThreadLocal () {
  335. protected java.lang.Object initialValue()
  336. {
  337. return new StackImpl();
  338. }
  339. };
  340. clientInvocationInfoStack =
  341. new ThreadLocal() {
  342. protected java.lang.Object initialValue() {
  343. return new StackImpl();
  344. }
  345. };
  346. serviceContextRegistry = new ServiceContextRegistry( this ) ;
  347. }
  348. protected void setDebugFlags( String[] args )
  349. {
  350. for (int ctr=0; ctr<args.length; ctr++ ) {
  351. String token = args[ctr] ;
  352. // If there is a public boolean data member in this class
  353. // named token + "DebugFlag", set it to true.
  354. try {
  355. Field fld = this.getClass().getField( token + "DebugFlag" ) ;
  356. int mod = fld.getModifiers() ;
  357. if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
  358. if (fld.getType() == boolean.class)
  359. fld.setBoolean( this, true ) ;
  360. } catch (Exception exc) {
  361. // ignore it XXX log this as info
  362. }
  363. }
  364. }
  365. // Class that defines a parser that gets the name of the
  366. // ORBConfigurator class.
  367. private static class ConfigParser extends ParserImplBase {
  368. // The default here is the ORBConfiguratorImpl that we define,
  369. // but this can be replaced.
  370. public Class configurator = ORBConfiguratorImpl.class ;
  371. public PropertyParser makeParser()
  372. {
  373. PropertyParser parser = new PropertyParser() ;
  374. parser.add( ORBConstants.SUN_PREFIX + "ORBConfigurator",
  375. OperationFactory.classAction(), "configurator" ) ;
  376. return parser ;
  377. }
  378. }
  379. private void postInit( String[] params, DataCollector dataCollector )
  380. {
  381. // First, create the standard ORB config data.
  382. // This must be initialized before the ORBConfigurator
  383. // is executed.
  384. configData = new ORBDataParserImpl( this, dataCollector) ;
  385. // Set the debug flags early so they can be used by other
  386. // parts of the initialization.
  387. setDebugFlags( configData.getORBDebugFlags() ) ;
  388. // REVISIT: this should go away after more transport init cleanup
  389. // and going to ORT based ORBD.
  390. getTransportManager();
  391. getLegacyServerSocketManager();
  392. // Create a parser to get the configured ORBConfigurator.
  393. ConfigParser parser = new ConfigParser() ;
  394. parser.init( dataCollector ) ;
  395. ORBConfigurator configurator = null ;
  396. try {
  397. configurator =
  398. (ORBConfigurator)(parser.configurator.newInstance()) ;
  399. } catch (Exception iexc) {
  400. throw wrapper.badOrbConfigurator( iexc, parser.configurator.getName() ) ;
  401. }
  402. // Finally, run the configurator. Note that the default implementation allows
  403. // other configurators with their own parsers to run,
  404. // using the same DataCollector.
  405. try {
  406. configurator.configure( dataCollector, this ) ;
  407. } catch (Exception exc) {
  408. throw wrapper.orbConfiguratorError( exc ) ;
  409. }
  410. // Last of all, create the PIHandler and run the ORB initializers.
  411. pihandler = new PIHandlerImpl( this, params) ;
  412. pihandler.initialize() ;
  413. // Initialize the thread manager pool and byte buffer pool
  414. // so they may be initialized & accessed without synchronization
  415. getThreadPoolManager();
  416. super.getByteBufferPool();
  417. }
  418. private synchronized POAFactory getPOAFactory()
  419. {
  420. if (poaFactory == null) {
  421. poaFactory = (POAFactory)requestDispatcherRegistry.getObjectAdapterFactory(
  422. ORBConstants.TRANSIENT_SCID ) ;
  423. }
  424. return poaFactory ;
  425. }
  426. private synchronized TOAFactory getTOAFactory()
  427. {
  428. if (toaFactory == null) {
  429. toaFactory = (TOAFactory)requestDispatcherRegistry.getObjectAdapterFactory(
  430. ORBConstants.TOA_SCID ) ;
  431. }
  432. return toaFactory ;
  433. }
  434. public void set_parameters( Properties props )
  435. {
  436. preInit( null, props ) ;
  437. DataCollector dataCollector =
  438. DataCollectorFactory.create( props, getLocalHostName() ) ;
  439. postInit( null, dataCollector ) ;
  440. }
  441. protected void set_parameters(Applet app, Properties props)
  442. {
  443. preInit( null, props ) ;
  444. DataCollector dataCollector =
  445. DataCollectorFactory.create( app, props, getLocalHostName() ) ;
  446. postInit( null, dataCollector ) ;
  447. }
  448. protected void set_parameters (String[] params, Properties props)
  449. {
  450. preInit( params, props ) ;
  451. DataCollector dataCollector =
  452. DataCollectorFactory.create( params, props, getLocalHostName() ) ;
  453. postInit( params, dataCollector ) ;
  454. }
  455. /****************************************************************************
  456. * The following methods are standard public CORBA ORB APIs
  457. ****************************************************************************/
  458. public synchronized org.omg.CORBA.portable.OutputStream create_output_stream()
  459. {
  460. checkShutdownState();
  461. return new EncapsOutputStream(this);
  462. }
  463. /**
  464. * Get a Current pseudo-object.
  465. * The Current interface is used to manage thread-specific
  466. * information for use by the transactions, security and other
  467. * services. This method is deprecated,
  468. * and replaced by ORB.resolve_initial_references("NameOfCurrentObject");
  469. *
  470. * @return a Current pseudo-object.
  471. * @deprecated
  472. */
  473. public synchronized org.omg.CORBA.Current get_current()
  474. {
  475. checkShutdownState();
  476. /* _REVISIT_
  477. The implementation of get_current is not clear. How would
  478. ORB know whether the caller wants a Current for transactions
  479. or security ?? Or is it assumed that there is just one
  480. implementation for both ? If Current is thread-specific,
  481. then it should not be instantiated; so where does the
  482. ORB get a Current ?
  483. This should probably be deprecated. */
  484. throw wrapper.genericNoImpl() ;
  485. }
  486. /**
  487. * Create an NVList
  488. *
  489. * @param count size of list to create
  490. * @result NVList created
  491. *
  492. * @see NVList
  493. */
  494. public synchronized NVList create_list(int count)
  495. {
  496. checkShutdownState();
  497. return new NVListImpl(this, count);
  498. }
  499. /**
  500. * Create an NVList corresponding to an OperationDef
  501. *
  502. * @param oper operation def to use to create list
  503. * @result NVList created
  504. *
  505. * @see NVList
  506. */
  507. public synchronized NVList create_operation_list(org.omg.CORBA.Object oper)
  508. {
  509. checkShutdownState();
  510. throw wrapper.genericNoImpl() ;
  511. }
  512. /**
  513. * Create a NamedValue
  514. *
  515. * @result NamedValue created
  516. */
  517. public synchronized NamedValue create_named_value(String s, Any any, int flags)
  518. {
  519. checkShutdownState();
  520. return new NamedValueImpl(this, s, any, flags);
  521. }
  522. /**
  523. * Create an ExceptionList
  524. *
  525. * @result ExceptionList created
  526. */
  527. public synchronized org.omg.CORBA.ExceptionList create_exception_list()
  528. {
  529. checkShutdownState();
  530. return new ExceptionListImpl();
  531. }
  532. /**
  533. * Create a ContextList
  534. *
  535. * @result ContextList created
  536. */
  537. public synchronized org.omg.CORBA.ContextList create_context_list()
  538. {
  539. checkShutdownState();
  540. return new ContextListImpl(this);
  541. }
  542. /**
  543. * Get the default Context object
  544. *
  545. * @result the default Context object
  546. */
  547. public synchronized org.omg.CORBA.Context get_default_context()
  548. {
  549. checkShutdownState();
  550. throw wrapper.genericNoImpl() ;
  551. }
  552. /**
  553. * Create an Environment
  554. *
  555. * @result Environment created
  556. */
  557. public synchronized org.omg.CORBA.Environment create_environment()
  558. {
  559. checkShutdownState();
  560. return new EnvironmentImpl();
  561. }
  562. public synchronized void send_multiple_requests_oneway(Request[] req)
  563. {
  564. checkShutdownState();
  565. // Invoke the send_oneway on each new Request
  566. for (int i = 0; i < req.length; i++) {
  567. req[i].send_oneway();
  568. }
  569. }
  570. /**
  571. * Send multiple dynamic requests asynchronously.
  572. *
  573. * @param req an array of request objects.
  574. */
  575. public synchronized void send_multiple_requests_deferred(Request[] req)
  576. {
  577. checkShutdownState();
  578. // add the new Requests to pending dynamic Requests
  579. for (int i = 0; i < req.length; i++) {
  580. dynamicRequests.addElement(req[i]);
  581. }
  582. // Invoke the send_deferred on each new Request
  583. for (int i = 0; i < req.length; i++) {
  584. AsynchInvoke invokeObject = new AsynchInvoke( this,
  585. (com.sun.corba.se.impl.corba.RequestImpl)req[i], true);
  586. new Thread(invokeObject).start();
  587. }
  588. }
  589. /**
  590. * Find out if any of the deferred invocations have a response yet.
  591. */
  592. public synchronized boolean poll_next_response()
  593. {
  594. checkShutdownState();
  595. Request currRequest;
  596. // poll on each pending request
  597. Enumeration ve = dynamicRequests.elements();
  598. while (ve.hasMoreElements() == true) {
  599. currRequest = (Request)ve.nextElement();
  600. if (currRequest.poll_response() == true) {
  601. return true;
  602. }
  603. }
  604. return false;
  605. }
  606. /**
  607. * Get the next request that has gotten a response.
  608. *
  609. * @result the next request ready with a response.
  610. */
  611. public org.omg.CORBA.Request get_next_response()
  612. throws org.omg.CORBA.WrongTransaction
  613. {
  614. synchronized( this ) {
  615. checkShutdownState();
  616. }
  617. while (true) {
  618. // check if there already is a response
  619. synchronized ( dynamicRequests ) {
  620. Enumeration elems = dynamicRequests.elements();
  621. while ( elems.hasMoreElements() ) {
  622. Request currRequest = (Request)elems.nextElement();
  623. if ( currRequest.poll_response() ) {
  624. // get the response for this successfully polled Request
  625. currRequest.get_response();
  626. dynamicRequests.removeElement(currRequest);
  627. return currRequest;
  628. }
  629. }
  630. }
  631. // wait for a response
  632. synchronized(this.svResponseReceived) {
  633. while (!this.svResponseReceived.value()) {
  634. try {
  635. this.svResponseReceived.wait();
  636. } catch(java.lang.InterruptedException ex) {
  637. // NO-OP
  638. }
  639. }
  640. // reinitialize the response flag
  641. this.svResponseReceived.reset();
  642. }
  643. }
  644. }
  645. /**
  646. * Notify response to ORB for get_next_response
  647. */
  648. public void notifyORB()
  649. {
  650. synchronized (this.svResponseReceived) {
  651. this.svResponseReceived.set();
  652. this.svResponseReceived.notify();
  653. }
  654. }
  655. /**
  656. * Convert an object ref to a string.
  657. * @param obj The object to stringify.
  658. * @return A stringified object reference.
  659. */
  660. public synchronized String object_to_string(org.omg.CORBA.Object obj)
  661. {
  662. checkShutdownState();
  663. // Handle the null objref case
  664. if (obj == null) {
  665. IOR nullIOR = IORFactories.makeIOR( this ) ;
  666. return nullIOR.stringify();
  667. }
  668. IOR ior = null ;
  669. try {
  670. ior = ORBUtility.connectAndGetIOR( this, obj ) ;
  671. } catch (BAD_PARAM bp) {
  672. // Throw MARSHAL instead if this is a LOCAL_OBJECT_NOT_ALLOWED error.
  673. if (bp.minor == ORBUtilSystemException.LOCAL_OBJECT_NOT_ALLOWED) {
  674. throw omgWrapper.notAnObjectImpl( bp ) ;
  675. } else
  676. // Not a local object problem: just rethrow the exception.
  677. // Do not wrap and log this, since it was already logged at its
  678. // point of origin.
  679. throw bp ;
  680. }
  681. return ior.stringify() ;
  682. }
  683. /**
  684. * Convert a stringified object reference to the object it represents.
  685. * @param str The stringified object reference.
  686. * @return The unstringified object reference.
  687. */
  688. public org.omg.CORBA.Object string_to_object(String str)
  689. {
  690. Operation op ;
  691. synchronized (this) {
  692. checkShutdownState();
  693. op = urlOperation ;
  694. }
  695. if (str == null)
  696. throw wrapper.nullParam() ;
  697. synchronized (resolverLock) {
  698. org.omg.CORBA.Object obj = (org.omg.CORBA.Object)op.operate( str ) ;
  699. return obj ;
  700. }
  701. }
  702. // pure java orb support, moved this method from FVDCodeBaseImpl.
  703. // Note that we connect this if we have not already done so.
  704. public synchronized IOR getFVDCodeBaseIOR()
  705. {
  706. if (codeBaseIOR != null) // i.e. We are already connected to it
  707. return codeBaseIOR;
  708. // backward compatability 4365188
  709. CodeBase cb;
  710. ValueHandler vh = ORBUtility.createValueHandler(this);
  711. cb = (CodeBase)vh.getRunTimeCodeBase();
  712. return ORBUtility.connectAndGetIOR( this, cb ) ;
  713. }
  714. /**
  715. * Get the TypeCode for a primitive type.
  716. *
  717. * @param tcKind the integer kind for the primitive type
  718. * @return the requested TypeCode
  719. */
  720. public synchronized TypeCode get_primitive_tc(TCKind tcKind)
  721. {
  722. checkShutdownState();
  723. return get_primitive_tc( tcKind.value() ) ;
  724. }
  725. /**
  726. * Create a TypeCode for a structure.
  727. *
  728. * @param id the logical id for the typecode.
  729. * @param name the name for the typecode.
  730. * @param members an array describing the members of the TypeCode.
  731. * @return the requested TypeCode.
  732. */
  733. public synchronized TypeCode create_struct_tc(String id,
  734. String name,
  735. StructMember[] members)
  736. {
  737. checkShutdownState();
  738. return new TypeCodeImpl(this, TCKind._tk_struct, id, name, members);
  739. }
  740. /**
  741. * Create a TypeCode for a union.
  742. *
  743. * @param id the logical id for the typecode.
  744. * @param name the name for the typecode.
  745. * @param discriminator_type
  746. * the type of the union discriminator.
  747. * @param members an array describing the members of the TypeCode.
  748. * @return the requested TypeCode.
  749. */
  750. public synchronized TypeCode create_union_tc(String id,
  751. String name,
  752. TypeCode discriminator_type,
  753. UnionMember[] members)
  754. {
  755. checkShutdownState();
  756. return new TypeCodeImpl(this,
  757. TCKind._tk_union,
  758. id,
  759. name,
  760. discriminator_type,
  761. members);
  762. }
  763. /**
  764. * Create a TypeCode for an enum.
  765. *
  766. * @param id the logical id for the typecode.
  767. * @param name the name for the typecode.
  768. * @param members an array describing the members of the TypeCode.
  769. * @return the requested TypeCode.
  770. */
  771. public synchronized TypeCode create_enum_tc(String id,
  772. String name,
  773. String[] members)
  774. {
  775. checkShutdownState();
  776. return new TypeCodeImpl(this, TCKind._tk_enum, id, name, members);
  777. }
  778. /**
  779. * Create a TypeCode for an alias.
  780. *
  781. * @param id the logical id for the typecode.
  782. * @param name the name for the typecode.
  783. * @param original_type
  784. * the type this is an alias for.
  785. * @return the requested TypeCode.
  786. */
  787. public synchronized TypeCode create_alias_tc(String id,
  788. String name,
  789. TypeCode original_type)
  790. {
  791. checkShutdownState();
  792. return new TypeCodeImpl(this, TCKind._tk_alias, id, name, original_type);
  793. }
  794. /**
  795. * Create a TypeCode for an exception.
  796. *
  797. * @param id the logical id for the typecode.
  798. * @param name the name for the typecode.
  799. * @param members an array describing the members of the TypeCode.
  800. * @return the requested TypeCode.
  801. */
  802. public synchronized TypeCode create_exception_tc(String id,
  803. String name,
  804. StructMember[] members)
  805. {
  806. checkShutdownState();
  807. return new TypeCodeImpl(this, TCKind._tk_except, id, name, members);
  808. }
  809. /**
  810. * Create a TypeCode for an interface.
  811. *
  812. * @param id the logical id for the typecode.
  813. * @param name the name for the typecode.
  814. * @return the requested TypeCode.
  815. */
  816. public synchronized TypeCode create_interface_tc(String id,
  817. String name)
  818. {
  819. checkShutdownState();
  820. return new TypeCodeImpl(this, TCKind._tk_objref, id, name);
  821. }
  822. /**
  823. * Create a TypeCode for a string.
  824. *
  825. * @param bound the bound for the string.
  826. * @return the requested TypeCode.
  827. */
  828. public synchronized TypeCode create_string_tc(int bound)
  829. {
  830. checkShutdownState();
  831. return new TypeCodeImpl(this, TCKind._tk_string, bound);
  832. }
  833. /**
  834. * Create a TypeCode for a wide string.
  835. *
  836. * @param bound the bound for the string.
  837. * @return the requested TypeCode.
  838. */
  839. public synchronized TypeCode create_wstring_tc(int bound)
  840. {
  841. checkShutdownState();
  842. return new TypeCodeImpl(this, TCKind._tk_wstring, bound);
  843. }
  844. /**
  845. * Create a TypeCode for a sequence.
  846. *
  847. * @param bound the bound for the sequence.
  848. * @param element_type
  849. * the type of elements of the sequence.
  850. * @return the requested TypeCode.
  851. */
  852. public synchronized TypeCode create_sequence_tc(int bound,
  853. TypeCode element_type)
  854. {
  855. checkShutdownState();
  856. return new TypeCodeImpl(this, TCKind._tk_sequence, bound, element_type);
  857. }
  858. /**
  859. * Create a recursive TypeCode in a sequence.
  860. *
  861. * @param bound the bound for the sequence.
  862. * @param offset the index to the enclosing TypeCode that is
  863. * being referenced.
  864. * @return the requested TypeCode.
  865. */
  866. public synchronized TypeCode create_recursive_sequence_tc(int bound,
  867. int offset)
  868. {
  869. checkShutdownState();
  870. return new TypeCodeImpl(this, TCKind._tk_sequence, bound, offset);
  871. }
  872. /**
  873. * Create a TypeCode for an array.
  874. *
  875. * @param length the length of the array.
  876. * @param element_type
  877. * the type of elements of the array.
  878. * @return the requested TypeCode.
  879. */
  880. public synchronized TypeCode create_array_tc(int length,
  881. TypeCode element_type)
  882. {
  883. checkShutdownState();
  884. return new TypeCodeImpl(this, TCKind._tk_array, length, element_type);
  885. }
  886. public synchronized org.omg.CORBA.TypeCode create_native_tc(String id,
  887. String name)
  888. {
  889. checkShutdownState();
  890. return new TypeCodeImpl(this, TCKind._tk_native, id, name);
  891. }
  892. public synchronized org.omg.CORBA.TypeCode create_abstract_interface_tc(
  893. String id,
  894. String name)
  895. {
  896. checkShutdownState();
  897. return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name);
  898. }
  899. public synchronized org.omg.CORBA.TypeCode create_fixed_tc(short digits, short scale)
  900. {
  901. checkShutdownState();
  902. return new TypeCodeImpl(this, TCKind._tk_fixed, digits, scale);
  903. }
  904. public synchronized org.omg.CORBA.TypeCode create_value_tc(String id,
  905. String name,
  906. short type_modifier,
  907. TypeCode concrete_base,
  908. ValueMember[] members)
  909. {
  910. checkShutdownState();
  911. return new TypeCodeImpl(this, TCKind._tk_value, id, name,
  912. type_modifier, concrete_base, members);
  913. }
  914. public synchronized org.omg.CORBA.TypeCode create_recursive_tc(String id) {
  915. checkShutdownState();
  916. return new TypeCodeImpl(this, id);
  917. }
  918. public synchronized org.omg.CORBA.TypeCode create_value_box_tc(String id,
  919. String name,
  920. TypeCode boxed_type)
  921. {
  922. checkShutdownState();
  923. return new TypeCodeImpl(this, TCKind._tk_value_box, id, name,
  924. boxed_type);
  925. }
  926. /**
  927. * Create a new Any
  928. *
  929. * @return the new Any created.
  930. */
  931. public synchronized Any create_any()
  932. {
  933. checkShutdownState();
  934. return new AnyImpl(this);
  935. }
  936. // TypeCodeFactory interface methods.
  937. // Keeping track of type codes by repository id.
  938. // Keeping a cache of TypeCodes associated with the class
  939. // they got created from in Util.writeAny().
  940. public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci)
  941. {
  942. if (typeCodeForClassMap == null)
  943. typeCodeForClassMap = Collections.synchronizedMap(
  944. new WeakHashMap(64));
  945. // Store only one TypeCode per class.
  946. if ( ! typeCodeForClassMap.containsKey(c))
  947. typeCodeForClassMap.put(c, tci);
  948. }
  949. public synchronized TypeCodeImpl getTypeCodeForClass(Class c)
  950. {
  951. if (typeCodeForClassMap == null)
  952. return null;
  953. return (TypeCodeImpl)typeCodeForClassMap.get(c);
  954. }
  955. /****************************************************************************
  956. * The following methods deal with listing and resolving the initial
  957. * (bootstrap) object references such as "NameService".
  958. ****************************************************************************/
  959. /**
  960. * Get a list of the initially available CORBA services.
  961. * This does not work unless an ORBInitialHost is specified during
  962. * initialization (or unless there is an ORB running on the AppletHost)
  963. * since the localhostname
  964. * is inaccessible to applets. If a service properties URL was specified,
  965. * then it is used, otherwise the bootstrapping protocol is used.
  966. * @return A list of the initial services available.
  967. */
  968. public String[] list_initial_services()
  969. {
  970. Resolver res ;
  971. synchronized( this ) {
  972. checkShutdownState();
  973. res = resolver ;
  974. }
  975. synchronized (resolverLock) {
  976. java.util.Set keys = res.list() ;
  977. return (String[])keys.toArray( new String[keys.size()] ) ;
  978. }
  979. }
  980. /**
  981. * Resolve the stringified reference of one of the initially
  982. * available CORBA services.
  983. * @param identifier The stringified object reference of the
  984. * desired service.
  985. * @return An object reference for the desired service.
  986. * @exception InvalidName The supplied identifier is not associated
  987. * with a known service.
  988. * @exception SystemException One of a fixed set of Corba system exceptions.
  989. */
  990. public org.omg.CORBA.Object resolve_initial_references(
  991. String identifier) throws InvalidName
  992. {
  993. Resolver res ;
  994. synchronized( this ) {
  995. checkShutdownState();
  996. res = resolver ;
  997. }
  998. synchronized (resolverLock) {
  999. org.omg.CORBA.Object result = res.resolve( identifier ) ;
  1000. if (result == null)
  1001. throw new InvalidName() ;
  1002. else
  1003. return result ;
  1004. }
  1005. }
  1006. /**
  1007. * If this operation is called with an id, <code>"Y"</code>, and an
  1008. * object, <code>YY</code>, then a subsequent call to
  1009. * <code>ORB.resolve_initial_references( "Y" )</code> will
  1010. * return object <code>YY</code>.
  1011. *
  1012. * @param id The ID by which the initial reference will be known.
  1013. * @param obj The initial reference itself.
  1014. * @throws InvalidName if this operation is called with an empty string id
  1015. * or this operation is called with an id that is already registered,
  1016. * including the default names defined by OMG.
  1017. * @throws BAD_PARAM if the obj parameter is null.
  1018. */
  1019. public void register_initial_reference(
  1020. String id, org.omg.CORBA.Object obj ) throws InvalidName
  1021. {
  1022. CorbaServerRequestDispatcher insnd ;
  1023. if ((id == null) || (id.length() == 0))
  1024. throw new InvalidName() ;
  1025. synchronized (this) {
  1026. checkShutdownState();
  1027. }
  1028. synchronized (resolverLock) {
  1029. insnd = insNamingDelegate ;
  1030. java.lang.Object obj2 = localResolver.resolve( id ) ;
  1031. if (obj2 != null)
  1032. throw new InvalidName(id + " already registered") ;
  1033. localResolver.register( id, ClosureFactory.makeConstant( obj )) ;
  1034. }
  1035. synchronized (this) {
  1036. if (StubAdapter.isStub(obj))
  1037. // Make all remote object references available for INS.
  1038. requestDispatcherRegistry.registerServerRequestDispatcher(
  1039. insnd, id ) ;
  1040. }
  1041. }
  1042. /****************************************************************************
  1043. * The following methods (introduced in POA / CORBA2.1) deal with
  1044. * shutdown / single threading.
  1045. ****************************************************************************/
  1046. public void run()
  1047. {
  1048. synchronized (this) {
  1049. checkShutdownState();
  1050. }
  1051. synchronized (runObj) {
  1052. try {
  1053. runObj.wait();
  1054. } catch ( InterruptedException ex ) {}
  1055. }
  1056. }
  1057. public void shutdown(boolean wait_for_completion)
  1058. {
  1059. synchronized (this) {
  1060. checkShutdownState();
  1061. }
  1062. // Avoid more than one thread performing shutdown at a time.
  1063. synchronized (shutdownObj) {
  1064. checkShutdownState();
  1065. // This is to avoid deadlock
  1066. if (wait_for_completion &&
  1067. isProcessingInvocation.get() == Boolean.TRUE) {
  1068. throw omgWrapper.shutdownWaitForCompletionDeadlock() ;
  1069. }
  1070. status = STATUS_SHUTTING_DOWN;
  1071. // XXX access to requestDispatcherRegistry should be protected
  1072. // by the ORBImpl instance monitor, but is not here in the
  1073. // shutdownServants call.
  1074. shutdownServants(wait_for_completion);
  1075. if (wait_for_completion) {
  1076. synchronized ( waitForCompletionObj ) {
  1077. while (numInvocations > 0) {
  1078. try {
  1079. waitForCompletionObj.wait();
  1080. } catch (InterruptedException ex) {}
  1081. }
  1082. }
  1083. }
  1084. synchronized ( runObj ) {
  1085. runObj.notifyAll();
  1086. }
  1087. status = STATUS_SHUTDOWN;
  1088. }
  1089. }
  1090. /** This method shuts down the ORB and causes orb.run() to return.
  1091. * It will cause all POAManagers to be deactivated, which in turn
  1092. * will cause all POAs to be deactivated.
  1093. */
  1094. protected void shutdownServants(boolean wait_for_completion) {
  1095. Iterator iter = requestDispatcherRegistry.getObjectAdapterFactories().iterator() ;
  1096. while (iter.hasNext()) {
  1097. ObjectAdapterFactory oaf = (ObjectAdapterFactory)iter.next() ;
  1098. oaf.shutdown( wait_for_completion ) ;
  1099. }
  1100. }
  1101. // REVISIT: was protected - made public for framework
  1102. // Note that the caller must hold the ORBImpl lock.
  1103. public void checkShutdownState()
  1104. {
  1105. if (status == STATUS_DESTROYED) {
  1106. throw wrapper.orbDestroyed() ;
  1107. }
  1108. if (status == STATUS_SHUTDOWN) {
  1109. throw omgWrapper.badOperationAfterShutdown() ;
  1110. }
  1111. }
  1112. public boolean isDuringDispatch()
  1113. {
  1114. Boolean value = (Boolean)(isProcessingInvocation.get()) ;
  1115. return value.booleanValue() ;
  1116. }
  1117. public void startingDispatch()
  1118. {
  1119. synchronized (invocationObj) {
  1120. isProcessingInvocation.set(Boolean.TRUE);
  1121. numInvocations++;
  1122. }
  1123. }
  1124. public void finishedDispatch()
  1125. {
  1126. synchronized (invocationObj) {
  1127. numInvocations--;
  1128. isProcessingInvocation.set(Boolean.FALSE);
  1129. if (numInvocations == 0) {
  1130. synchronized (waitForCompletionObj) {
  1131. waitForCompletionObj.notifyAll();
  1132. }
  1133. } else if (numInvocations < 0) {
  1134. throw wrapper.numInvocationsAlreadyZero(
  1135. CompletionStatus.COMPLETED_YES ) ;
  1136. }
  1137. }
  1138. }
  1139. /**
  1140. * formal/99-10-07 p 159: "If destroy is called on an ORB that has
  1141. * not been shut down, it will start the shutdown process and block until
  1142. * the ORB has shut down before it destroys the ORB."
  1143. */
  1144. public synchronized void destroy()
  1145. {
  1146. if (status == STATUS_OPERATING) {
  1147. shutdown(true);
  1148. }
  1149. getCorbaTransportManager().close();
  1150. getPIHandler().destroyInterceptors() ;
  1151. status = STATUS_DESTROYED;
  1152. }
  1153. /**
  1154. * Registers a value factory for a particular repository ID.
  1155. *
  1156. * @param repositoryID the repository ID.
  1157. * @param factory the factory.
  1158. * @return the previously registered factory for the given repository ID,
  1159. * or null if no such factory was previously registered.
  1160. * @exception org.omg.CORBA.BAD_PARAM if the registration fails.
  1161. **/
  1162. public synchronized ValueFactory register_value_factory(String repositoryID,
  1163. ValueFactory factory)
  1164. {
  1165. checkShutdownState();
  1166. if ((repositoryID == null) || (factory == null))
  1167. throw omgWrapper.unableRegisterValueFactory() ;
  1168. return (ValueFactory)valueFactoryCache.put(repositoryID, factory);
  1169. }
  1170. /**
  1171. * Unregisters a value factory for a particular repository ID.
  1172. *
  1173. * @param repositoryID the repository ID.
  1174. **/
  1175. public synchronized void unregister_value_factory(String repositoryID)
  1176. {
  1177. checkShutdownState();
  1178. if (valueFactoryCache.remove(repositoryID) == null)
  1179. throw wrapper.nullParam() ;
  1180. }
  1181. /**
  1182. * Finds and returns a value factory for the given repository ID.
  1183. * The value factory returned was previously registered by a call to
  1184. * {@link #register_value_factory} or is the default factory.
  1185. *
  1186. * @param repositoryID the repository ID.
  1187. * @return the value factory.
  1188. * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
  1189. **/
  1190. public synchronized ValueFactory lookup_value_factory(String repositoryID)
  1191. {
  1192. checkShutdownState();
  1193. ValueFactory factory =
  1194. (ValueFactory)valueFactoryCache.get(repositoryID);
  1195. if (factory == null) {
  1196. try {
  1197. factory = Utility.getFactory(null, null, null, repositoryID);
  1198. } catch(org.omg.CORBA.MARSHAL ex) {
  1199. throw wrapper.unableFindValueFactory( ex ) ;
  1200. }
  1201. }
  1202. return factory ;
  1203. }
  1204. public OAInvocationInfo peekInvocationInfo()
  1205. {
  1206. StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
  1207. return (OAInvocationInfo)(stack.peek()) ;
  1208. }
  1209. public void pushInvocationInfo( OAInvocationInfo info )
  1210. {
  1211. StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
  1212. stack.push( info ) ;
  1213. }
  1214. public OAInvocationInfo popInvocationInfo()
  1215. {
  1216. StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ;
  1217. return (OAInvocationInfo)(stack.pop()) ;
  1218. }
  1219. /**
  1220. * The bad server id handler is used by the Locator to
  1221. * send back the location of a persistant server to the client.
  1222. */
  1223. private Object badServerIdHandlerAccessLock = new Object();
  1224. public void initBadServerIdHandler()
  1225. {
  1226. synchronized (badServerIdHandlerAccessLock) {
  1227. Class cls = configData.getBadServerIdHandler() ;
  1228. if (cls != null) {
  1229. try {
  1230. Class[] params = new Class[] { org.omg.CORBA.ORB.class };
  1231. java.lang.Object[] args = new java.lang.Object[]{this};
  1232. Constructor cons = cls.getConstructor(params);
  1233. badServerIdHandler =
  1234. (BadServerIdHandler) cons.newInstance(args);
  1235. } catch (Exception e) {
  1236. throw wrapper.errorInitBadserveridhandler( e ) ;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. public void setBadServerIdHandler( BadServerIdHandler handler )
  1242. {
  1243. synchronized (badServerIdHandlerAccessLock) {
  1244. badServerIdHandler = handler;
  1245. }
  1246. }
  1247. public void handleBadServerId( ObjectKey okey )
  1248. {
  1249. synchronized (badServerIdHandlerAccessLock) {
  1250. if (badServerIdHandler == null)
  1251. throw wrapper.badServerId() ;
  1252. else
  1253. badServerIdHandler.handle( okey ) ;
  1254. }
  1255. }
  1256. public synchronized org.omg.CORBA.Policy create_policy( int type,
  1257. org.omg.CORBA.Any val ) throws org.omg.CORBA.PolicyError
  1258. {
  1259. checkShutdownState() ;
  1260. return pihandler.create_policy( type, val ) ;
  1261. }
  1262. /** This is the implementation of the public API used to connect
  1263. * a servant-skeleton to the ORB.
  1264. */
  1265. public synchronized void connect(org.omg.CORBA.Object servant)
  1266. {
  1267. checkShutdownState();
  1268. if (getTOAFactory() == null)
  1269. throw wrapper.noToa() ;
  1270. try {
  1271. String codebase = javax.rmi.CORBA.Util.getCodebase( servant.getClass() ) ;
  1272. getTOAFactory().getTOA( codebase ).connect( servant ) ;
  1273. } catch ( Exception ex ) {
  1274. throw wrapper.orbConnectError( ex ) ;
  1275. }
  1276. }
  1277. public synchronized void disconnect(org.omg.CORBA.Object obj)
  1278. {
  1279. checkShutdownState();
  1280. if (getTOAFactory() == null)
  1281. throw wrapper.noToa() ;
  1282. try {
  1283. getTOAFactory().getTOA().disconnect( obj ) ;
  1284. } catch ( Exception ex ) {
  1285. throw wrapper.orbConnectError( ex ) ;
  1286. }
  1287. }
  1288. public int getTransientServerId()
  1289. {
  1290. if( configData.getORBServerIdPropertySpecified( ) ) {
  1291. // ORBServerId is specified then use that value
  1292. return configData.getPersistentServerId( );
  1293. }
  1294. return transientServerId;
  1295. }
  1296. public RequestDispatcherRegistry getRequestDispatcherRegistry()
  1297. {
  1298. return requestDispatcherRegistry;
  1299. }
  1300. public ServiceContextRegistry getServiceContextRegistry()
  1301. {
  1302. return serviceContextRegistry ;
  1303. }
  1304. // XXX All of the isLocalXXX checking needs to be revisited.
  1305. // First of all, all three of these methods are called from
  1306. // only one place in impl.ior.IORImpl. Second, we have problems
  1307. // both with multi-homed hosts and with multi-profile IORs.
  1308. // A possible strategy: like the LocalClientRequestDispatcher, we need
  1309. // to determine this more abstractly at the ContactInfo level.
  1310. // This level should probably just get the CorbaContactInfoList from
  1311. // the IOR, then iterator over ContactInfo. If any ContactInfo is
  1312. // local, the IOR is local, and we can pick one to create the
  1313. // LocalClientRequestDispatcher as well. Bottom line: this code needs to move.
  1314. // XXX What about multi-homed host?
  1315. public boolean isLocalHost( String hostName )
  1316. {
  1317. return hostName.equals( configData.getORBServerHost() ) ||
  1318. hostName.equals( getLocalHostName() ) ;
  1319. }
  1320. public boolean isLocalServerId( int subcontractId, int serverId )
  1321. {
  1322. if ((subcontractId < ORBConstants.FIRST_POA_SCID) ||
  1323. (subcontractId > ORBConstants.MAX_POA_SCID))
  1324. return serverId == getTransientServerId( ) ;
  1325. // XXX isTransient info should be stored in subcontract registry
  1326. if (ORBConstants.isTransient( subcontractId ))
  1327. return (serverId == getTransientServerId()) ;
  1328. else if (configData.getPersistentServerIdInitialized())
  1329. return (serverId == configData.getPersistentServerId()) ;
  1330. else
  1331. return false ;
  1332. }
  1333. /*************************************************************************
  1334. * The following public methods are for ORB shutdown.
  1335. *************************************************************************/
  1336. private String getHostName(String host)
  1337. throws java.net.UnknownHostException
  1338. {
  1339. return InetAddress.getByName( host ).getHostAddress();
  1340. }
  1341. /* keeping a copy of the getLocalHostName so that it can only be called
  1342. * internally and the unauthorized clients cannot have access to the
  1343. * localHost information, originally, the above code was calling
  1344. * getLocalHostName from Connection.java. If the hostname is cached in
  1345. * Connection.java, then
  1346. * it is a security hole, since any unauthorized client has access to
  1347. * the host information. With this change it is used internally so the
  1348. * security problem is resolved. Also in Connection.java, the
  1349. * getLocalHost() implementation has changed to always call the
  1350. * InetAddress.getLocalHost().getHostAddress()
  1351. * The above mentioned method has been removed from the connection class
  1352. */
  1353. private static String localHostString = null;
  1354. private synchronized String getLocalHostName()
  1355. {
  1356. if (localHostString == null) {
  1357. try {
  1358. localHostString = InetAddress.getLocalHost().getHostAddress();
  1359. } catch (Exception ex) {
  1360. throw wrapper.getLocalHostFailed( ex ) ;
  1361. }
  1362. }
  1363. return localHostString ;
  1364. }
  1365. /******************************************************************************
  1366. * The following public methods are for ORB shutdown.
  1367. *
  1368. ******************************************************************************/
  1369. /** This method always returns false because the ORB never needs the
  1370. * main thread to do work.
  1371. */
  1372. public synchronized boolean work_pending()
  1373. {
  1374. checkShutdownState();
  1375. throw wrapper.genericNoImpl() ;
  1376. }
  1377. /** This method does nothing. It is not required by the spec to do anything!
  1378. */
  1379. public synchronized void perform_work()
  1380. {
  1381. checkShutdownState();
  1382. throw wrapper.genericNoImpl() ;
  1383. }
  1384. public synchronized void set_delegate(java.lang.Object servant){
  1385. checkShutdownState();
  1386. POAFactory poaFactory = getPOAFactory() ;
  1387. if (poaFactory != null)
  1388. ((org.omg.PortableServer.Servant)servant)
  1389. ._set_delegate( poaFactory.getDelegateImpl() ) ;
  1390. else
  1391. throw wrapper.noPoa() ;
  1392. }
  1393. ////////////////////////////////////////////////////
  1394. //
  1395. // pept.broker.Broker
  1396. //
  1397. public ClientInvocationInfo createOrIncrementInvocationInfo()
  1398. {
  1399. StackImpl invocationInfoStack =
  1400. (StackImpl) clientInvocationInfoStack.get();
  1401. ClientInvocationInfo clientInvocationInfo = null;
  1402. if (!invocationInfoStack.empty()) {
  1403. clientInvocationInfo =
  1404. (ClientInvocationInfo) invocationInfoStack.peek();
  1405. }
  1406. if ((clientInvocationInfo == null) ||
  1407. (!clientInvocationInfo.isRetryInvocation()))
  1408. {
  1409. // This is a new call - not a retry.
  1410. clientInvocationInfo = new CorbaInvocationInfo(this);
  1411. invocationInfoStack.push(clientInvocationInfo);
  1412. }
  1413. // Reset retry so recursive calls will get a new info object.
  1414. clientInvocationInfo.setIsRetryInvocation(false);
  1415. clientInvocationInfo.incrementEntryCount();
  1416. return clientInvocationInfo;
  1417. }
  1418. public void releaseOrDecrementInvocationInfo()
  1419. {
  1420. StackImpl invocationInfoStack =
  1421. (StackImpl)clientInvocationInfoStack.get();
  1422. ClientInvocationInfo clientInvocationInfo = null;
  1423. if (!invocationInfoStack.empty()) {
  1424. clientInvocationInfo =
  1425. (ClientInvocationInfo)invocationInfoStack.peek();
  1426. } else {
  1427. throw wrapper.invocationInfoStackEmpty() ;
  1428. }
  1429. clientInvocationInfo.decrementEntryCount();
  1430. if (clientInvocationInfo.getEntryCount() == 0) {
  1431. invocationInfoStack.pop();
  1432. }
  1433. }
  1434. public ClientInvocationInfo getInvocationInfo()
  1435. {
  1436. StackImpl invocationInfoStack =
  1437. (StackImpl) clientInvocationInfoStack.get();
  1438. return (ClientInvocationInfo) invocationInfoStack.peek();
  1439. }
  1440. ////////////////////////////////////////////////////
  1441. //
  1442. //
  1443. //
  1444. private Object clientDelegateFactoryAccessorLock = new Object();
  1445. public void setClientDelegateFactory( ClientDelegateFactory factory )
  1446. {
  1447. synchronized (clientDelegateFactoryAccessorLock) {
  1448. clientDelegateFactory = factory ;
  1449. }
  1450. }
  1451. public ClientDelegateFactory getClientDelegateFactory()
  1452. {
  1453. synchronized (clientDelegateFactoryAccessorLock) {
  1454. return clientDelegateFactory ;
  1455. }
  1456. }
  1457. private Object corbaContactInfoListFactoryAccessLock = new Object();
  1458. public void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory )
  1459. {
  1460. synchronized (corbaContactInfoListFactoryAccessLock) {
  1461. corbaContactInfoListFactory = factory ;
  1462. }
  1463. }
  1464. public synchronized CorbaContactInfoListFactory getCorbaContactInfoListFactory()
  1465. {
  1466. return corbaContactInfoListFactory ;
  1467. }
  1468. /** Set the resolver used in this ORB. This resolver will be used for list_initial_services
  1469. * and resolve_initial_references.
  1470. */
  1471. public void setResolver( Resolver resolver )
  1472. {
  1473. synchronized (resolverLock) {
  1474. this.resolver = resolver ;
  1475. }
  1476. }
  1477. /** Get the resolver used in this ORB. This resolver will be used for list_initial_services
  1478. * and resolve_initial_references.
  1479. */
  1480. public Resolver getResolver()
  1481. {
  1482. synchronized (resolverLock) {
  1483. return resolver ;
  1484. }
  1485. }
  1486. /** Set the LocalResolver used in this ORB. This LocalResolver is used for
  1487. * register_initial_reference only.
  1488. */
  1489. public void setLocalResolver( LocalResolver resolver )
  1490. {
  1491. synchronized (resolverLock) {
  1492. this.localResolver = resolver ;
  1493. }
  1494. }
  1495. /** Get the LocalResolver used in this ORB. This LocalResolver is used for
  1496. * register_initial_reference only.
  1497. */
  1498. public LocalResolver getLocalResolver()
  1499. {
  1500. synchronized (resolverLock) {
  1501. return localResolver ;
  1502. }
  1503. }
  1504. /** Set the operation used in string_to_object calls. The Operation must expect a
  1505. * String and return an org.omg.CORBA.Object.
  1506. */
  1507. public void setURLOperation( Operation stringToObject )
  1508. {
  1509. synchronized (resolverLock) {
  1510. urlOperation = stringToObject ;
  1511. }
  1512. }
  1513. /** Get the operation used in string_to_object calls. The Operation must expect a
  1514. * String and return an org.omg.CORBA.Object.
  1515. */
  1516. public Operation getURLOperation()
  1517. {
  1518. synchronized (resolverLock) {
  1519. return urlOperation ;
  1520. }
  1521. }
  1522. public void setINSDelegate( CorbaServerRequestDispatcher sdel )
  1523. {
  1524. synchronized (resolverLock) {
  1525. insNamingDelegate = sdel ;
  1526. }
  1527. }
  1528. public TaggedComponentFactoryFinder getTaggedComponentFactoryFinder()
  1529. {
  1530. return taggedComponentFactoryFinder ;
  1531. }
  1532. public IdentifiableFactoryFinder getTaggedProfileFactoryFinder()
  1533. {
  1534. return taggedProfileFactoryFinder ;
  1535. }
  1536. public IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder()
  1537. {
  1538. return taggedProfileTemplateFactoryFinder ;
  1539. }
  1540. private Object objectKeyFactoryAccessLock = new Object();
  1541. public ObjectKeyFactory getObjectKeyFactory()
  1542. {
  1543. synchronized (objectKeyFactoryAccessLock) {
  1544. return objectKeyFactory ;
  1545. }
  1546. }
  1547. public void setObjectKeyFactory( ObjectKeyFactory factory )
  1548. {
  1549. synchronized (objectKeyFactoryAccessLock) {
  1550. objectKeyFactory = factory ;
  1551. }
  1552. }
  1553. private Object transportManagerAccessorLock = new Object();
  1554. public TransportManager getTransportManager()
  1555. {
  1556. synchronized (transportManagerAccessorLock) {
  1557. if (transportManager == null) {
  1558. transportManager = new CorbaTransportManagerImpl(this);
  1559. }
  1560. return transportManager;
  1561. }
  1562. }
  1563. public CorbaTransportManager getCorbaTransportManager()
  1564. {
  1565. return (CorbaTransportManager) getTransportManager();
  1566. }
  1567. private Object legacyServerSocketManagerAccessLock = new Object();
  1568. public LegacyServerSocketManager getLegacyServerSocketManager()
  1569. {
  1570. synchronized (legacyServerSocketManagerAccessLock) {
  1571. if (legacyServerSocketManager == null) {
  1572. legacyServerSocketManager = new LegacyServerSocketManagerImpl(this);
  1573. }
  1574. return legacyServerSocketManager;
  1575. }
  1576. }
  1577. private Object threadPoolManagerAccessLock = new Object();
  1578. public void setThreadPoolManager(ThreadPoolManager mgr)
  1579. {
  1580. synchronized (threadPoolManagerAccessLock) {
  1581. threadpoolMgr = mgr;
  1582. }
  1583. }
  1584. public ThreadPoolManager getThreadPoolManager()
  1585. {
  1586. synchronized (threadPoolManagerAccessLock) {
  1587. if (threadpoolMgr == null) {
  1588. threadpoolMgr = new ThreadPoolManagerImpl( threadGroup );
  1589. }
  1590. return threadpoolMgr;
  1591. }
  1592. }
  1593. public CopierManager getCopierManager()
  1594. {
  1595. return copierManager ;
  1596. }
  1597. } // Class ORBImpl
  1598. ////////////////////////////////////////////////////////////////////////
  1599. /// Helper class for a Synchronization Variable
  1600. ////////////////////////////////////////////////////////////////////////
  1601. class SynchVariable
  1602. {
  1603. // Synchronization Variable
  1604. public boolean _flag;
  1605. // Constructor
  1606. SynchVariable()
  1607. {
  1608. _flag = false;
  1609. }
  1610. // set Flag to true
  1611. public void set()
  1612. {
  1613. _flag = true;
  1614. }
  1615. // get value
  1616. public boolean value()
  1617. {
  1618. return _flag;
  1619. }
  1620. // reset Flag to true
  1621. public void reset()
  1622. {
  1623. _flag = false;
  1624. }
  1625. }
  1626. // End of file.