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