1. /*
  2. * @(#)ORB.java 1.53 04/06/21
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.spi.orb;
  8. import java.util.Map ;
  9. import java.util.HashMap ;
  10. import java.util.Properties ;
  11. import java.util.logging.Logger ;
  12. import java.security.AccessController ;
  13. import java.security.PrivilegedAction ;
  14. import org.omg.CORBA.TCKind ;
  15. import com.sun.corba.se.pept.broker.Broker ;
  16. import com.sun.corba.se.pept.transport.ByteBufferPool;
  17. import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
  18. import com.sun.corba.se.spi.protocol.ClientDelegateFactory ;
  19. import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
  20. import com.sun.corba.se.spi.protocol.CorbaMessageMediator ;
  21. import com.sun.corba.se.spi.protocol.PIHandler ;
  22. import com.sun.corba.se.spi.resolver.LocalResolver ;
  23. import com.sun.corba.se.spi.resolver.Resolver ;
  24. import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory ;
  25. import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
  26. import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
  27. import com.sun.corba.se.spi.monitoring.MonitoringConstants;
  28. import com.sun.corba.se.spi.monitoring.MonitoringManager;
  29. import com.sun.corba.se.spi.monitoring.MonitoringManagerFactory;
  30. import com.sun.corba.se.spi.monitoring.MonitoringFactories;
  31. import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
  32. import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder ;
  33. import com.sun.corba.se.spi.ior.ObjectKey ;
  34. import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
  35. import com.sun.corba.se.spi.ior.IOR ;
  36. import com.sun.corba.se.spi.orbutil.closure.Closure ;
  37. import com.sun.corba.se.spi.orb.Operation ;
  38. import com.sun.corba.se.spi.orb.ORBData ;
  39. import com.sun.corba.se.spi.orb.ORBVersion ;
  40. import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager;
  41. import com.sun.corba.se.spi.oa.OAInvocationInfo ;
  42. import com.sun.corba.se.spi.transport.CorbaTransportManager;
  43. import com.sun.corba.se.spi.logging.LogWrapperFactory ;
  44. import com.sun.corba.se.spi.logging.LogWrapperBase ;
  45. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  46. import com.sun.corba.se.spi.copyobject.CopierManager ;
  47. import com.sun.corba.se.spi.presentation.rmi.PresentationManager ;
  48. import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ;
  49. import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry ;
  50. // XXX needs an SPI or else it does not belong here
  51. import com.sun.corba.se.impl.corba.TypeCodeImpl ;
  52. import com.sun.corba.se.impl.corba.TypeCodeFactory ;
  53. // XXX Should there be a SPI level constants ?
  54. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  55. import com.sun.corba.se.impl.oa.poa.BadServerIdHandler ;
  56. import com.sun.corba.se.impl.transport.ByteBufferPoolImpl;
  57. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  58. import com.sun.corba.se.impl.logging.OMGSystemException ;
  59. import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl ;
  60. import com.sun.corba.se.impl.orbutil.ORBClassLoader ;
  61. public abstract class ORB extends com.sun.corba.se.org.omg.CORBA.ORB
  62. implements Broker, TypeCodeFactory
  63. {
  64. // As much as possible, this class should be stateless. However,
  65. // there are a few reasons why it is not:
  66. //
  67. // 1. The ORB debug flags are defined here because they are accessed
  68. // frequently, and we do not want a cast to the impl just for that.
  69. // 2. typeCodeMap and primitiveTypeCodeConstants are here because they
  70. // are needed in both ORBImpl and ORBSingleton.
  71. // 3. Logging support is here so that we can avoid problems with
  72. // incompletely initialized ORBs that need to perform logging.
  73. // Flag set at compile time to debug flag processing: this can't
  74. // be one of the xxxDebugFlags because it is used to debug the mechanism
  75. // that sets the xxxDebugFlags!
  76. public static boolean ORBInitDebug = false;
  77. // Currently defined debug flags. Any additions must be called xxxDebugFlag.
  78. // All debug flags must be public boolean types.
  79. // These are set by passing the flag -ORBDebug x,y,z in the ORB init args.
  80. // Note that x,y,z must not contain spaces.
  81. public boolean transportDebugFlag = false ;
  82. public boolean subcontractDebugFlag = false ;
  83. public boolean poaDebugFlag = false ;
  84. public boolean poaConcurrencyDebugFlag = false ;
  85. public boolean poaFSMDebugFlag = false ;
  86. public boolean orbdDebugFlag = false ;
  87. public boolean namingDebugFlag = false ;
  88. public boolean serviceContextDebugFlag = false ;
  89. public boolean transientObjectManagerDebugFlag = false ;
  90. public boolean giopVersionDebugFlag = false;
  91. public boolean shutdownDebugFlag = false;
  92. public boolean giopDebugFlag = false;
  93. public boolean invocationTimingDebugFlag = false ;
  94. // SystemException log wrappers. Protected so that they can be used in
  95. // subclasses.
  96. protected static ORBUtilSystemException staticWrapper ;
  97. protected ORBUtilSystemException wrapper ;
  98. protected OMGSystemException omgWrapper ;
  99. // This map is needed for resolving recursive type code placeholders
  100. // based on the unique repository id.
  101. // XXX Should this be a WeakHashMap for GC?
  102. private Map typeCodeMap ;
  103. private TypeCodeImpl[] primitiveTypeCodeConstants ;
  104. // ByteBufferPool - needed by both ORBImpl and ORBSingleton
  105. ByteBufferPool byteBufferPool;
  106. // Local testing
  107. // XXX clean this up, probably remove these
  108. public abstract boolean isLocalHost( String hostName ) ;
  109. public abstract boolean isLocalServerId( int subcontractId, int serverId ) ;
  110. // Invocation stack manipulation
  111. public abstract OAInvocationInfo peekInvocationInfo() ;
  112. public abstract void pushInvocationInfo( OAInvocationInfo info ) ;
  113. public abstract OAInvocationInfo popInvocationInfo() ;
  114. public abstract CorbaTransportManager getCorbaTransportManager();
  115. public abstract LegacyServerSocketManager getLegacyServerSocketManager();
  116. // wrapperMap maintains a table of LogWrapper instances used by
  117. // different classes to log exceptions. The key is a StringPair
  118. // representing LogDomain and ExceptionGroup.
  119. private Map wrapperMap ;
  120. private static Map staticWrapperMap = new HashMap() ;
  121. private MonitoringManager monitoringManager;
  122. // There is only one instance of the PresentationManager
  123. // that is shared between all ORBs. This is necessary
  124. // because RMI-IIOP requires the PresentationManager in
  125. // places where no ORB is available, so the PresentationManager
  126. // must be global. It is initialized here as well.
  127. protected static PresentationManager globalPM = null ;
  128. static {
  129. staticWrapper = ORBUtilSystemException.get(
  130. CORBALogDomains.RPC_PRESENTATION ) ;
  131. boolean useDynamicStub =
  132. ((Boolean)AccessController.doPrivileged(
  133. new PrivilegedAction() {
  134. public java.lang.Object run() {
  135. return Boolean.valueOf( Boolean.getBoolean (
  136. ORBConstants.USE_DYNAMIC_STUB_PROPERTY ) ) ;
  137. }
  138. }
  139. )).booleanValue() ;
  140. PresentationManager.StubFactoryFactory dynamicStubFactoryFactory =
  141. (PresentationManager.StubFactoryFactory)AccessController.doPrivileged(
  142. new PrivilegedAction() {
  143. public java.lang.Object run() {
  144. PresentationManager.StubFactoryFactory sff =
  145. PresentationDefaults.getProxyStubFactoryFactory() ;
  146. String className = System.getProperty(
  147. ORBConstants.DYNAMIC_STUB_FACTORY_FACTORY_CLASS,
  148. "com.sun.corba.se.impl.presentation.rmi.bcel.StubFactoryFactoryBCELImpl" ) ;
  149. try {
  150. // First try the configured class name, if any
  151. Class cls = ORBClassLoader.loadClass( className ) ;
  152. sff = (PresentationManager.StubFactoryFactory)cls.newInstance() ;
  153. } catch (Exception exc) {
  154. // Use the default. Log the error as a warning.
  155. staticWrapper.errorInSettingDynamicStubFactoryFactory(
  156. exc, className ) ;
  157. }
  158. return sff ;
  159. }
  160. }
  161. ) ;
  162. globalPM = new PresentationManagerImpl( useDynamicStub ) ;
  163. globalPM.setStubFactoryFactory( false,
  164. PresentationDefaults.getStaticStubFactoryFactory() ) ;
  165. globalPM.setStubFactoryFactory( true, dynamicStubFactoryFactory ) ;
  166. }
  167. /** Get the single instance of the PresentationManager
  168. */
  169. public static PresentationManager getPresentationManager()
  170. {
  171. return globalPM ;
  172. }
  173. /** Get the appropriate StubFactoryFactory. This
  174. * will be dynamic or static depending on whether
  175. * com.sun.CORBA.ORBUseDynamicStub is true or false.
  176. */
  177. public static PresentationManager.StubFactoryFactory
  178. getStubFactoryFactory()
  179. {
  180. boolean useDynamicStubs = globalPM.useDynamicStubs() ;
  181. return globalPM.getStubFactoryFactory( useDynamicStubs ) ;
  182. }
  183. protected ORB()
  184. {
  185. // Initialize logging first, since it is needed nearly
  186. // everywhere (for example, in TypeCodeImpl).
  187. wrapperMap = new HashMap() ;
  188. wrapper = ORBUtilSystemException.get( this,
  189. CORBALogDomains.RPC_PRESENTATION ) ;
  190. omgWrapper = OMGSystemException.get( this,
  191. CORBALogDomains.RPC_PRESENTATION ) ;
  192. typeCodeMap = new HashMap();
  193. primitiveTypeCodeConstants = new TypeCodeImpl[] {
  194. new TypeCodeImpl(this, TCKind._tk_null),
  195. new TypeCodeImpl(this, TCKind._tk_void),
  196. new TypeCodeImpl(this, TCKind._tk_short),
  197. new TypeCodeImpl(this, TCKind._tk_long),
  198. new TypeCodeImpl(this, TCKind._tk_ushort),
  199. new TypeCodeImpl(this, TCKind._tk_ulong),
  200. new TypeCodeImpl(this, TCKind._tk_float),
  201. new TypeCodeImpl(this, TCKind._tk_double),
  202. new TypeCodeImpl(this, TCKind._tk_boolean),
  203. new TypeCodeImpl(this, TCKind._tk_char),
  204. new TypeCodeImpl(this, TCKind._tk_octet),
  205. new TypeCodeImpl(this, TCKind._tk_any),
  206. new TypeCodeImpl(this, TCKind._tk_TypeCode),
  207. new TypeCodeImpl(this, TCKind._tk_Principal),
  208. new TypeCodeImpl(this, TCKind._tk_objref),
  209. null, // tk_struct
  210. null, // tk_union
  211. null, // tk_enum
  212. new TypeCodeImpl(this, TCKind._tk_string),
  213. null, // tk_sequence
  214. null, // tk_array
  215. null, // tk_alias
  216. null, // tk_except
  217. new TypeCodeImpl(this, TCKind._tk_longlong),
  218. new TypeCodeImpl(this, TCKind._tk_ulonglong),
  219. new TypeCodeImpl(this, TCKind._tk_longdouble),
  220. new TypeCodeImpl(this, TCKind._tk_wchar),
  221. new TypeCodeImpl(this, TCKind._tk_wstring),
  222. new TypeCodeImpl(this, TCKind._tk_fixed),
  223. new TypeCodeImpl(this, TCKind._tk_value),
  224. new TypeCodeImpl(this, TCKind._tk_value_box),
  225. new TypeCodeImpl(this, TCKind._tk_native),
  226. new TypeCodeImpl(this, TCKind._tk_abstract_interface)
  227. } ;
  228. monitoringManager =
  229. MonitoringFactories.getMonitoringManagerFactory( ).
  230. createMonitoringManager(
  231. MonitoringConstants.DEFAULT_MONITORING_ROOT,
  232. MonitoringConstants.DEFAULT_MONITORING_ROOT_DESCRIPTION);
  233. }
  234. // Typecode support: needed in both ORBImpl and ORBSingleton
  235. public TypeCodeImpl get_primitive_tc(int kind)
  236. {
  237. try {
  238. return primitiveTypeCodeConstants[kind] ;
  239. } catch (Throwable t) {
  240. throw wrapper.invalidTypecodeKind( t, new Integer(kind) ) ;
  241. }
  242. }
  243. public synchronized void setTypeCode(String id, TypeCodeImpl code)
  244. {
  245. typeCodeMap.put(id, code);
  246. }
  247. public synchronized TypeCodeImpl getTypeCode(String id)
  248. {
  249. return (TypeCodeImpl)typeCodeMap.get(id);
  250. }
  251. public MonitoringManager getMonitoringManager( ) {
  252. return monitoringManager;
  253. }
  254. // Special non-standard set_parameters method for
  255. // creating a precisely controlled ORB instance.
  256. // An ORB created by this call is affected only by
  257. // those properties passes explicitly in props, not by
  258. // the system properties and orb.properties files as
  259. // with the standard ORB.init methods.
  260. public abstract void set_parameters( Properties props ) ;
  261. // ORB versioning
  262. public abstract ORBVersion getORBVersion() ;
  263. public abstract void setORBVersion( ORBVersion version ) ;
  264. // XXX This needs a better name
  265. public abstract IOR getFVDCodeBaseIOR() ;
  266. /**
  267. * Handle a bad server id for the given object key. This should
  268. * always through an exception: either a ForwardException to
  269. * allow another server to handle the request, or else an error
  270. * indication. XXX Remove after ORT for ORBD work is integrated.
  271. */
  272. public abstract void handleBadServerId( ObjectKey okey ) ;
  273. public abstract void setBadServerIdHandler( BadServerIdHandler handler ) ;
  274. public abstract void initBadServerIdHandler() ;
  275. public abstract void notifyORB() ;
  276. public abstract PIHandler getPIHandler() ;
  277. public abstract void checkShutdownState();
  278. // Dispatch support: in the ORB because it is needed for shutdown.
  279. // This is used by the first level server side subcontract.
  280. public abstract boolean isDuringDispatch() ;
  281. public abstract void startingDispatch();
  282. public abstract void finishedDispatch();
  283. /** Return this ORB's transient server ID. This is needed for
  284. * initializing object adapters.
  285. */
  286. public abstract int getTransientServerId();
  287. public abstract ServiceContextRegistry getServiceContextRegistry() ;
  288. public abstract RequestDispatcherRegistry getRequestDispatcherRegistry();
  289. public abstract ORBData getORBData() ;
  290. public abstract void setClientDelegateFactory( ClientDelegateFactory factory ) ;
  291. public abstract ClientDelegateFactory getClientDelegateFactory() ;
  292. public abstract void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory ) ;
  293. public abstract CorbaContactInfoListFactory getCorbaContactInfoListFactory() ;
  294. // XXX These next 7 methods should be moved to a ResolverManager.
  295. /** Set the resolver used in this ORB. This resolver will be used for list_initial_services
  296. * and resolve_initial_references.
  297. */
  298. public abstract void setResolver( Resolver resolver ) ;
  299. /** Get the resolver used in this ORB. This resolver will be used for list_initial_services
  300. * and resolve_initial_references.
  301. */
  302. public abstract Resolver getResolver() ;
  303. /** Set the LocalResolver used in this ORB. This LocalResolver is used for
  304. * register_initial_reference only.
  305. */
  306. public abstract void setLocalResolver( LocalResolver resolver ) ;
  307. /** Get the LocalResolver used in this ORB. This LocalResolver is used for
  308. * register_initial_reference only.
  309. */
  310. public abstract LocalResolver getLocalResolver() ;
  311. /** Set the operation used in string_to_object calls. The Operation must expect a
  312. * String and return an org.omg.CORBA.Object.
  313. */
  314. public abstract void setURLOperation( Operation stringToObject ) ;
  315. /** Get the operation used in string_to_object calls. The Operation must expect a
  316. * String and return an org.omg.CORBA.Object.
  317. */
  318. public abstract Operation getURLOperation() ;
  319. /** Set the ServerRequestDispatcher that should be used for handling INS requests.
  320. */
  321. public abstract void setINSDelegate( CorbaServerRequestDispatcher insDelegate ) ;
  322. // XXX The next 5 operations should be moved to an IORManager.
  323. /** Factory finders for the various parts of the IOR: tagged components, tagged
  324. * profiles, and tagged profile templates.
  325. */
  326. public abstract TaggedComponentFactoryFinder getTaggedComponentFactoryFinder() ;
  327. public abstract IdentifiableFactoryFinder getTaggedProfileFactoryFinder() ;
  328. public abstract IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder() ;
  329. public abstract ObjectKeyFactory getObjectKeyFactory() ;
  330. public abstract void setObjectKeyFactory( ObjectKeyFactory factory ) ;
  331. // Logging SPI
  332. /**
  333. * Returns the logger based on the category.
  334. */
  335. public Logger getLogger( String domain )
  336. {
  337. ORBData odata = getORBData() ;
  338. // Determine the correct ORBId. There are 3 cases:
  339. // 1. odata is null, which happens if we are getting a logger before
  340. // ORB initialization is complete. In this case we cannot determine
  341. // the ORB ID (it's not known yet), so we set the ORBId to
  342. // _INITIALIZING_.
  343. // 2. odata is not null, so initialization is complete, but ORBId is set to
  344. // the default "". To avoid a ".." in
  345. // the log domain, we simply use _DEFAULT_ in this case.
  346. // 3. odata is not null, ORBId is not "": just use the ORBId.
  347. String ORBId ;
  348. if (odata == null)
  349. ORBId = "_INITIALIZING_" ;
  350. else {
  351. ORBId = odata.getORBId() ;
  352. if (ORBId.equals(""))
  353. ORBId = "_DEFAULT_" ;
  354. }
  355. return getCORBALogger( ORBId, domain ) ;
  356. }
  357. public static Logger staticGetLogger( String domain )
  358. {
  359. return getCORBALogger( "_CORBA_", domain ) ;
  360. }
  361. private static Logger getCORBALogger( String ORBId, String domain )
  362. {
  363. String fqLogDomain = CORBALogDomains.TOP_LEVEL_DOMAIN + "." +
  364. ORBId + "." + domain;
  365. return Logger.getLogger( fqLogDomain, ORBConstants.LOG_RESOURCE_FILE );
  366. }
  367. /** get the log wrapper class (its type is dependent on the exceptionGroup) for the
  368. * given log domain and exception group in this ORB instance.
  369. */
  370. public synchronized LogWrapperBase getLogWrapper( String logDomain,
  371. String exceptionGroup, LogWrapperFactory factory )
  372. {
  373. StringPair key = new StringPair( logDomain, exceptionGroup ) ;
  374. LogWrapperBase logWrapper = (LogWrapperBase)wrapperMap.get( key );
  375. if (logWrapper == null) {
  376. logWrapper = factory.create( getLogger( logDomain ) );
  377. wrapperMap.put( key, logWrapper );
  378. }
  379. return logWrapper;
  380. }
  381. /** get the log wrapper class (its type is dependent on the exceptionGroup) for the
  382. * given log domain and exception group in this ORB instance.
  383. */
  384. public synchronized static LogWrapperBase staticGetLogWrapper( String logDomain,
  385. String exceptionGroup, LogWrapperFactory factory )
  386. {
  387. StringPair key = new StringPair( logDomain, exceptionGroup ) ;
  388. LogWrapperBase logWrapper = (LogWrapperBase)staticWrapperMap.get( key );
  389. if (logWrapper == null) {
  390. logWrapper = factory.create( staticGetLogger( logDomain ) );
  391. staticWrapperMap.put( key, logWrapper );
  392. }
  393. return logWrapper;
  394. }
  395. // get a reference to a ByteBufferPool, a pool of NIO ByteBuffers
  396. // NOTE: ByteBuffer pool must be unique per ORB, not per process.
  397. // There can be more than one ORB per process.
  398. // This method must also be inherited by both ORB and ORBSingleton.
  399. public ByteBufferPool getByteBufferPool()
  400. {
  401. if (byteBufferPool == null)
  402. byteBufferPool = new ByteBufferPoolImpl(this);
  403. return byteBufferPool;
  404. }
  405. public abstract void setThreadPoolManager(ThreadPoolManager mgr);
  406. public abstract ThreadPoolManager getThreadPoolManager();
  407. public abstract CopierManager getCopierManager() ;
  408. }
  409. // End of file.