1 /* 2 * Copyright (c) 2002, 2012, 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 protected 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 public void destroy() { 230 wrapper = null; 231 omgWrapper = null; 232 typeCodeMap = null; 233 primitiveTypeCodeConstants = null; 234 byteBufferPool = null; 235 } 236 237 /** Get the single instance of the PresentationManager 238 */ 239 public static PresentationManager getPresentationManager() 240 { 241 return globalPM ; 242 } 243 244 /** Get the appropriate StubFactoryFactory. This 245 * will be dynamic or static depending on whether 246 * com.sun.CORBA.ORBUseDynamicStub is true or false. 247 */ 248 public static PresentationManager.StubFactoryFactory 249 getStubFactoryFactory() 250 { 251 boolean useDynamicStubs = globalPM.useDynamicStubs() ; 252 return globalPM.getStubFactoryFactory( useDynamicStubs ) ; 253 } 254 255 protected ORB() 256 { 257 // Initialize logging first, since it is needed nearly 258 // everywhere (for example, in TypeCodeImpl). 259 wrapperMap = new ConcurrentHashMap(); 260 wrapper = ORBUtilSystemException.get( this, 261 CORBALogDomains.RPC_PRESENTATION ) ; 262 omgWrapper = OMGSystemException.get( this, 263 CORBALogDomains.RPC_PRESENTATION ) ; 264 265 typeCodeMap = new HashMap(); 266 267 primitiveTypeCodeConstants = new TypeCodeImpl[] { 268 new TypeCodeImpl(this, TCKind._tk_null), 269 new TypeCodeImpl(this, TCKind._tk_void), 270 new TypeCodeImpl(this, TCKind._tk_short), 271 new TypeCodeImpl(this, TCKind._tk_long), 272 new TypeCodeImpl(this, TCKind._tk_ushort), 273 new TypeCodeImpl(this, TCKind._tk_ulong), 274 new TypeCodeImpl(this, TCKind._tk_float), 275 new TypeCodeImpl(this, TCKind._tk_double), 276 new TypeCodeImpl(this, TCKind._tk_boolean), 277 new TypeCodeImpl(this, TCKind._tk_char), 278 new TypeCodeImpl(this, TCKind._tk_octet), 279 new TypeCodeImpl(this, TCKind._tk_any), 280 new TypeCodeImpl(this, TCKind._tk_TypeCode), 281 new TypeCodeImpl(this, TCKind._tk_Principal), 282 new TypeCodeImpl(this, TCKind._tk_objref), 283 null, // tk_struct 284 null, // tk_union 285 null, // tk_enum 286 new TypeCodeImpl(this, TCKind._tk_string), 287 null, // tk_sequence 288 null, // tk_array 289 null, // tk_alias 290 null, // tk_except 291 new TypeCodeImpl(this, TCKind._tk_longlong), 292 new TypeCodeImpl(this, TCKind._tk_ulonglong), 293 new TypeCodeImpl(this, TCKind._tk_longdouble), 294 new TypeCodeImpl(this, TCKind._tk_wchar), 295 new TypeCodeImpl(this, TCKind._tk_wstring), 296 new TypeCodeImpl(this, TCKind._tk_fixed), 297 new TypeCodeImpl(this, TCKind._tk_value), 298 new TypeCodeImpl(this, TCKind._tk_value_box), 299 new TypeCodeImpl(this, TCKind._tk_native), 300 new TypeCodeImpl(this, TCKind._tk_abstract_interface) 301 } ; 302 303 monitoringManager = 304 MonitoringFactories.getMonitoringManagerFactory( ). 305 createMonitoringManager( 306 MonitoringConstants.DEFAULT_MONITORING_ROOT, 307 MonitoringConstants.DEFAULT_MONITORING_ROOT_DESCRIPTION); 308 } 309 310 // Typecode support: needed in both ORBImpl and ORBSingleton 311 public TypeCodeImpl get_primitive_tc(int kind) 312 { 313 synchronized (this) { 314 checkShutdownState(); 315 } 316 try { 317 return primitiveTypeCodeConstants[kind] ; 318 } catch (Throwable t) { 319 throw wrapper.invalidTypecodeKind( t, new Integer(kind) ) ; 320 } 321 } 322 323 public synchronized void setTypeCode(String id, TypeCodeImpl code) 324 { 325 checkShutdownState(); 326 typeCodeMap.put(id, code); 327 } 328 329 public synchronized TypeCodeImpl getTypeCode(String id) 330 { 331 checkShutdownState(); 332 return (TypeCodeImpl)typeCodeMap.get(id); 333 } 334 335 public MonitoringManager getMonitoringManager( ) { 336 synchronized (this) { 337 checkShutdownState(); 338 } 339 return monitoringManager; 340 } 341 342 // Special non-standard set_parameters method for 343 // creating a precisely controlled ORB instance. 344 // An ORB created by this call is affected only by 345 // those properties passes explicitly in props, not by 346 // the system properties and orb.properties files as 347 // with the standard ORB.init methods. 348 public abstract void set_parameters( Properties props ) ; 349 350 // ORB versioning 351 public abstract ORBVersion getORBVersion() ; 352 public abstract void setORBVersion( ORBVersion version ) ; 353 354 // XXX This needs a better name 355 public abstract IOR getFVDCodeBaseIOR() ; 356 357 /** 358 * Handle a bad server id for the given object key. This should 359 * always through an exception: either a ForwardException to 360 * allow another server to handle the request, or else an error 361 * indication. XXX Remove after ORT for ORBD work is integrated. 362 */ 363 public abstract void handleBadServerId( ObjectKey okey ) ; 364 public abstract void setBadServerIdHandler( BadServerIdHandler handler ) ; 365 public abstract void initBadServerIdHandler() ; 366 367 public abstract void notifyORB() ; 368 369 public abstract PIHandler getPIHandler() ; 370 371 public abstract void checkShutdownState(); 372 373 // Dispatch support: in the ORB because it is needed for shutdown. 374 // This is used by the first level server side subcontract. 375 public abstract boolean isDuringDispatch() ; 376 public abstract void startingDispatch(); 377 public abstract void finishedDispatch(); 378 379 /** Return this ORB's transient server ID. This is needed for 380 * initializing object adapters. 381 */ 382 public abstract int getTransientServerId(); 383 384 public abstract ServiceContextRegistry getServiceContextRegistry() ; 385 386 public abstract RequestDispatcherRegistry getRequestDispatcherRegistry(); 387 388 public abstract ORBData getORBData() ; 389 390 public abstract void setClientDelegateFactory( ClientDelegateFactory factory ) ; 391 392 public abstract ClientDelegateFactory getClientDelegateFactory() ; 393 394 public abstract void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory ) ; 395 396 public abstract CorbaContactInfoListFactory getCorbaContactInfoListFactory() ; 397 398 // XXX These next 7 methods should be moved to a ResolverManager. 399 400 /** Set the resolver used in this ORB. This resolver will be used for list_initial_services 401 * and resolve_initial_references. 402 */ 403 public abstract void setResolver( Resolver resolver ) ; 404 405 /** Get the resolver used in this ORB. This resolver will be used for list_initial_services 406 * and resolve_initial_references. 407 */ 408 public abstract Resolver getResolver() ; 409 410 /** Set the LocalResolver used in this ORB. This LocalResolver is used for 411 * register_initial_reference only. 412 */ 413 public abstract void setLocalResolver( LocalResolver resolver ) ; 414 415 /** Get the LocalResolver used in this ORB. This LocalResolver is used for 416 * register_initial_reference only. 417 */ 418 public abstract LocalResolver getLocalResolver() ; 419 420 /** Set the operation used in string_to_object calls. The Operation must expect a 421 * String and return an org.omg.CORBA.Object. 422 */ 423 public abstract void setURLOperation( Operation stringToObject ) ; 424 425 /** Get the operation used in string_to_object calls. The Operation must expect a 426 * String and return an org.omg.CORBA.Object. 427 */ 428 public abstract Operation getURLOperation() ; 429 430 /** Set the ServerRequestDispatcher that should be used for handling INS requests. 431 */ 432 public abstract void setINSDelegate( CorbaServerRequestDispatcher insDelegate ) ; 433 434 // XXX The next 5 operations should be moved to an IORManager. 435 436 /** Factory finders for the various parts of the IOR: tagged components, tagged 437 * profiles, and tagged profile templates. 438 */ 439 public abstract TaggedComponentFactoryFinder getTaggedComponentFactoryFinder() ; 440 public abstract IdentifiableFactoryFinder getTaggedProfileFactoryFinder() ; 441 public abstract IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder() ; 442 443 public abstract ObjectKeyFactory getObjectKeyFactory() ; 444 public abstract void setObjectKeyFactory( ObjectKeyFactory factory ) ; 445 446 // Logging SPI 447 448 /** 449 * Returns the logger based on the category. 450 */ 451 public Logger getLogger( String domain ) 452 { 453 synchronized (this) { 454 checkShutdownState(); 455 } 456 ORBData odata = getORBData() ; 457 458 // Determine the correct ORBId. There are 3 cases: 459 // 1. odata is null, which happens if we are getting a logger before 460 // ORB initialization is complete. In this case we cannot determine 461 // the ORB ID (it's not known yet), so we set the ORBId to 462 // _INITIALIZING_. 463 // 2. odata is not null, so initialization is complete, but ORBId is set to 464 // the default "". To avoid a ".." in 465 // the log domain, we simply use _DEFAULT_ in this case. 466 // 3. odata is not null, ORBId is not "": just use the ORBId. 467 String ORBId ; 468 if (odata == null) 469 ORBId = "_INITIALIZING_" ; 470 else { 471 ORBId = odata.getORBId() ; 472 if (ORBId.equals("")) 473 ORBId = "_DEFAULT_" ; 474 } 475 476 return getCORBALogger( ORBId, domain ) ; 477 } 478 479 public static Logger staticGetLogger( String domain ) 480 { 481 return getCORBALogger( "_CORBA_", domain ) ; 482 } 483 484 private static Logger getCORBALogger( String ORBId, String domain ) 485 { 486 String fqLogDomain = CORBALogDomains.TOP_LEVEL_DOMAIN + "." + 487 ORBId + "." + domain; 488 489 return Logger.getLogger( fqLogDomain, ORBConstants.LOG_RESOURCE_FILE ); 490 } 491 492 /** get the log wrapper class (its type is dependent on the exceptionGroup) for the 493 * given log domain and exception group in this ORB instance. 494 */ 495 public LogWrapperBase getLogWrapper( String logDomain, 496 String exceptionGroup, LogWrapperFactory factory ) 497 { 498 StringPair key = new StringPair( logDomain, exceptionGroup ) ; 499 500 LogWrapperBase logWrapper = (LogWrapperBase)wrapperMap.get( key ); 501 if (logWrapper == null) { 502 logWrapper = factory.create( getLogger( logDomain ) ); 503 wrapperMap.put( key, logWrapper ); 504 } 505 506 return logWrapper; 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 static LogWrapperBase staticGetLogWrapper( String logDomain, 513 String exceptionGroup, LogWrapperFactory factory ) 514 { 515 StringPair key = new StringPair( logDomain, exceptionGroup ) ; 516 517 LogWrapperBase logWrapper = (LogWrapperBase)staticWrapperMap.get( key ); 518 if (logWrapper == null) { 519 logWrapper = factory.create( staticGetLogger( logDomain ) ); 520 staticWrapperMap.put( key, logWrapper ); 521 } 522 523 return logWrapper; 524 } 525 526 // get a reference to a ByteBufferPool, a pool of NIO ByteBuffers 527 // NOTE: ByteBuffer pool must be unique per ORB, not per process. 528 // There can be more than one ORB per process. 529 // This method must also be inherited by both ORB and ORBSingleton. 530 public ByteBufferPool getByteBufferPool() 531 { 532 synchronized (this) { 533 checkShutdownState(); 534 } 535 if (byteBufferPool == null) 536 byteBufferPool = new ByteBufferPoolImpl(this); 537 538 return byteBufferPool; 539 } 540 541 public abstract void setThreadPoolManager(ThreadPoolManager mgr); 542 543 public abstract ThreadPoolManager getThreadPoolManager(); 544 545 public abstract CopierManager getCopierManager() ; 546 } 547 548 // End of file.