1 /* 2 * Copyright (c) 2002, 2010, 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.impl.orb ; 27 28 import java.applet.Applet; 29 30 import java.io.IOException ; 31 32 import java.lang.reflect.Constructor; 33 import java.lang.reflect.Field ; 34 import java.lang.reflect.Modifier ; 35 import java.lang.reflect.InvocationTargetException ; 36 37 import java.util.ArrayList ; 38 import java.util.Iterator ; 39 import java.util.Properties ; 40 import java.util.Vector ; 41 import java.util.Hashtable ; 42 import java.util.Map ; 43 import java.util.HashMap ; 44 import java.util.LinkedList ; 45 import java.util.Collection ; 46 import java.util.Collections ; 47 import java.util.StringTokenizer ; 48 import java.util.Enumeration ; 49 import java.util.WeakHashMap ; 50 51 import java.net.InetAddress ; 52 53 import java.security.PrivilegedAction; 54 import java.security.AccessController ; 55 56 import javax.rmi.CORBA.Util; 57 import javax.rmi.CORBA.ValueHandler; 58 59 import org.omg.CORBA.Context; 60 import org.omg.CORBA.ContextList; 61 import org.omg.CORBA.Environment; 62 import org.omg.CORBA.ExceptionList; 63 import org.omg.CORBA.ORBPackage.InvalidName; 64 import org.omg.CORBA.NVList; 65 import org.omg.CORBA.TCKind; 66 import org.omg.CORBA.NamedValue; 67 import org.omg.CORBA.Request; 68 import org.omg.CORBA.SystemException; 69 import org.omg.CORBA.CompletionStatus; 70 import org.omg.CORBA.TypeCode; 71 import org.omg.CORBA.Any; 72 import org.omg.CORBA.StructMember; 73 import org.omg.CORBA.UnionMember; 74 import org.omg.CORBA.ValueMember; 75 import org.omg.CORBA.BAD_PARAM; 76 import org.omg.CORBA.MARSHAL; 77 78 import org.omg.CORBA.portable.ValueFactory; 79 80 import org.omg.CORBA.ORBPackage.InvalidName; 81 82 import com.sun.org.omg.SendingContext.CodeBase; 83 84 import com.sun.corba.se.pept.broker.Broker; 85 import com.sun.corba.se.pept.protocol.ClientInvocationInfo ; 86 import com.sun.corba.se.pept.transport.ContactInfo; 87 import com.sun.corba.se.pept.transport.ConnectionCache; 88 import com.sun.corba.se.pept.transport.TransportManager; 89 90 import com.sun.corba.se.spi.ior.IOR; 91 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ; 92 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder; 93 import com.sun.corba.se.spi.ior.IORFactories ; 94 import com.sun.corba.se.spi.ior.ObjectKey ; 95 import com.sun.corba.se.spi.ior.ObjectKeyFactory ; 96 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ; 97 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 98 import com.sun.corba.se.spi.oa.OAInvocationInfo; 99 import com.sun.corba.se.spi.oa.ObjectAdapterFactory; 100 import com.sun.corba.se.spi.orb.DataCollector; 101 import com.sun.corba.se.spi.orb.Operation; 102 import com.sun.corba.se.spi.orb.ORBData; 103 import com.sun.corba.se.spi.orb.ORBConfigurator; 104 import com.sun.corba.se.spi.orb.ParserImplBase; 105 import com.sun.corba.se.spi.orb.PropertyParser; 106 import com.sun.corba.se.spi.orb.OperationFactory; 107 import com.sun.corba.se.spi.orb.ORBVersion; 108 import com.sun.corba.se.spi.orb.ORBVersionFactory; 109 import com.sun.corba.se.spi.orbutil.closure.ClosureFactory; 110 import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager; 111 import com.sun.corba.se.spi.protocol.ClientDelegateFactory; 112 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 113 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher; 114 import com.sun.corba.se.spi.protocol.RequestDispatcherDefault; 115 import com.sun.corba.se.spi.protocol.PIHandler; 116 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 117 import com.sun.corba.se.spi.protocol.ForwardException; 118 import com.sun.corba.se.spi.resolver.Resolver; 119 import com.sun.corba.se.spi.resolver.LocalResolver; 120 import com.sun.corba.se.spi.orb.StringPair; 121 import com.sun.corba.se.spi.orb.StringPair; 122 import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory; 123 import com.sun.corba.se.spi.transport.CorbaTransportManager; 124 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager; 125 import com.sun.corba.se.spi.copyobject.CopierManager ; 126 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ; 127 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ; 128 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ; 129 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry; 130 131 import com.sun.corba.se.impl.corba.TypeCodeFactory; 132 import com.sun.corba.se.impl.corba.TypeCodeImpl; 133 import com.sun.corba.se.impl.corba.NVListImpl; 134 import com.sun.corba.se.impl.corba.ExceptionListImpl; 135 import com.sun.corba.se.impl.corba.ContextListImpl; 136 import com.sun.corba.se.impl.corba.NamedValueImpl; 137 import com.sun.corba.se.impl.corba.EnvironmentImpl; 138 import com.sun.corba.se.impl.corba.AsynchInvoke; 139 import com.sun.corba.se.impl.corba.AnyImpl; 140 import com.sun.corba.se.impl.corba.RequestImpl; 141 import com.sun.corba.se.impl.dynamicany.DynAnyFactoryImpl; 142 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 143 import com.sun.corba.se.impl.interceptors.PIHandlerImpl; 144 import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl; 145 import com.sun.corba.se.impl.ior.TaggedComponentFactoryFinderImpl; 146 import com.sun.corba.se.impl.ior.TaggedProfileFactoryFinderImpl; 147 import com.sun.corba.se.impl.ior.TaggedProfileTemplateFactoryFinderImpl; 148 import com.sun.corba.se.impl.oa.toa.TOAFactory; 149 import com.sun.corba.se.impl.oa.poa.BadServerIdHandler; 150 import com.sun.corba.se.impl.oa.poa.DelegateImpl; 151 import com.sun.corba.se.impl.oa.poa.POAFactory; 152 import com.sun.corba.se.impl.orbutil.ORBClassLoader; 153 import com.sun.corba.se.impl.orbutil.ORBConstants; 154 import com.sun.corba.se.impl.orbutil.ORBUtility; 155 import com.sun.corba.se.impl.orbutil.StackImpl; 156 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl; 157 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolManagerImpl; 158 import com.sun.corba.se.impl.protocol.RequestDispatcherRegistryImpl; 159 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo; 160 import com.sun.corba.se.impl.transport.CorbaTransportManagerImpl; 161 import com.sun.corba.se.impl.legacy.connection.LegacyServerSocketManagerImpl; 162 import com.sun.corba.se.impl.util.Utility; 168 * The JavaIDL ORB implementation. 169 */ 170 public class ORBImpl extends com.sun.corba.se.spi.orb.ORB 171 { 172 protected TransportManager transportManager; 173 protected LegacyServerSocketManager legacyServerSocketManager; 174 175 private ThreadLocal OAInvocationInfoStack ; 176 177 private ThreadLocal clientInvocationInfoStack ; 178 179 // pure java orb, caching the servant IOR per ORB 180 private static IOR codeBaseIOR ; 181 182 // Vector holding deferred Requests 183 private Vector dynamicRequests ; 184 private SynchVariable svResponseReceived ; 185 186 private java.lang.Object runObj = new java.lang.Object(); 187 private java.lang.Object shutdownObj = new java.lang.Object(); 188 private static final byte STATUS_OPERATING = 1; 189 private static final byte STATUS_SHUTTING_DOWN = 2; 190 private static final byte STATUS_SHUTDOWN = 3; 191 private static final byte STATUS_DESTROYED = 4; 192 private byte status = STATUS_OPERATING; 193 194 // XXX Should we move invocation tracking to the first level server dispatcher? 195 private java.lang.Object invocationObj = new java.lang.Object(); 196 197 // thread local variable to store a boolean to detect deadlock in 198 // ORB.shutdown(true). 199 private ThreadLocal isProcessingInvocation = new ThreadLocal () { 200 protected java.lang.Object initialValue() { 201 return Boolean.FALSE; 202 } 203 }; 204 205 // This map is caching TypeCodes created for a certain class (key) 206 // and is used in Util.writeAny() 207 private Map typeCodeForClassMap ; 208 209 // Cache to hold ValueFactories (Helper classes) keyed on repository ids 210 private Hashtable valueFactoryCache = new Hashtable(); 211 212 // thread local variable to store the current ORB version. 213 // default ORB version is the version of ORB with correct Rep-id 214 // changes 215 private ThreadLocal orbVersionThreadLocal ; 216 217 private RequestDispatcherRegistry requestDispatcherRegistry ; 218 219 private CopierManager copierManager ; 220 221 private int transientServerId ; 222 223 private ThreadGroup threadGroup ; 224 225 private ServiceContextRegistry serviceContextRegistry ; 226 227 // Needed here to implement connect/disconnect 228 private TOAFactory toaFactory ; 229 230 // Needed here for set_delegate 231 private POAFactory poaFactory ; 232 233 // The interceptor handler, which provides portable interceptor services for 234 // subcontracts and object adapters. 235 private PIHandler pihandler ; 236 237 private ORBData configData ; 238 239 private BadServerIdHandler badServerIdHandler ; 240 241 private ClientDelegateFactory clientDelegateFactory ; 242 243 private CorbaContactInfoListFactory corbaContactInfoListFactory ; 244 248 // Note that we now have separate locks for each resolver type. This is due 249 // to bug 6980681 and 6238477, which was caused by a deadlock while resolving a 250 // corbaname: URL that contained a reference to the same ORB as the 251 // ORB making the call to string_to_object. This caused a deadlock between the 252 // client thread holding the single lock for access to the urlOperation, 253 // and the server thread handling the client is_a request waiting on the 254 // same lock to access the localResolver. 255 256 257 // Used for resolver_initial_references and list_initial_services 258 private Resolver resolver ; 259 260 // Used for register_initial_references 261 private LocalResolver localResolver ; 262 263 // Converts strings to object references for resolvers and string_to_object 264 private Operation urlOperation ; 265 private final Object urlOperationLock = new java.lang.Object() ; 266 267 private CorbaServerRequestDispatcher insNamingDelegate ; 268 // resolverLock must be used for all access to either resolver or 269 // localResolver, since it is possible for the resolver to indirectly 270 // refer to the localResolver. Also used to protect access to 271 // insNamingDelegate. 272 private final Object resolverLock = new Object() ; 273 274 private TaggedComponentFactoryFinder taggedComponentFactoryFinder ; 275 276 private IdentifiableFactoryFinder taggedProfileFactoryFinder ; 277 278 private IdentifiableFactoryFinder taggedProfileTemplateFactoryFinder ; 279 280 private ObjectKeyFactory objectKeyFactory ; 281 282 private ThreadPoolManager threadpoolMgr; 283 284 private void dprint( String msg ) 285 { 286 ORBUtility.dprint( this, msg ) ; 287 } 288 289 //////////////////////////////////////////////////// 290 // 291 // NOTE: 292 // 293 // Methods that are synchronized MUST stay synchronized. 294 // 295 // Methods that are NOT synchronized must stay that way to avoid deadlock. 296 // 297 // 298 // REVISIT: 299 // 300 // checkShutDownState - lock on different object - and normalize usage. 301 // starting/FinishDispatch and Shutdown 305 { 306 return configData ; 307 } 308 309 public PIHandler getPIHandler() 310 { 311 return pihandler ; 312 } 313 314 /** 315 * Create a new ORB. Should be followed by the appropriate 316 * set_parameters() call. 317 */ 318 public ORBImpl() 319 { 320 // All initialization is done through set_parameters(). 321 } 322 323 public ORBVersion getORBVersion() 324 { 325 return (ORBVersion)(orbVersionThreadLocal.get()) ; 326 } 327 328 public void setORBVersion(ORBVersion verObj) 329 { 330 orbVersionThreadLocal.set(verObj); 331 } 332 333 /**************************************************************************** 334 * The following methods are ORB initialization 335 ****************************************************************************/ 336 337 // preInit initializes all non-pluggable ORB data that is independent 338 // of the property parsing. 339 private void preInit( String[] params, Properties props ) 340 { 341 // Before ORBConfiguration we need to set a PINoOpHandlerImpl, 342 // because PersisentServer Initialization inside configurator will 343 // invoke orb.resolve_initial_references( ) which will result in a 344 // check on piHandler to invoke Interceptors. We do not want any 345 // Interceptors to be invoked before the complete ORB initialization. 346 // piHandler will be replaced by a real PIHandler implementation at the 347 // end of this method. 348 pihandler = new PINoOpHandlerImpl( ); 349 350 // See bugs 4916766 and 4936203 351 // We intend to create new threads in a reliable thread group. 352 // This avoids problems if the application/applet 353 // creates a thread group, makes JavaIDL calls which create a new 354 // connection and ReaderThread, and then destroys the thread 355 // group. If our ReaderThreads were to be part of such destroyed thread 356 // group then it might get killed and cause other invoking threads 357 // sharing the same connection to get a non-restartable 358 // CommunicationFailure. We'd like to avoid that. 359 // 360 // Our solution is to create all of our threads in the highest thread 361 // group that we have access to, given our own security clearance. 362 // 363 try { 364 // try to get a thread group that's as high in the threadgroup 365 // parent-child hierarchy, as we can get to. 366 // this will prevent an ORB thread created during applet-init from 367 // being killed when an applet dies. 368 threadGroup = (ThreadGroup) AccessController.doPrivileged( 369 new PrivilegedAction() { 370 public Object run() { 371 ThreadGroup tg = Thread.currentThread().getThreadGroup() ; 372 ThreadGroup ptg = tg ; 373 try { 374 while (ptg != null) { 375 tg = ptg; 376 ptg = tg.getParent(); 377 } 378 } catch (SecurityException se) { 379 // Discontinue going higher on a security exception. 380 } 381 return new ThreadGroup(tg, "ORB ThreadGroup"); 382 } 383 } 384 ); 385 } catch (SecurityException e) { 386 // something wrong, we go back to the original code 387 threadGroup = Thread.currentThread().getThreadGroup(); 388 } 389 390 // This is the unique id of this server (JVM). Multiple incarnations 391 // of this server will get different ids. 392 // Compute transientServerId = milliseconds since Jan 1, 1970 393 // Note: transientServerId will wrap in about 2^32 / 86400000 = 49.7 days. 394 // If two ORBS are started at the same time then there is a possibility 395 // of having the same transientServerId. This may result in collision 396 // and may be a problem in ior.isLocal() check to see if the object 397 // belongs to the current ORB. This problem is taken care of by checking 398 // to see if the IOR port matches ORB server port in legacyIsLocalServerPort() 399 // method. 400 // 401 // XXX need to move server ID to a string for CORBA 3.0. At that point, 402 // make this more unique (possibly use java.rmi.server.UID). 403 transientServerId = (int)System.currentTimeMillis(); 404 405 orbVersionThreadLocal = new ThreadLocal () { 406 protected java.lang.Object initialValue() { 407 // set default to version of the ORB with correct Rep-ids 408 return ORBVersionFactory.getORBVersion() ; 409 } 530 if (poaFactory == null) { 531 poaFactory = (POAFactory)requestDispatcherRegistry.getObjectAdapterFactory( 532 ORBConstants.TRANSIENT_SCID ) ; 533 } 534 535 return poaFactory ; 536 } 537 538 private synchronized TOAFactory getTOAFactory() 539 { 540 if (toaFactory == null) { 541 toaFactory = (TOAFactory)requestDispatcherRegistry.getObjectAdapterFactory( 542 ORBConstants.TOA_SCID ) ; 543 } 544 545 return toaFactory ; 546 } 547 548 public void set_parameters( Properties props ) 549 { 550 preInit( null, props ) ; 551 DataCollector dataCollector = 552 DataCollectorFactory.create( props, getLocalHostName() ) ; 553 postInit( null, dataCollector ) ; 554 } 555 556 protected void set_parameters(Applet app, Properties props) 557 { 558 preInit( null, props ) ; 559 DataCollector dataCollector = 560 DataCollectorFactory.create( app, props, getLocalHostName() ) ; 561 postInit( null, dataCollector ) ; 562 } 563 564 protected void set_parameters (String[] params, Properties props) 565 { 566 preInit( params, props ) ; 567 DataCollector dataCollector = 568 DataCollectorFactory.create( params, props, getLocalHostName() ) ; 569 postInit( params, dataCollector ) ; 771 // wait for a response 772 synchronized(this.svResponseReceived) { 773 while (!this.svResponseReceived.value()) { 774 try { 775 this.svResponseReceived.wait(); 776 } catch(java.lang.InterruptedException ex) { 777 // NO-OP 778 } 779 } 780 // reinitialize the response flag 781 this.svResponseReceived.reset(); 782 } 783 } 784 } 785 786 /** 787 * Notify response to ORB for get_next_response 788 */ 789 public void notifyORB() 790 { 791 synchronized (this.svResponseReceived) { 792 this.svResponseReceived.set(); 793 this.svResponseReceived.notify(); 794 } 795 } 796 797 /** 798 * Convert an object ref to a string. 799 * @param obj The object to stringify. 800 * @return A stringified object reference. 801 */ 802 public synchronized String object_to_string(org.omg.CORBA.Object obj) 803 { 804 checkShutdownState(); 805 806 // Handle the null objref case 807 if (obj == null) { 808 IOR nullIOR = IORFactories.makeIOR( this ) ; 809 return nullIOR.stringify(); 810 } 837 Operation op ; 838 839 synchronized (this) { 840 checkShutdownState(); 841 op = urlOperation ; 842 } 843 844 if (str == null) 845 throw wrapper.nullParam() ; 846 847 synchronized (urlOperationLock) { 848 org.omg.CORBA.Object obj = (org.omg.CORBA.Object)op.operate( str ) ; 849 return obj ; 850 } 851 } 852 853 // pure java orb support, moved this method from FVDCodeBaseImpl. 854 // Note that we connect this if we have not already done so. 855 public synchronized IOR getFVDCodeBaseIOR() 856 { 857 if (codeBaseIOR != null) // i.e. We are already connected to it 858 return codeBaseIOR; 859 860 // backward compatability 4365188 861 CodeBase cb; 862 863 ValueHandler vh = ORBUtility.createValueHandler(this); 864 865 cb = (CodeBase)vh.getRunTimeCodeBase(); 866 return ORBUtility.connectAndGetIOR( this, cb ) ; 867 } 868 869 /** 870 * Get the TypeCode for a primitive type. 871 * 872 * @param tcKind the integer kind for the primitive type 873 * @return the requested TypeCode 874 */ 875 public synchronized TypeCode get_primitive_tc(TCKind tcKind) 876 { 1101 1102 /** 1103 * Create a new Any 1104 * 1105 * @return the new Any created. 1106 */ 1107 public synchronized Any create_any() 1108 { 1109 checkShutdownState(); 1110 return new AnyImpl(this); 1111 } 1112 1113 // TypeCodeFactory interface methods. 1114 // Keeping track of type codes by repository id. 1115 1116 // Keeping a cache of TypeCodes associated with the class 1117 // they got created from in Util.writeAny(). 1118 1119 public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci) 1120 { 1121 if (typeCodeForClassMap == null) 1122 typeCodeForClassMap = Collections.synchronizedMap( 1123 new WeakHashMap(64)); 1124 // Store only one TypeCode per class. 1125 if ( ! typeCodeForClassMap.containsKey(c)) 1126 typeCodeForClassMap.put(c, tci); 1127 } 1128 1129 public synchronized TypeCodeImpl getTypeCodeForClass(Class c) 1130 { 1131 if (typeCodeForClassMap == null) 1132 return null; 1133 return (TypeCodeImpl)typeCodeForClassMap.get(c); 1134 } 1135 1136 /**************************************************************************** 1137 * The following methods deal with listing and resolving the initial 1138 * (bootstrap) object references such as "NameService". 1139 ****************************************************************************/ 1140 1141 /** 1142 * Get a list of the initially available CORBA services. 1143 * This does not work unless an ORBInitialHost is specified during 1144 * initialization (or unless there is an ORB running on the AppletHost) 1145 * since the localhostname 1146 * is inaccessible to applets. If a service properties URL was specified, 1147 * then it is used, otherwise the bootstrapping protocol is used. 1148 * @return A list of the initial services available. 1149 */ 1150 public String[] list_initial_services() 1193 } 1194 1195 /** 1196 * If this operation is called with an id, <code>"Y"</code>, and an 1197 * object, <code>YY</code>, then a subsequent call to 1198 * <code>ORB.resolve_initial_references( "Y" )</code> will 1199 * return object <code>YY</code>. 1200 * 1201 * @param id The ID by which the initial reference will be known. 1202 * @param obj The initial reference itself. 1203 * @throws InvalidName if this operation is called with an empty string id 1204 * or this operation is called with an id that is already registered, 1205 * including the default names defined by OMG. 1206 * @throws BAD_PARAM if the obj parameter is null. 1207 */ 1208 public void register_initial_reference( 1209 String id, org.omg.CORBA.Object obj ) throws InvalidName 1210 { 1211 CorbaServerRequestDispatcher insnd ; 1212 1213 if ((id == null) || (id.length() == 0)) 1214 throw new InvalidName() ; 1215 1216 synchronized (this) { 1217 checkShutdownState(); 1218 } 1219 1220 synchronized (resolverLock) { 1221 insnd = insNamingDelegate ; 1222 1223 java.lang.Object obj2 = localResolver.resolve( id ) ; 1224 if (obj2 != null) 1225 throw new InvalidName(id + " already registered") ; 1226 1227 localResolver.register( id, ClosureFactory.makeConstant( obj )) ; 1228 } 1229 1230 synchronized (this) { 1231 if (StubAdapter.isStub(obj)) 1232 // Make all remote object references available for INS. 1236 } 1237 1238 /**************************************************************************** 1239 * The following methods (introduced in POA / CORBA2.1) deal with 1240 * shutdown / single threading. 1241 ****************************************************************************/ 1242 1243 public void run() 1244 { 1245 synchronized (this) { 1246 checkShutdownState(); 1247 } 1248 1249 synchronized (runObj) { 1250 try { 1251 runObj.wait(); 1252 } catch ( InterruptedException ex ) {} 1253 } 1254 } 1255 1256 public void shutdown(boolean wait_for_completion) 1257 { 1258 // to wait for completion, we would deadlock, so throw a standard 1259 // OMG exception. 1260 if (wait_for_completion && ((Boolean)isProcessingInvocation.get()).booleanValue()) { 1261 throw omgWrapper.shutdownWaitForCompletionDeadlock() ; 1262 } 1263 1264 boolean doShutdown = false ; 1265 1266 synchronized (this) { 1267 checkShutdownState() ; 1268 1269 if (status == STATUS_SHUTTING_DOWN) { 1270 if (!wait_for_completion) 1271 // If we are already shutting down and don't want 1272 // to wait, nothing to do: return. 1273 return ; 1274 } else { 1275 // The ORB status was STATUS_OPERATING, so start the shutdown. 1276 status = STATUS_SHUTTING_DOWN ; 1277 doShutdown = true ; 1278 } 1279 } 1280 1281 // At this point, status is SHUTTING_DOWN. 1282 // All shutdown calls with wait_for_completion == true must synchronize 1283 // here. Only the first call will be made with doShutdown == true. 1284 synchronized (shutdownObj) { 1285 if (doShutdown) { 1286 // shutdownServants will set all POAManagers into the 1287 // INACTIVE state, causing request to be rejected. 1288 // If wait_for_completion is true, this will not return until 1289 // all invocations have completed. 1290 shutdownServants(wait_for_completion); 1291 1292 synchronized (runObj) { 1293 runObj.notifyAll(); 1294 } 1295 1296 synchronized (this) { 1297 status = STATUS_SHUTDOWN; 1298 } 1299 } 1300 } 1301 } 1302 1303 /** This method shuts down the ORB and causes orb.run() to return. 1304 * It will cause all POAManagers to be deactivated, which in turn 1305 * will cause all POAs to be deactivated. 1306 */ 1307 protected void shutdownServants(boolean wait_for_completion) { 1308 Iterator iter = requestDispatcherRegistry.getObjectAdapterFactories().iterator() ; 1309 while (iter.hasNext()) { 1310 ObjectAdapterFactory oaf = (ObjectAdapterFactory)iter.next() ; 1311 oaf.shutdown( wait_for_completion ) ; 1312 } 1313 } 1314 1315 // REVISIT: was protected - made public for framework 1316 // Note that the caller must hold the ORBImpl lock. 1317 public void checkShutdownState() 1318 { 1319 if (status == STATUS_DESTROYED) { 1320 throw wrapper.orbDestroyed() ; 1321 } 1322 1323 if (status == STATUS_SHUTDOWN) { 1324 throw omgWrapper.badOperationAfterShutdown() ; 1325 } 1326 } 1327 1328 public boolean isDuringDispatch() 1329 { 1330 Boolean value = (Boolean)(isProcessingInvocation.get()) ; 1331 return value.booleanValue() ; 1332 } 1333 1334 public void startingDispatch() 1335 { 1336 synchronized (invocationObj) { 1337 isProcessingInvocation.set(Boolean.TRUE); 1338 } 1339 } 1340 1341 public void finishedDispatch() 1342 { 1343 synchronized (invocationObj) { 1344 isProcessingInvocation.set(Boolean.FALSE); 1345 } 1346 } 1347 1348 /** 1349 * formal/99-10-07 p 159: "If destroy is called on an ORB that has 1350 * not been shut down, it will start the shutdown process and block until 1351 * the ORB has shut down before it destroys the ORB." 1352 */ 1353 public synchronized void destroy() 1354 { 1355 boolean shutdownFirst = false ; 1356 1357 synchronized (this) { 1358 shutdownFirst = (status == STATUS_OPERATING) ; 1359 } 1360 1361 if (shutdownFirst) { 1362 shutdown(true); 1363 } 1364 1365 synchronized (this) { 1366 if (status < STATUS_DESTROYED) { 1367 getCorbaTransportManager().close(); 1368 getPIHandler().destroyInterceptors() ; 1369 status = STATUS_DESTROYED; 1370 } 1371 } 1372 1373 } 1374 1375 /** 1376 * Registers a value factory for a particular repository ID. 1377 * 1378 * @param repositoryID the repository ID. 1379 * @param factory the factory. 1380 * @return the previously registered factory for the given repository ID, 1381 * or null if no such factory was previously registered. 1382 * @exception org.omg.CORBA.BAD_PARAM if the registration fails. 1383 **/ 1384 public synchronized ValueFactory register_value_factory(String repositoryID, 1385 ValueFactory factory) 1386 { 1387 checkShutdownState(); 1388 1389 if ((repositoryID == null) || (factory == null)) 1390 throw omgWrapper.unableRegisterValueFactory() ; 1391 1392 return (ValueFactory)valueFactoryCache.put(repositoryID, factory); 1393 } 1394 1417 public synchronized ValueFactory lookup_value_factory(String repositoryID) 1418 { 1419 checkShutdownState(); 1420 1421 ValueFactory factory = 1422 (ValueFactory)valueFactoryCache.get(repositoryID); 1423 1424 if (factory == null) { 1425 try { 1426 factory = Utility.getFactory(null, null, null, repositoryID); 1427 } catch(org.omg.CORBA.MARSHAL ex) { 1428 throw wrapper.unableFindValueFactory( ex ) ; 1429 } 1430 } 1431 1432 return factory ; 1433 } 1434 1435 public OAInvocationInfo peekInvocationInfo() 1436 { 1437 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1438 return (OAInvocationInfo)(stack.peek()) ; 1439 } 1440 1441 public void pushInvocationInfo( OAInvocationInfo info ) 1442 { 1443 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1444 stack.push( info ) ; 1445 } 1446 1447 public OAInvocationInfo popInvocationInfo() 1448 { 1449 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1450 return (OAInvocationInfo)(stack.pop()) ; 1451 } 1452 1453 /** 1454 * The bad server id handler is used by the Locator to 1455 * send back the location of a persistant server to the client. 1456 */ 1457 1458 private Object badServerIdHandlerAccessLock = new Object(); 1459 1460 public void initBadServerIdHandler() 1461 { 1462 synchronized (badServerIdHandlerAccessLock) { 1463 Class cls = configData.getBadServerIdHandler() ; 1464 if (cls != null) { 1465 try { 1466 Class[] params = new Class[] { org.omg.CORBA.ORB.class }; 1467 java.lang.Object[] args = new java.lang.Object[]{this}; 1468 Constructor cons = cls.getConstructor(params); 1469 badServerIdHandler = 1470 (BadServerIdHandler) cons.newInstance(args); 1471 } catch (Exception e) { 1472 throw wrapper.errorInitBadserveridhandler( e ) ; 1473 } 1474 } 1475 } 1476 } 1477 1478 public void setBadServerIdHandler( BadServerIdHandler handler ) 1479 { 1480 synchronized (badServerIdHandlerAccessLock) { 1481 badServerIdHandler = handler; 1482 } 1483 } 1484 1485 public void handleBadServerId( ObjectKey okey ) 1486 { 1487 synchronized (badServerIdHandlerAccessLock) { 1488 if (badServerIdHandler == null) 1489 throw wrapper.badServerId() ; 1490 else 1491 badServerIdHandler.handle( okey ) ; 1492 } 1493 } 1494 1495 public synchronized org.omg.CORBA.Policy create_policy( int type, 1496 org.omg.CORBA.Any val ) throws org.omg.CORBA.PolicyError 1497 { 1498 checkShutdownState() ; 1499 1500 return pihandler.create_policy( type, val ) ; 1501 } 1502 1503 /** This is the implementation of the public API used to connect 1504 * a servant-skeleton to the ORB. 1505 */ 1506 public synchronized void connect(org.omg.CORBA.Object servant) 1515 } catch ( Exception ex ) { 1516 throw wrapper.orbConnectError( ex ) ; 1517 } 1518 } 1519 1520 public synchronized void disconnect(org.omg.CORBA.Object obj) 1521 { 1522 checkShutdownState(); 1523 if (getTOAFactory() == null) 1524 throw wrapper.noToa() ; 1525 1526 try { 1527 getTOAFactory().getTOA().disconnect( obj ) ; 1528 } catch ( Exception ex ) { 1529 throw wrapper.orbConnectError( ex ) ; 1530 } 1531 } 1532 1533 public int getTransientServerId() 1534 { 1535 if( configData.getORBServerIdPropertySpecified( ) ) { 1536 // ORBServerId is specified then use that value 1537 return configData.getPersistentServerId( ); 1538 } 1539 return transientServerId; 1540 } 1541 1542 public RequestDispatcherRegistry getRequestDispatcherRegistry() 1543 { 1544 return requestDispatcherRegistry; 1545 } 1546 1547 public ServiceContextRegistry getServiceContextRegistry() 1548 { 1549 return serviceContextRegistry ; 1550 } 1551 1552 // XXX All of the isLocalXXX checking needs to be revisited. 1553 // First of all, all three of these methods are called from 1554 // only one place in impl.ior.IORImpl. Second, we have problems 1555 // both with multi-homed hosts and with multi-profile IORs. 1556 // A possible strategy: like the LocalClientRequestDispatcher, we need 1557 // to determine this more abstractly at the ContactInfo level. 1558 // This level should probably just get the CorbaContactInfoList from 1559 // the IOR, then iterator over ContactInfo. If any ContactInfo is 1560 // local, the IOR is local, and we can pick one to create the 1561 // LocalClientRequestDispatcher as well. Bottom line: this code needs to move. 1562 1563 // XXX What about multi-homed host? 1564 public boolean isLocalHost( String hostName ) 1565 { 1566 return hostName.equals( configData.getORBServerHost() ) || 1567 hostName.equals( getLocalHostName() ) ; 1568 } 1569 1570 public boolean isLocalServerId( int subcontractId, int serverId ) 1571 { 1572 if ((subcontractId < ORBConstants.FIRST_POA_SCID) || 1573 (subcontractId > ORBConstants.MAX_POA_SCID)) 1574 return serverId == getTransientServerId( ) ; 1575 1576 // XXX isTransient info should be stored in subcontract registry 1577 if (ORBConstants.isTransient( subcontractId )) 1578 return (serverId == getTransientServerId()) ; 1579 else if (configData.getPersistentServerIdInitialized()) 1580 return (serverId == configData.getPersistentServerId()) ; 1581 else 1582 return false ; 1583 } 1584 1585 /************************************************************************* 1586 * The following public methods are for ORB shutdown. 1587 *************************************************************************/ 1588 1589 private String getHostName(String host) 1590 throws java.net.UnknownHostException 1591 { 1642 } 1643 1644 public synchronized void set_delegate(java.lang.Object servant){ 1645 checkShutdownState(); 1646 1647 POAFactory poaFactory = getPOAFactory() ; 1648 if (poaFactory != null) 1649 ((org.omg.PortableServer.Servant)servant) 1650 ._set_delegate( poaFactory.getDelegateImpl() ) ; 1651 else 1652 throw wrapper.noPoa() ; 1653 } 1654 1655 //////////////////////////////////////////////////// 1656 // 1657 // pept.broker.Broker 1658 // 1659 1660 public ClientInvocationInfo createOrIncrementInvocationInfo() 1661 { 1662 StackImpl invocationInfoStack = 1663 (StackImpl) clientInvocationInfoStack.get(); 1664 ClientInvocationInfo clientInvocationInfo = null; 1665 if (!invocationInfoStack.empty()) { 1666 clientInvocationInfo = 1667 (ClientInvocationInfo) invocationInfoStack.peek(); 1668 } 1669 if ((clientInvocationInfo == null) || 1670 (!clientInvocationInfo.isRetryInvocation())) 1671 { 1672 // This is a new call - not a retry. 1673 clientInvocationInfo = new CorbaInvocationInfo(this); 1674 startingDispatch(); 1675 invocationInfoStack.push(clientInvocationInfo); 1676 } 1677 // Reset retry so recursive calls will get a new info object. 1678 clientInvocationInfo.setIsRetryInvocation(false); 1679 clientInvocationInfo.incrementEntryCount(); 1680 return clientInvocationInfo; 1681 } 1682 1683 public void releaseOrDecrementInvocationInfo() 1684 { 1685 StackImpl invocationInfoStack = 1686 (StackImpl)clientInvocationInfoStack.get(); 1687 int entryCount = -1; 1688 ClientInvocationInfo clientInvocationInfo = null; 1689 if (!invocationInfoStack.empty()) { 1690 clientInvocationInfo = 1691 (ClientInvocationInfo)invocationInfoStack.peek(); 1692 } else { 1693 throw wrapper.invocationInfoStackEmpty() ; 1694 } 1695 clientInvocationInfo.decrementEntryCount(); 1696 entryCount = clientInvocationInfo.getEntryCount(); 1697 if (clientInvocationInfo.getEntryCount() == 0) { 1698 // 6763340: don't pop if this is a retry! 1699 if (!clientInvocationInfo.isRetryInvocation()) { 1700 invocationInfoStack.pop(); 1701 } 1702 finishedDispatch(); 1703 } 1704 } 1705 1706 public ClientInvocationInfo getInvocationInfo() 1707 { 1708 StackImpl invocationInfoStack = 1709 (StackImpl) clientInvocationInfoStack.get(); 1710 return (ClientInvocationInfo) invocationInfoStack.peek(); 1711 } 1712 1713 //////////////////////////////////////////////////// 1714 // 1715 // 1716 // 1717 1718 private Object clientDelegateFactoryAccessorLock = new Object(); 1719 1720 public void setClientDelegateFactory( ClientDelegateFactory factory ) 1721 { 1722 synchronized (clientDelegateFactoryAccessorLock) { 1723 clientDelegateFactory = factory ; 1724 } 1725 } 1726 1727 public ClientDelegateFactory getClientDelegateFactory() 1728 { 1729 synchronized (clientDelegateFactoryAccessorLock) { 1730 return clientDelegateFactory ; 1731 } 1732 } 1733 1734 private Object corbaContactInfoListFactoryAccessLock = new Object(); 1735 1736 public void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory ) 1737 { 1738 synchronized (corbaContactInfoListFactoryAccessLock) { 1739 corbaContactInfoListFactory = factory ; 1740 } 1741 } 1742 1743 public synchronized CorbaContactInfoListFactory getCorbaContactInfoListFactory() 1744 { 1745 return corbaContactInfoListFactory ; 1746 } 1747 1748 /** Set the resolver used in this ORB. This resolver will be used for list_initial_services 1749 * and resolve_initial_references. 1750 */ 1751 public void setResolver( Resolver resolver ) 1752 { 1753 synchronized (resolverLock) { 1754 this.resolver = resolver ; 1755 } 1756 } 1757 1758 /** Get the resolver used in this ORB. This resolver will be used for list_initial_services 1759 * and resolve_initial_references. 1760 */ 1761 public Resolver getResolver() 1762 { 1763 synchronized (resolverLock) { 1764 return resolver ; 1765 } 1766 } 1767 1768 /** Set the LocalResolver used in this ORB. This LocalResolver is used for 1769 * register_initial_reference only. 1770 */ 1771 public void setLocalResolver( LocalResolver resolver ) 1772 { 1773 synchronized (resolverLock) { 1774 this.localResolver = resolver ; 1775 } 1776 } 1777 1778 /** Get the LocalResolver used in this ORB. This LocalResolver is used for 1779 * register_initial_reference only. 1780 */ 1781 public LocalResolver getLocalResolver() 1782 { 1783 synchronized (resolverLock) { 1784 return localResolver ; 1785 } 1786 } 1787 1788 /** Set the operation used in string_to_object calls. The Operation must expect a 1789 * String and return an org.omg.CORBA.Object. 1790 */ 1791 public void setURLOperation( Operation stringToObject ) 1792 { 1793 synchronized (urlOperationLock) { 1794 urlOperation = stringToObject ; 1795 } 1796 } 1797 1798 /** Get the operation used in string_to_object calls. The Operation must expect a 1799 * String and return an org.omg.CORBA.Object. 1800 */ 1801 public Operation getURLOperation() 1802 { 1803 synchronized (urlOperationLock) { 1804 return urlOperation ; 1805 } 1806 } 1807 1808 public void setINSDelegate( CorbaServerRequestDispatcher sdel ) 1809 { 1810 synchronized (resolverLock) { 1811 insNamingDelegate = sdel ; 1812 } 1813 } 1814 1815 public TaggedComponentFactoryFinder getTaggedComponentFactoryFinder() 1816 { 1817 return taggedComponentFactoryFinder ; 1818 } 1819 1820 public IdentifiableFactoryFinder getTaggedProfileFactoryFinder() 1821 { 1822 return taggedProfileFactoryFinder ; 1823 } 1824 1825 public IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder() 1826 { 1827 return taggedProfileTemplateFactoryFinder ; 1828 } 1829 1830 private Object objectKeyFactoryAccessLock = new Object(); 1831 1832 public ObjectKeyFactory getObjectKeyFactory() 1833 { 1834 synchronized (objectKeyFactoryAccessLock) { 1835 return objectKeyFactory ; 1836 } 1837 } 1838 1839 public void setObjectKeyFactory( ObjectKeyFactory factory ) 1840 { 1841 synchronized (objectKeyFactoryAccessLock) { 1842 objectKeyFactory = factory ; 1843 } 1844 } 1845 1846 private Object transportManagerAccessorLock = new Object(); 1847 1848 public TransportManager getTransportManager() 1849 { 1850 synchronized (transportManagerAccessorLock) { 1851 if (transportManager == null) { 1852 transportManager = new CorbaTransportManagerImpl(this); 1853 } 1854 return transportManager; 1855 } 1856 } 1857 1858 public CorbaTransportManager getCorbaTransportManager() 1859 { 1860 return (CorbaTransportManager) getTransportManager(); 1861 } 1862 1863 private Object legacyServerSocketManagerAccessLock = new Object(); 1864 1865 public LegacyServerSocketManager getLegacyServerSocketManager() 1866 { 1867 synchronized (legacyServerSocketManagerAccessLock) { 1868 if (legacyServerSocketManager == null) { 1869 legacyServerSocketManager = new LegacyServerSocketManagerImpl(this); 1870 } 1871 return legacyServerSocketManager; 1872 } 1873 } 1874 1875 private Object threadPoolManagerAccessLock = new Object(); 1876 1877 public void setThreadPoolManager(ThreadPoolManager mgr) 1878 { 1879 synchronized (threadPoolManagerAccessLock) { 1880 threadpoolMgr = mgr; 1881 } 1882 } 1883 1884 public ThreadPoolManager getThreadPoolManager() 1885 { 1886 synchronized (threadPoolManagerAccessLock) { 1887 if (threadpoolMgr == null) { 1888 threadpoolMgr = new ThreadPoolManagerImpl( threadGroup ); 1889 } 1890 return threadpoolMgr; 1891 } 1892 } 1893 1894 public CopierManager getCopierManager() 1895 { 1896 return copierManager ; 1897 } 1898 } // Class ORBImpl 1899 1900 //////////////////////////////////////////////////////////////////////// 1901 /// Helper class for a Synchronization Variable 1902 //////////////////////////////////////////////////////////////////////// 1903 1904 class SynchVariable 1905 { 1906 // Synchronization Variable 1907 public boolean _flag; 1908 1909 // Constructor 1910 SynchVariable() 1911 { 1912 _flag = false; 1913 } 1914 1915 // set Flag to true | 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.impl.orb; 27 28 import java.applet.Applet; 29 30 import java.io.IOException; 31 32 import java.lang.reflect.Constructor; 33 import java.lang.reflect.Field; 34 import java.lang.reflect.Modifier; 35 import java.lang.reflect.InvocationTargetException; 36 37 import java.util.Set; 38 import java.util.HashSet; 39 import java.util.ArrayList; 40 import java.util.Iterator; 41 import java.util.Properties; 42 import java.util.Vector; 43 import java.util.Hashtable; 44 import java.util.Map; 45 import java.util.HashMap; 46 import java.util.LinkedList; 47 import java.util.Collection; 48 import java.util.Collections; 49 import java.util.StringTokenizer; 50 import java.util.Enumeration; 51 import java.util.WeakHashMap; 52 53 import java.net.InetAddress; 54 55 import java.security.PrivilegedAction; 56 import java.security.AccessController; 57 58 import javax.rmi.CORBA.Util; 59 import javax.rmi.CORBA.ValueHandler; 60 61 import org.omg.CORBA.Context; 62 import org.omg.CORBA.ContextList; 63 import org.omg.CORBA.Environment; 64 import org.omg.CORBA.ExceptionList; 65 import org.omg.CORBA.ORBPackage.InvalidName; 66 import org.omg.CORBA.NVList; 67 import org.omg.CORBA.TCKind; 68 import org.omg.CORBA.NamedValue; 69 import org.omg.CORBA.Request; 70 import org.omg.CORBA.SystemException; 71 import org.omg.CORBA.CompletionStatus; 72 import org.omg.CORBA.TypeCode; 73 import org.omg.CORBA.Any; 74 import org.omg.CORBA.StructMember; 75 import org.omg.CORBA.UnionMember; 76 import org.omg.CORBA.ValueMember; 77 import org.omg.CORBA.BAD_PARAM; 78 import org.omg.CORBA.MARSHAL; 79 80 import org.omg.CORBA.portable.ValueFactory; 81 82 import org.omg.CORBA.ORBPackage.InvalidName; 83 84 import com.sun.org.omg.SendingContext.CodeBase; 85 86 import com.sun.corba.se.pept.broker.Broker; 87 import com.sun.corba.se.pept.protocol.ClientInvocationInfo; 88 import com.sun.corba.se.pept.transport.ContactInfo; 89 import com.sun.corba.se.pept.transport.ConnectionCache; 90 import com.sun.corba.se.pept.transport.TransportManager; 91 92 import com.sun.corba.se.spi.ior.IOR; 93 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder; 94 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder; 95 import com.sun.corba.se.spi.ior.IORFactories; 96 import com.sun.corba.se.spi.ior.ObjectKey; 97 import com.sun.corba.se.spi.ior.ObjectKeyFactory; 98 import com.sun.corba.se.spi.ior.iiop.IIOPFactories; 99 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 100 import com.sun.corba.se.spi.oa.OAInvocationInfo; 101 import com.sun.corba.se.spi.oa.ObjectAdapterFactory; 102 import com.sun.corba.se.spi.orb.DataCollector; 103 import com.sun.corba.se.spi.orb.Operation; 104 import com.sun.corba.se.spi.orb.ORBData; 105 import com.sun.corba.se.spi.orb.ORBConfigurator; 106 import com.sun.corba.se.spi.orb.ParserImplBase; 107 import com.sun.corba.se.spi.orb.PropertyParser; 108 import com.sun.corba.se.spi.orb.OperationFactory; 109 import com.sun.corba.se.spi.orb.ORBVersion; 110 import com.sun.corba.se.spi.orb.ORBVersionFactory; 111 import com.sun.corba.se.spi.orbutil.closure.ClosureFactory; 112 import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager; 113 import com.sun.corba.se.spi.protocol.ClientDelegateFactory; 114 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 115 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher; 116 import com.sun.corba.se.spi.protocol.RequestDispatcherDefault; 117 import com.sun.corba.se.spi.protocol.PIHandler; 118 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 119 import com.sun.corba.se.spi.protocol.ForwardException; 120 import com.sun.corba.se.spi.resolver.Resolver; 121 import com.sun.corba.se.spi.resolver.LocalResolver; 122 import com.sun.corba.se.spi.orb.StringPair; 123 import com.sun.corba.se.spi.orb.StringPair; 124 import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory; 125 import com.sun.corba.se.spi.transport.CorbaTransportManager; 126 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager; 127 import com.sun.corba.se.spi.copyobject.CopierManager; 128 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults; 129 import com.sun.corba.se.spi.presentation.rmi.PresentationManager; 130 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 131 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry; 132 133 import com.sun.corba.se.impl.corba.TypeCodeFactory; 134 import com.sun.corba.se.impl.corba.TypeCodeImpl; 135 import com.sun.corba.se.impl.corba.NVListImpl; 136 import com.sun.corba.se.impl.corba.ExceptionListImpl; 137 import com.sun.corba.se.impl.corba.ContextListImpl; 138 import com.sun.corba.se.impl.corba.NamedValueImpl; 139 import com.sun.corba.se.impl.corba.EnvironmentImpl; 140 import com.sun.corba.se.impl.corba.AsynchInvoke; 141 import com.sun.corba.se.impl.corba.AnyImpl; 142 import com.sun.corba.se.impl.corba.RequestImpl; 143 import com.sun.corba.se.impl.dynamicany.DynAnyFactoryImpl; 144 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 145 import com.sun.corba.se.impl.encoding.CachedCodeBase; 146 import com.sun.corba.se.impl.interceptors.PIHandlerImpl; 147 import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl; 148 import com.sun.corba.se.impl.ior.TaggedComponentFactoryFinderImpl; 149 import com.sun.corba.se.impl.ior.TaggedProfileFactoryFinderImpl; 150 import com.sun.corba.se.impl.ior.TaggedProfileTemplateFactoryFinderImpl; 151 import com.sun.corba.se.impl.oa.toa.TOAFactory; 152 import com.sun.corba.se.impl.oa.poa.BadServerIdHandler; 153 import com.sun.corba.se.impl.oa.poa.DelegateImpl; 154 import com.sun.corba.se.impl.oa.poa.POAFactory; 155 import com.sun.corba.se.impl.orbutil.ORBClassLoader; 156 import com.sun.corba.se.impl.orbutil.ORBConstants; 157 import com.sun.corba.se.impl.orbutil.ORBUtility; 158 import com.sun.corba.se.impl.orbutil.StackImpl; 159 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl; 160 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolManagerImpl; 161 import com.sun.corba.se.impl.protocol.RequestDispatcherRegistryImpl; 162 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo; 163 import com.sun.corba.se.impl.transport.CorbaTransportManagerImpl; 164 import com.sun.corba.se.impl.legacy.connection.LegacyServerSocketManagerImpl; 165 import com.sun.corba.se.impl.util.Utility; 171 * The JavaIDL ORB implementation. 172 */ 173 public class ORBImpl extends com.sun.corba.se.spi.orb.ORB 174 { 175 protected TransportManager transportManager; 176 protected LegacyServerSocketManager legacyServerSocketManager; 177 178 private ThreadLocal OAInvocationInfoStack ; 179 180 private ThreadLocal clientInvocationInfoStack ; 181 182 // pure java orb, caching the servant IOR per ORB 183 private static IOR codeBaseIOR ; 184 185 // Vector holding deferred Requests 186 private Vector dynamicRequests ; 187 private SynchVariable svResponseReceived ; 188 189 private java.lang.Object runObj = new java.lang.Object(); 190 private java.lang.Object shutdownObj = new java.lang.Object(); 191 private java.lang.Object waitForCompletionObj = new java.lang.Object(); 192 private static final byte STATUS_OPERATING = 1; 193 private static final byte STATUS_SHUTTING_DOWN = 2; 194 private static final byte STATUS_SHUTDOWN = 3; 195 private static final byte STATUS_DESTROYED = 4; 196 private byte status = STATUS_OPERATING; 197 198 // XXX Should we move invocation tracking to the first level server dispatcher? 199 private java.lang.Object invocationObj = new java.lang.Object(); 200 private int numInvocations = 0; 201 202 // thread local variable to store a boolean to detect deadlock in 203 // ORB.shutdown(true). 204 private ThreadLocal isProcessingInvocation = new ThreadLocal () { 205 protected java.lang.Object initialValue() { 206 return Boolean.FALSE; 207 } 208 }; 209 210 // This map is caching TypeCodes created for a certain class (key) 211 // and is used in Util.writeAny() 212 private Map typeCodeForClassMap ; 213 214 // Cache to hold ValueFactories (Helper classes) keyed on repository ids 215 private Hashtable valueFactoryCache = new Hashtable(); 216 217 // thread local variable to store the current ORB version. 218 // default ORB version is the version of ORB with correct Rep-id 219 // changes 220 private ThreadLocal orbVersionThreadLocal ; 221 222 private RequestDispatcherRegistry requestDispatcherRegistry ; 223 224 private CopierManager copierManager ; 225 226 private int transientServerId ; 227 228 private ServiceContextRegistry serviceContextRegistry ; 229 230 // Needed here to implement connect/disconnect 231 private TOAFactory toaFactory ; 232 233 // Needed here for set_delegate 234 private POAFactory poaFactory ; 235 236 // The interceptor handler, which provides portable interceptor services for 237 // subcontracts and object adapters. 238 private PIHandler pihandler ; 239 240 private ORBData configData ; 241 242 private BadServerIdHandler badServerIdHandler ; 243 244 private ClientDelegateFactory clientDelegateFactory ; 245 246 private CorbaContactInfoListFactory corbaContactInfoListFactory ; 247 251 // Note that we now have separate locks for each resolver type. This is due 252 // to bug 6980681 and 6238477, which was caused by a deadlock while resolving a 253 // corbaname: URL that contained a reference to the same ORB as the 254 // ORB making the call to string_to_object. This caused a deadlock between the 255 // client thread holding the single lock for access to the urlOperation, 256 // and the server thread handling the client is_a request waiting on the 257 // same lock to access the localResolver. 258 259 260 // Used for resolver_initial_references and list_initial_services 261 private Resolver resolver ; 262 263 // Used for register_initial_references 264 private LocalResolver localResolver ; 265 266 // Converts strings to object references for resolvers and string_to_object 267 private Operation urlOperation ; 268 private final Object urlOperationLock = new java.lang.Object() ; 269 270 private CorbaServerRequestDispatcher insNamingDelegate ; 271 272 // resolverLock must be used for all access to either resolver or 273 // localResolver, since it is possible for the resolver to indirectly 274 // refer to the localResolver. Also used to protect access to 275 // insNamingDelegate. 276 private final Object resolverLock = new Object() ; 277 278 private TaggedComponentFactoryFinder taggedComponentFactoryFinder ; 279 280 private IdentifiableFactoryFinder taggedProfileFactoryFinder ; 281 282 private IdentifiableFactoryFinder taggedProfileTemplateFactoryFinder ; 283 284 private ObjectKeyFactory objectKeyFactory ; 285 286 private boolean orbOwnsThreadPoolManager = false ; 287 288 private ThreadPoolManager threadpoolMgr; 289 290 private void dprint( String msg ) 291 { 292 ORBUtility.dprint( this, msg ) ; 293 } 294 295 //////////////////////////////////////////////////// 296 // 297 // NOTE: 298 // 299 // Methods that are synchronized MUST stay synchronized. 300 // 301 // Methods that are NOT synchronized must stay that way to avoid deadlock. 302 // 303 // 304 // REVISIT: 305 // 306 // checkShutDownState - lock on different object - and normalize usage. 307 // starting/FinishDispatch and Shutdown 311 { 312 return configData ; 313 } 314 315 public PIHandler getPIHandler() 316 { 317 return pihandler ; 318 } 319 320 /** 321 * Create a new ORB. Should be followed by the appropriate 322 * set_parameters() call. 323 */ 324 public ORBImpl() 325 { 326 // All initialization is done through set_parameters(). 327 } 328 329 public ORBVersion getORBVersion() 330 { 331 synchronized (this) { 332 checkShutdownState(); 333 } 334 return (ORBVersion)(orbVersionThreadLocal.get()) ; 335 } 336 337 public void setORBVersion(ORBVersion verObj) 338 { 339 synchronized (this) { 340 checkShutdownState(); 341 } 342 orbVersionThreadLocal.set(verObj); 343 } 344 345 /**************************************************************************** 346 * The following methods are ORB initialization 347 ****************************************************************************/ 348 349 // preInit initializes all non-pluggable ORB data that is independent 350 // of the property parsing. 351 private void preInit( String[] params, Properties props ) 352 { 353 // Before ORBConfiguration we need to set a PINoOpHandlerImpl, 354 // because PersisentServer Initialization inside configurator will 355 // invoke orb.resolve_initial_references( ) which will result in a 356 // check on piHandler to invoke Interceptors. We do not want any 357 // Interceptors to be invoked before the complete ORB initialization. 358 // piHandler will be replaced by a real PIHandler implementation at the 359 // end of this method. 360 pihandler = new PINoOpHandlerImpl( ); 361 362 // This is the unique id of this server (JVM). Multiple incarnations 363 // of this server will get different ids. 364 // Compute transientServerId = milliseconds since Jan 1, 1970 365 // Note: transientServerId will wrap in about 2^32 / 86400000 = 49.7 days. 366 // If two ORBS are started at the same time then there is a possibility 367 // of having the same transientServerId. This may result in collision 368 // and may be a problem in ior.isLocal() check to see if the object 369 // belongs to the current ORB. This problem is taken care of by checking 370 // to see if the IOR port matches ORB server port in legacyIsLocalServerPort() 371 // method. 372 // 373 // XXX need to move server ID to a string for CORBA 3.0. At that point, 374 // make this more unique (possibly use java.rmi.server.UID). 375 transientServerId = (int)System.currentTimeMillis(); 376 377 orbVersionThreadLocal = new ThreadLocal () { 378 protected java.lang.Object initialValue() { 379 // set default to version of the ORB with correct Rep-ids 380 return ORBVersionFactory.getORBVersion() ; 381 } 502 if (poaFactory == null) { 503 poaFactory = (POAFactory)requestDispatcherRegistry.getObjectAdapterFactory( 504 ORBConstants.TRANSIENT_SCID ) ; 505 } 506 507 return poaFactory ; 508 } 509 510 private synchronized TOAFactory getTOAFactory() 511 { 512 if (toaFactory == null) { 513 toaFactory = (TOAFactory)requestDispatcherRegistry.getObjectAdapterFactory( 514 ORBConstants.TOA_SCID ) ; 515 } 516 517 return toaFactory ; 518 } 519 520 public void set_parameters( Properties props ) 521 { 522 synchronized (this) { 523 checkShutdownState(); 524 } 525 preInit( null, props ) ; 526 DataCollector dataCollector = 527 DataCollectorFactory.create( props, getLocalHostName() ) ; 528 postInit( null, dataCollector ) ; 529 } 530 531 protected void set_parameters(Applet app, Properties props) 532 { 533 preInit( null, props ) ; 534 DataCollector dataCollector = 535 DataCollectorFactory.create( app, props, getLocalHostName() ) ; 536 postInit( null, dataCollector ) ; 537 } 538 539 protected void set_parameters (String[] params, Properties props) 540 { 541 preInit( params, props ) ; 542 DataCollector dataCollector = 543 DataCollectorFactory.create( params, props, getLocalHostName() ) ; 544 postInit( params, dataCollector ) ; 746 // wait for a response 747 synchronized(this.svResponseReceived) { 748 while (!this.svResponseReceived.value()) { 749 try { 750 this.svResponseReceived.wait(); 751 } catch(java.lang.InterruptedException ex) { 752 // NO-OP 753 } 754 } 755 // reinitialize the response flag 756 this.svResponseReceived.reset(); 757 } 758 } 759 } 760 761 /** 762 * Notify response to ORB for get_next_response 763 */ 764 public void notifyORB() 765 { 766 synchronized (this) { 767 checkShutdownState(); 768 } 769 synchronized (this.svResponseReceived) { 770 this.svResponseReceived.set(); 771 this.svResponseReceived.notify(); 772 } 773 } 774 775 /** 776 * Convert an object ref to a string. 777 * @param obj The object to stringify. 778 * @return A stringified object reference. 779 */ 780 public synchronized String object_to_string(org.omg.CORBA.Object obj) 781 { 782 checkShutdownState(); 783 784 // Handle the null objref case 785 if (obj == null) { 786 IOR nullIOR = IORFactories.makeIOR( this ) ; 787 return nullIOR.stringify(); 788 } 815 Operation op ; 816 817 synchronized (this) { 818 checkShutdownState(); 819 op = urlOperation ; 820 } 821 822 if (str == null) 823 throw wrapper.nullParam() ; 824 825 synchronized (urlOperationLock) { 826 org.omg.CORBA.Object obj = (org.omg.CORBA.Object)op.operate( str ) ; 827 return obj ; 828 } 829 } 830 831 // pure java orb support, moved this method from FVDCodeBaseImpl. 832 // Note that we connect this if we have not already done so. 833 public synchronized IOR getFVDCodeBaseIOR() 834 { 835 checkShutdownState(); 836 837 if (codeBaseIOR != null) // i.e. We are already connected to it 838 return codeBaseIOR; 839 840 // backward compatability 4365188 841 CodeBase cb; 842 843 ValueHandler vh = ORBUtility.createValueHandler(this); 844 845 cb = (CodeBase)vh.getRunTimeCodeBase(); 846 return ORBUtility.connectAndGetIOR( this, cb ) ; 847 } 848 849 /** 850 * Get the TypeCode for a primitive type. 851 * 852 * @param tcKind the integer kind for the primitive type 853 * @return the requested TypeCode 854 */ 855 public synchronized TypeCode get_primitive_tc(TCKind tcKind) 856 { 1081 1082 /** 1083 * Create a new Any 1084 * 1085 * @return the new Any created. 1086 */ 1087 public synchronized Any create_any() 1088 { 1089 checkShutdownState(); 1090 return new AnyImpl(this); 1091 } 1092 1093 // TypeCodeFactory interface methods. 1094 // Keeping track of type codes by repository id. 1095 1096 // Keeping a cache of TypeCodes associated with the class 1097 // they got created from in Util.writeAny(). 1098 1099 public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci) 1100 { 1101 checkShutdownState(); 1102 1103 if (typeCodeForClassMap == null) 1104 typeCodeForClassMap = Collections.synchronizedMap( 1105 new WeakHashMap(64)); 1106 // Store only one TypeCode per class. 1107 if ( ! typeCodeForClassMap.containsKey(c)) 1108 typeCodeForClassMap.put(c, tci); 1109 } 1110 1111 public synchronized TypeCodeImpl getTypeCodeForClass(Class c) 1112 { 1113 checkShutdownState(); 1114 1115 if (typeCodeForClassMap == null) 1116 return null; 1117 return (TypeCodeImpl)typeCodeForClassMap.get(c); 1118 } 1119 1120 /**************************************************************************** 1121 * The following methods deal with listing and resolving the initial 1122 * (bootstrap) object references such as "NameService". 1123 ****************************************************************************/ 1124 1125 /** 1126 * Get a list of the initially available CORBA services. 1127 * This does not work unless an ORBInitialHost is specified during 1128 * initialization (or unless there is an ORB running on the AppletHost) 1129 * since the localhostname 1130 * is inaccessible to applets. If a service properties URL was specified, 1131 * then it is used, otherwise the bootstrapping protocol is used. 1132 * @return A list of the initial services available. 1133 */ 1134 public String[] list_initial_services() 1177 } 1178 1179 /** 1180 * If this operation is called with an id, <code>"Y"</code>, and an 1181 * object, <code>YY</code>, then a subsequent call to 1182 * <code>ORB.resolve_initial_references( "Y" )</code> will 1183 * return object <code>YY</code>. 1184 * 1185 * @param id The ID by which the initial reference will be known. 1186 * @param obj The initial reference itself. 1187 * @throws InvalidName if this operation is called with an empty string id 1188 * or this operation is called with an id that is already registered, 1189 * including the default names defined by OMG. 1190 * @throws BAD_PARAM if the obj parameter is null. 1191 */ 1192 public void register_initial_reference( 1193 String id, org.omg.CORBA.Object obj ) throws InvalidName 1194 { 1195 CorbaServerRequestDispatcher insnd ; 1196 1197 synchronized (this) { 1198 checkShutdownState(); 1199 } 1200 1201 if ((id == null) || (id.length() == 0)) 1202 throw new InvalidName() ; 1203 1204 synchronized (this) { 1205 checkShutdownState(); 1206 } 1207 1208 synchronized (resolverLock) { 1209 insnd = insNamingDelegate ; 1210 1211 java.lang.Object obj2 = localResolver.resolve( id ) ; 1212 if (obj2 != null) 1213 throw new InvalidName(id + " already registered") ; 1214 1215 localResolver.register( id, ClosureFactory.makeConstant( obj )) ; 1216 } 1217 1218 synchronized (this) { 1219 if (StubAdapter.isStub(obj)) 1220 // Make all remote object references available for INS. 1224 } 1225 1226 /**************************************************************************** 1227 * The following methods (introduced in POA / CORBA2.1) deal with 1228 * shutdown / single threading. 1229 ****************************************************************************/ 1230 1231 public void run() 1232 { 1233 synchronized (this) { 1234 checkShutdownState(); 1235 } 1236 1237 synchronized (runObj) { 1238 try { 1239 runObj.wait(); 1240 } catch ( InterruptedException ex ) {} 1241 } 1242 } 1243 1244 public void shutdown(boolean wait_for_completion) { 1245 boolean wait = false; 1246 1247 synchronized (this) { 1248 checkShutdownState(); 1249 1250 // This is to avoid deadlock: don't allow a thread that is 1251 // processing a request to call shutdown( true ), because 1252 // the shutdown would block waiting for the request to complete, 1253 // while the request would block waiting for shutdown to complete. 1254 if (wait_for_completion && 1255 isProcessingInvocation.get() == Boolean.TRUE) { 1256 throw omgWrapper.shutdownWaitForCompletionDeadlock(); 1257 } 1258 1259 if (status == STATUS_SHUTTING_DOWN) { 1260 if (wait_for_completion) { 1261 wait = true; 1262 } else { 1263 return; 1264 } 1265 } 1266 1267 status = STATUS_SHUTTING_DOWN; 1268 } 1269 1270 // Avoid more than one thread performing shutdown at a time. 1271 synchronized (shutdownObj) { 1272 // At this point, the ORB status is certainly STATUS_SHUTTING_DOWN. 1273 // If wait is true, another thread already called shutdown( true ), 1274 // and so we wait for completion 1275 if (wait) { 1276 while (true) { 1277 synchronized (this) { 1278 if (status == STATUS_SHUTDOWN) 1279 break; 1280 } 1281 1282 try { 1283 shutdownObj.wait(); 1284 } catch (InterruptedException exc) { 1285 // NOP: just loop and wait until state is changed 1286 } 1287 } 1288 } else { 1289 // perform the actual shutdown 1290 shutdownServants(wait_for_completion); 1291 1292 if (wait_for_completion) { 1293 synchronized ( waitForCompletionObj ) { 1294 while (numInvocations > 0) { 1295 try { 1296 waitForCompletionObj.wait(); 1297 } catch (InterruptedException ex) {} 1298 } 1299 } 1300 } 1301 1302 synchronized (runObj) { 1303 runObj.notifyAll(); 1304 } 1305 1306 status = STATUS_SHUTDOWN; 1307 1308 shutdownObj.notifyAll(); 1309 } 1310 } 1311 } 1312 1313 // Cause all ObjectAdapaterFactories to clean up all of their internal state, which 1314 // may include activated objects that have associated state and callbacks that must 1315 // complete in order to shutdown. This will cause new request to be rejected. 1316 protected void shutdownServants(boolean wait_for_completion) { 1317 Set<ObjectAdapterFactory> oaset; 1318 synchronized (this) { 1319 oaset = new HashSet<>(requestDispatcherRegistry.getObjectAdapterFactories()); 1320 } 1321 1322 for (ObjectAdapterFactory oaf : oaset) 1323 oaf.shutdown(wait_for_completion); 1324 } 1325 1326 // Note that the caller must hold the ORBImpl lock. 1327 public void checkShutdownState() 1328 { 1329 if (status == STATUS_DESTROYED) { 1330 throw wrapper.orbDestroyed() ; 1331 } 1332 1333 if (status == STATUS_SHUTDOWN) { 1334 throw omgWrapper.badOperationAfterShutdown() ; 1335 } 1336 } 1337 1338 public boolean isDuringDispatch() 1339 { 1340 synchronized (this) { 1341 checkShutdownState(); 1342 } 1343 Boolean value = (Boolean)(isProcessingInvocation.get()) ; 1344 return value.booleanValue() ; 1345 } 1346 1347 public void startingDispatch() 1348 { 1349 synchronized (this) { 1350 checkShutdownState(); 1351 } 1352 synchronized (invocationObj) { 1353 isProcessingInvocation.set(Boolean.TRUE); 1354 numInvocations++; 1355 } 1356 } 1357 1358 public void finishedDispatch() 1359 { 1360 synchronized (this) { 1361 checkShutdownState(); 1362 } 1363 synchronized (invocationObj) { 1364 numInvocations--; 1365 isProcessingInvocation.set(false); 1366 if (numInvocations == 0) { 1367 synchronized (waitForCompletionObj) { 1368 waitForCompletionObj.notifyAll(); 1369 } 1370 } else if (numInvocations < 0) { 1371 throw wrapper.numInvocationsAlreadyZero( 1372 CompletionStatus.COMPLETED_YES); 1373 } 1374 } 1375 } 1376 1377 /** 1378 * formal/99-10-07 p 159: "If destroy is called on an ORB that has 1379 * not been shut down, it will start the shutdown process and block until 1380 * the ORB has shut down before it destroys the ORB." 1381 */ 1382 public void destroy() 1383 { 1384 boolean shutdownFirst = false; 1385 1386 synchronized (this) { 1387 shutdownFirst = (status == STATUS_OPERATING); 1388 } 1389 1390 if (shutdownFirst) { 1391 shutdown(true); 1392 } 1393 1394 synchronized (this) { 1395 if (status < STATUS_DESTROYED) { 1396 getCorbaTransportManager().close(); 1397 getPIHandler().destroyInterceptors(); 1398 status = STATUS_DESTROYED; 1399 } 1400 } 1401 synchronized (threadPoolManagerAccessLock) { 1402 if (orbOwnsThreadPoolManager) { 1403 try { 1404 threadpoolMgr.close(); 1405 threadpoolMgr = null; 1406 } catch (IOException exc) { 1407 wrapper.ioExceptionOnClose(exc); 1408 } 1409 } 1410 } 1411 1412 try { 1413 monitoringManager.close(); 1414 monitoringManager = null; 1415 } catch (IOException exc) { 1416 wrapper.ioExceptionOnClose(exc); 1417 } 1418 1419 CachedCodeBase.cleanCache(this); 1420 try { 1421 pihandler.close(); 1422 } catch (IOException exc) { 1423 wrapper.ioExceptionOnClose(exc); 1424 } 1425 1426 super.destroy(); 1427 1428 badServerIdHandlerAccessLock = null; 1429 clientDelegateFactoryAccessorLock = null; 1430 corbaContactInfoListFactoryAccessLock = null; 1431 1432 objectKeyFactoryAccessLock = null; 1433 legacyServerSocketManagerAccessLock = null; 1434 threadPoolManagerAccessLock = null; 1435 transportManager = null; 1436 legacyServerSocketManager = null; 1437 OAInvocationInfoStack = null; 1438 clientInvocationInfoStack = null; 1439 codeBaseIOR = null; 1440 dynamicRequests = null; 1441 svResponseReceived = null; 1442 runObj = null; 1443 shutdownObj = null; 1444 waitForCompletionObj = null; 1445 invocationObj = null; 1446 isProcessingInvocation = null; 1447 typeCodeForClassMap = null; 1448 valueFactoryCache = null; 1449 orbVersionThreadLocal = null; 1450 requestDispatcherRegistry = null; 1451 copierManager = null; 1452 toaFactory = null; 1453 poaFactory = null; 1454 pihandler = null; 1455 configData = null; 1456 badServerIdHandler = null; 1457 clientDelegateFactory = null; 1458 corbaContactInfoListFactory = null; 1459 resolver = null; 1460 localResolver = null; 1461 insNamingDelegate = null; 1462 urlOperation = null; 1463 taggedComponentFactoryFinder = null; 1464 taggedProfileFactoryFinder = null; 1465 taggedProfileTemplateFactoryFinder = null; 1466 objectKeyFactory = null; 1467 } 1468 1469 /** 1470 * Registers a value factory for a particular repository ID. 1471 * 1472 * @param repositoryID the repository ID. 1473 * @param factory the factory. 1474 * @return the previously registered factory for the given repository ID, 1475 * or null if no such factory was previously registered. 1476 * @exception org.omg.CORBA.BAD_PARAM if the registration fails. 1477 **/ 1478 public synchronized ValueFactory register_value_factory(String repositoryID, 1479 ValueFactory factory) 1480 { 1481 checkShutdownState(); 1482 1483 if ((repositoryID == null) || (factory == null)) 1484 throw omgWrapper.unableRegisterValueFactory() ; 1485 1486 return (ValueFactory)valueFactoryCache.put(repositoryID, factory); 1487 } 1488 1511 public synchronized ValueFactory lookup_value_factory(String repositoryID) 1512 { 1513 checkShutdownState(); 1514 1515 ValueFactory factory = 1516 (ValueFactory)valueFactoryCache.get(repositoryID); 1517 1518 if (factory == null) { 1519 try { 1520 factory = Utility.getFactory(null, null, null, repositoryID); 1521 } catch(org.omg.CORBA.MARSHAL ex) { 1522 throw wrapper.unableFindValueFactory( ex ) ; 1523 } 1524 } 1525 1526 return factory ; 1527 } 1528 1529 public OAInvocationInfo peekInvocationInfo() 1530 { 1531 synchronized (this) { 1532 checkShutdownState(); 1533 } 1534 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1535 return (OAInvocationInfo)(stack.peek()) ; 1536 } 1537 1538 public void pushInvocationInfo( OAInvocationInfo info ) 1539 { 1540 synchronized (this) { 1541 checkShutdownState(); 1542 } 1543 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1544 stack.push( info ) ; 1545 } 1546 1547 public OAInvocationInfo popInvocationInfo() 1548 { 1549 synchronized (this) { 1550 checkShutdownState(); 1551 } 1552 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1553 return (OAInvocationInfo)(stack.pop()) ; 1554 } 1555 1556 /** 1557 * The bad server id handler is used by the Locator to 1558 * send back the location of a persistant server to the client. 1559 */ 1560 1561 private Object badServerIdHandlerAccessLock = new Object(); 1562 1563 public void initBadServerIdHandler() 1564 { 1565 synchronized (this) { 1566 checkShutdownState(); 1567 } 1568 synchronized (badServerIdHandlerAccessLock) { 1569 Class cls = configData.getBadServerIdHandler() ; 1570 if (cls != null) { 1571 try { 1572 Class[] params = new Class[] { org.omg.CORBA.ORB.class }; 1573 java.lang.Object[] args = new java.lang.Object[]{this}; 1574 Constructor cons = cls.getConstructor(params); 1575 badServerIdHandler = 1576 (BadServerIdHandler) cons.newInstance(args); 1577 } catch (Exception e) { 1578 throw wrapper.errorInitBadserveridhandler( e ) ; 1579 } 1580 } 1581 } 1582 } 1583 1584 public void setBadServerIdHandler( BadServerIdHandler handler ) 1585 { 1586 synchronized (this) { 1587 checkShutdownState(); 1588 } 1589 synchronized (badServerIdHandlerAccessLock) { 1590 badServerIdHandler = handler; 1591 } 1592 } 1593 1594 public void handleBadServerId( ObjectKey okey ) 1595 { 1596 synchronized (this) { 1597 checkShutdownState(); 1598 } 1599 synchronized (badServerIdHandlerAccessLock) { 1600 if (badServerIdHandler == null) 1601 throw wrapper.badServerId() ; 1602 else 1603 badServerIdHandler.handle( okey ) ; 1604 } 1605 } 1606 1607 public synchronized org.omg.CORBA.Policy create_policy( int type, 1608 org.omg.CORBA.Any val ) throws org.omg.CORBA.PolicyError 1609 { 1610 checkShutdownState() ; 1611 1612 return pihandler.create_policy( type, val ) ; 1613 } 1614 1615 /** This is the implementation of the public API used to connect 1616 * a servant-skeleton to the ORB. 1617 */ 1618 public synchronized void connect(org.omg.CORBA.Object servant) 1627 } catch ( Exception ex ) { 1628 throw wrapper.orbConnectError( ex ) ; 1629 } 1630 } 1631 1632 public synchronized void disconnect(org.omg.CORBA.Object obj) 1633 { 1634 checkShutdownState(); 1635 if (getTOAFactory() == null) 1636 throw wrapper.noToa() ; 1637 1638 try { 1639 getTOAFactory().getTOA().disconnect( obj ) ; 1640 } catch ( Exception ex ) { 1641 throw wrapper.orbConnectError( ex ) ; 1642 } 1643 } 1644 1645 public int getTransientServerId() 1646 { 1647 synchronized (this) { 1648 checkShutdownState(); 1649 } 1650 if( configData.getORBServerIdPropertySpecified( ) ) { 1651 // ORBServerId is specified then use that value 1652 return configData.getPersistentServerId( ); 1653 } 1654 return transientServerId; 1655 } 1656 1657 public RequestDispatcherRegistry getRequestDispatcherRegistry() 1658 { 1659 synchronized (this) { 1660 checkShutdownState(); 1661 } 1662 return requestDispatcherRegistry; 1663 } 1664 1665 public ServiceContextRegistry getServiceContextRegistry() 1666 { 1667 synchronized (this) { 1668 checkShutdownState(); 1669 } 1670 return serviceContextRegistry ; 1671 } 1672 1673 // XXX All of the isLocalXXX checking needs to be revisited. 1674 // First of all, all three of these methods are called from 1675 // only one place in impl.ior.IORImpl. Second, we have problems 1676 // both with multi-homed hosts and with multi-profile IORs. 1677 // A possible strategy: like the LocalClientRequestDispatcher, we need 1678 // to determine this more abstractly at the ContactInfo level. 1679 // This level should probably just get the CorbaContactInfoList from 1680 // the IOR, then iterator over ContactInfo. If any ContactInfo is 1681 // local, the IOR is local, and we can pick one to create the 1682 // LocalClientRequestDispatcher as well. Bottom line: this code needs to move. 1683 1684 // XXX What about multi-homed host? 1685 public boolean isLocalHost( String hostName ) 1686 { 1687 synchronized (this) { 1688 checkShutdownState(); 1689 } 1690 return hostName.equals( configData.getORBServerHost() ) || 1691 hostName.equals( getLocalHostName() ) ; 1692 } 1693 1694 public boolean isLocalServerId( int subcontractId, int serverId ) 1695 { 1696 synchronized (this) { 1697 checkShutdownState(); 1698 } 1699 if ((subcontractId < ORBConstants.FIRST_POA_SCID) || 1700 (subcontractId > ORBConstants.MAX_POA_SCID)) 1701 return serverId == getTransientServerId( ) ; 1702 1703 // XXX isTransient info should be stored in subcontract registry 1704 if (ORBConstants.isTransient( subcontractId )) 1705 return (serverId == getTransientServerId()) ; 1706 else if (configData.getPersistentServerIdInitialized()) 1707 return (serverId == configData.getPersistentServerId()) ; 1708 else 1709 return false ; 1710 } 1711 1712 /************************************************************************* 1713 * The following public methods are for ORB shutdown. 1714 *************************************************************************/ 1715 1716 private String getHostName(String host) 1717 throws java.net.UnknownHostException 1718 { 1769 } 1770 1771 public synchronized void set_delegate(java.lang.Object servant){ 1772 checkShutdownState(); 1773 1774 POAFactory poaFactory = getPOAFactory() ; 1775 if (poaFactory != null) 1776 ((org.omg.PortableServer.Servant)servant) 1777 ._set_delegate( poaFactory.getDelegateImpl() ) ; 1778 else 1779 throw wrapper.noPoa() ; 1780 } 1781 1782 //////////////////////////////////////////////////// 1783 // 1784 // pept.broker.Broker 1785 // 1786 1787 public ClientInvocationInfo createOrIncrementInvocationInfo() 1788 { 1789 synchronized (this) { 1790 checkShutdownState(); 1791 } 1792 StackImpl invocationInfoStack = 1793 (StackImpl) clientInvocationInfoStack.get(); 1794 ClientInvocationInfo clientInvocationInfo = null; 1795 if (!invocationInfoStack.empty()) { 1796 clientInvocationInfo = 1797 (ClientInvocationInfo) invocationInfoStack.peek(); 1798 } 1799 if ((clientInvocationInfo == null) || 1800 (!clientInvocationInfo.isRetryInvocation())) 1801 { 1802 // This is a new call - not a retry. 1803 clientInvocationInfo = new CorbaInvocationInfo(this); 1804 startingDispatch(); 1805 invocationInfoStack.push(clientInvocationInfo); 1806 } 1807 // Reset retry so recursive calls will get a new info object. 1808 clientInvocationInfo.setIsRetryInvocation(false); 1809 clientInvocationInfo.incrementEntryCount(); 1810 return clientInvocationInfo; 1811 } 1812 1813 public void releaseOrDecrementInvocationInfo() 1814 { 1815 synchronized (this) { 1816 checkShutdownState(); 1817 } 1818 int entryCount = -1; 1819 ClientInvocationInfo clientInvocationInfo = null; 1820 StackImpl invocationInfoStack = 1821 (StackImpl)clientInvocationInfoStack.get(); 1822 if (!invocationInfoStack.empty()) { 1823 clientInvocationInfo = 1824 (ClientInvocationInfo)invocationInfoStack.peek(); 1825 } else { 1826 throw wrapper.invocationInfoStackEmpty() ; 1827 } 1828 clientInvocationInfo.decrementEntryCount(); 1829 entryCount = clientInvocationInfo.getEntryCount(); 1830 if (clientInvocationInfo.getEntryCount() == 0) { 1831 // 6763340: don't pop if this is a retry! 1832 if (!clientInvocationInfo.isRetryInvocation()) { 1833 invocationInfoStack.pop(); 1834 } 1835 finishedDispatch(); 1836 } 1837 } 1838 1839 public ClientInvocationInfo getInvocationInfo() 1840 { 1841 synchronized (this) { 1842 checkShutdownState(); 1843 } 1844 StackImpl invocationInfoStack = 1845 (StackImpl) clientInvocationInfoStack.get(); 1846 return (ClientInvocationInfo) invocationInfoStack.peek(); 1847 } 1848 1849 //////////////////////////////////////////////////// 1850 // 1851 // 1852 // 1853 1854 private Object clientDelegateFactoryAccessorLock = new Object(); 1855 1856 public void setClientDelegateFactory( ClientDelegateFactory factory ) 1857 { 1858 synchronized (this) { 1859 checkShutdownState(); 1860 } 1861 synchronized (clientDelegateFactoryAccessorLock) { 1862 clientDelegateFactory = factory ; 1863 } 1864 } 1865 1866 public ClientDelegateFactory getClientDelegateFactory() 1867 { 1868 synchronized (this) { 1869 checkShutdownState(); 1870 } 1871 synchronized (clientDelegateFactoryAccessorLock) { 1872 return clientDelegateFactory ; 1873 } 1874 } 1875 1876 private Object corbaContactInfoListFactoryAccessLock = new Object(); 1877 1878 public void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory ) 1879 { 1880 synchronized (this) { 1881 checkShutdownState(); 1882 } 1883 synchronized (corbaContactInfoListFactoryAccessLock) { 1884 corbaContactInfoListFactory = factory ; 1885 } 1886 } 1887 1888 public synchronized CorbaContactInfoListFactory getCorbaContactInfoListFactory() 1889 { 1890 checkShutdownState(); 1891 return corbaContactInfoListFactory ; 1892 } 1893 1894 /** Set the resolver used in this ORB. This resolver will be used for list_initial_services 1895 * and resolve_initial_references. 1896 */ 1897 public void setResolver( Resolver resolver ) 1898 { 1899 synchronized (this) { 1900 checkShutdownState(); 1901 } 1902 synchronized (resolverLock) { 1903 this.resolver = resolver ; 1904 } 1905 } 1906 1907 /** Get the resolver used in this ORB. This resolver will be used for list_initial_services 1908 * and resolve_initial_references. 1909 */ 1910 public Resolver getResolver() 1911 { 1912 synchronized (this) { 1913 checkShutdownState(); 1914 } 1915 synchronized (resolverLock) { 1916 return resolver ; 1917 } 1918 } 1919 1920 /** Set the LocalResolver used in this ORB. This LocalResolver is used for 1921 * register_initial_reference only. 1922 */ 1923 public void setLocalResolver( LocalResolver resolver ) 1924 { 1925 synchronized (this) { 1926 checkShutdownState(); 1927 } 1928 synchronized (resolverLock) { 1929 this.localResolver = resolver ; 1930 } 1931 } 1932 1933 /** Get the LocalResolver used in this ORB. This LocalResolver is used for 1934 * register_initial_reference only. 1935 */ 1936 public LocalResolver getLocalResolver() 1937 { 1938 synchronized (this) { 1939 checkShutdownState(); 1940 } 1941 synchronized (resolverLock) { 1942 return localResolver ; 1943 } 1944 } 1945 1946 /** Set the operation used in string_to_object calls. The Operation must expect a 1947 * String and return an org.omg.CORBA.Object. 1948 */ 1949 public void setURLOperation( Operation stringToObject ) 1950 { 1951 synchronized (this) { 1952 checkShutdownState(); 1953 } 1954 synchronized (urlOperationLock) { 1955 urlOperation = stringToObject ; 1956 } 1957 } 1958 1959 /** Get the operation used in string_to_object calls. The Operation must expect a 1960 * String and return an org.omg.CORBA.Object. 1961 */ 1962 public Operation getURLOperation() 1963 { 1964 synchronized (this) { 1965 checkShutdownState(); 1966 } 1967 synchronized (urlOperationLock) { 1968 return urlOperation ; 1969 } 1970 } 1971 1972 public void setINSDelegate( CorbaServerRequestDispatcher sdel ) 1973 { 1974 synchronized (this) { 1975 checkShutdownState(); 1976 } 1977 synchronized (resolverLock) { 1978 insNamingDelegate = sdel ; 1979 } 1980 } 1981 1982 public TaggedComponentFactoryFinder getTaggedComponentFactoryFinder() 1983 { 1984 synchronized (this) { 1985 checkShutdownState(); 1986 } 1987 return taggedComponentFactoryFinder ; 1988 } 1989 1990 public IdentifiableFactoryFinder getTaggedProfileFactoryFinder() 1991 { 1992 synchronized (this) { 1993 checkShutdownState(); 1994 } 1995 return taggedProfileFactoryFinder ; 1996 } 1997 1998 public IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder() 1999 { 2000 synchronized (this) { 2001 checkShutdownState(); 2002 } 2003 return taggedProfileTemplateFactoryFinder ; 2004 } 2005 2006 private Object objectKeyFactoryAccessLock = new Object(); 2007 2008 public ObjectKeyFactory getObjectKeyFactory() 2009 { 2010 synchronized (this) { 2011 checkShutdownState(); 2012 } 2013 synchronized (objectKeyFactoryAccessLock) { 2014 return objectKeyFactory ; 2015 } 2016 } 2017 2018 public void setObjectKeyFactory( ObjectKeyFactory factory ) 2019 { 2020 synchronized (this) { 2021 checkShutdownState(); 2022 } 2023 synchronized (objectKeyFactoryAccessLock) { 2024 objectKeyFactory = factory ; 2025 } 2026 } 2027 2028 private Object transportManagerAccessorLock = new Object(); 2029 2030 public TransportManager getTransportManager() 2031 { 2032 synchronized (transportManagerAccessorLock) { 2033 if (transportManager == null) { 2034 transportManager = new CorbaTransportManagerImpl(this); 2035 } 2036 return transportManager; 2037 } 2038 } 2039 2040 public CorbaTransportManager getCorbaTransportManager() 2041 { 2042 return (CorbaTransportManager) getTransportManager(); 2043 } 2044 2045 private Object legacyServerSocketManagerAccessLock = new Object(); 2046 2047 public LegacyServerSocketManager getLegacyServerSocketManager() 2048 { 2049 synchronized (this) { 2050 checkShutdownState(); 2051 } 2052 synchronized (legacyServerSocketManagerAccessLock) { 2053 if (legacyServerSocketManager == null) { 2054 legacyServerSocketManager = new LegacyServerSocketManagerImpl(this); 2055 } 2056 return legacyServerSocketManager; 2057 } 2058 } 2059 2060 private Object threadPoolManagerAccessLock = new Object(); 2061 2062 public void setThreadPoolManager(ThreadPoolManager mgr) 2063 { 2064 synchronized (this) { 2065 checkShutdownState(); 2066 } 2067 synchronized (threadPoolManagerAccessLock) { 2068 threadpoolMgr = mgr; 2069 } 2070 } 2071 2072 public ThreadPoolManager getThreadPoolManager() 2073 { 2074 synchronized (this) { 2075 checkShutdownState(); 2076 } 2077 synchronized (threadPoolManagerAccessLock) { 2078 if (threadpoolMgr == null) { 2079 threadpoolMgr = new ThreadPoolManagerImpl(); 2080 orbOwnsThreadPoolManager = true; 2081 } 2082 return threadpoolMgr; 2083 } 2084 } 2085 2086 public CopierManager getCopierManager() 2087 { 2088 synchronized (this) { 2089 checkShutdownState(); 2090 } 2091 return copierManager ; 2092 } 2093 } // Class ORBImpl 2094 2095 //////////////////////////////////////////////////////////////////////// 2096 /// Helper class for a Synchronization Variable 2097 //////////////////////////////////////////////////////////////////////// 2098 2099 class SynchVariable 2100 { 2101 // Synchronization Variable 2102 public boolean _flag; 2103 2104 // Constructor 2105 SynchVariable() 2106 { 2107 _flag = false; 2108 } 2109 2110 // set Flag to true |