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