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