1 6 7 package com.sun.corba.se.impl.orb ; 8 9 import java.applet.Applet ; 10 11 import java.io.IOException ; 12 13 import java.lang.reflect.Constructor ; 14 import java.lang.reflect.Field ; 15 import java.lang.reflect.Modifier ; 16 import java.lang.reflect.InvocationTargetException ; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.Properties ; 21 import java.util.Vector ; 22 import java.util.Hashtable ; 23 import java.util.Map ; 24 import java.util.HashMap ; 25 import java.util.LinkedList ; 26 import java.util.Collection ; 27 import java.util.Collections ; 28 import java.util.StringTokenizer ; 29 import java.util.Enumeration ; 30 import java.util.WeakHashMap ; 31 32 import java.net.InetAddress ; 33 34 import java.security.PrivilegedAction ; 35 import java.security.AccessController ; 36 37 import javax.rmi.CORBA.Util ; 38 import javax.rmi.CORBA.ValueHandler ; 39 40 import org.omg.CORBA.Context ; 41 import org.omg.CORBA.ContextList ; 42 import org.omg.CORBA.Environment ; 43 import org.omg.CORBA.ExceptionList ; 44 import org.omg.CORBA.ORBPackage.InvalidName ; 45 import org.omg.CORBA.NVList ; 46 import org.omg.CORBA.TCKind ; 47 import org.omg.CORBA.NamedValue ; 48 import org.omg.CORBA.Request ; 49 import org.omg.CORBA.SystemException ; 50 import org.omg.CORBA.CompletionStatus ; 51 import org.omg.CORBA.TypeCode ; 52 import org.omg.CORBA.Any ; 53 import org.omg.CORBA.StructMember ; 54 import org.omg.CORBA.UnionMember ; 55 import org.omg.CORBA.ValueMember ; 56 import org.omg.CORBA.BAD_PARAM ; 57 import org.omg.CORBA.MARSHAL ; 58 59 import org.omg.CORBA.portable.ValueFactory ; 60 61 import org.omg.CORBA.ORBPackage.InvalidName ; 62 63 import com.sun.org.omg.SendingContext.CodeBase; 64 65 import com.sun.corba.se.pept.broker.Broker; 66 import com.sun.corba.se.pept.protocol.ClientInvocationInfo ; 67 import com.sun.corba.se.pept.transport.ContactInfo; 68 import com.sun.corba.se.pept.transport.ConnectionCache; 69 import com.sun.corba.se.pept.transport.TransportManager; 70 71 import com.sun.corba.se.spi.ior.IOR; 72 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ; 73 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder; 74 import com.sun.corba.se.spi.ior.IORFactories ; 75 import com.sun.corba.se.spi.ior.ObjectKey ; 76 import com.sun.corba.se.spi.ior.ObjectKeyFactory ; 77 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ; 78 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 79 import com.sun.corba.se.spi.oa.OAInvocationInfo; 80 import com.sun.corba.se.spi.oa.ObjectAdapterFactory; 81 import com.sun.corba.se.spi.orb.DataCollector; 82 import com.sun.corba.se.spi.orb.Operation; 83 import com.sun.corba.se.spi.orb.ORBData; 84 import com.sun.corba.se.spi.orb.ORBConfigurator; 85 import com.sun.corba.se.spi.orb.ParserImplBase; 86 import com.sun.corba.se.spi.orb.PropertyParser; 87 import com.sun.corba.se.spi.orb.OperationFactory; 88 import com.sun.corba.se.spi.orb.ORBVersion; 89 import com.sun.corba.se.spi.orb.ORBVersionFactory; 90 import com.sun.corba.se.spi.orbutil.closure.ClosureFactory; 91 import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager; 92 import com.sun.corba.se.spi.protocol.ClientDelegateFactory; 93 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 94 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher; 95 import com.sun.corba.se.spi.protocol.RequestDispatcherDefault; 96 import com.sun.corba.se.spi.protocol.PIHandler; 97 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 98 import com.sun.corba.se.spi.protocol.ForwardException; 99 import com.sun.corba.se.spi.resolver.Resolver; 100 import com.sun.corba.se.spi.resolver.LocalResolver; 101 import com.sun.corba.se.spi.orb.StringPair; 102 import com.sun.corba.se.spi.orb.StringPair; 103 import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory; 104 import com.sun.corba.se.spi.transport.CorbaTransportManager; 105 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager; 106 import com.sun.corba.se.spi.copyobject.CopierManager ; 107 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ; 108 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ; 109 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ; 110 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry; 111 112 import com.sun.corba.se.impl.corba.TypeCodeFactory; 113 import com.sun.corba.se.impl.corba.TypeCodeImpl; 114 import com.sun.corba.se.impl.corba.NVListImpl; 115 import com.sun.corba.se.impl.corba.ExceptionListImpl; 116 import com.sun.corba.se.impl.corba.ContextListImpl; 117 import com.sun.corba.se.impl.corba.NamedValueImpl; 118 import com.sun.corba.se.impl.corba.EnvironmentImpl; 119 import com.sun.corba.se.impl.corba.AsynchInvoke; 120 import com.sun.corba.se.impl.corba.AnyImpl; 121 import com.sun.corba.se.impl.corba.RequestImpl; 122 import com.sun.corba.se.impl.dynamicany.DynAnyFactoryImpl; 123 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 124 import com.sun.corba.se.impl.interceptors.PIHandlerImpl; 125 import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl; 126 import com.sun.corba.se.impl.ior.TaggedComponentFactoryFinderImpl; 127 import com.sun.corba.se.impl.ior.TaggedProfileFactoryFinderImpl; 128 import com.sun.corba.se.impl.ior.TaggedProfileTemplateFactoryFinderImpl; 129 import com.sun.corba.se.impl.oa.toa.TOAFactory; 130 import com.sun.corba.se.impl.oa.poa.BadServerIdHandler; 131 import com.sun.corba.se.impl.oa.poa.DelegateImpl; 132 import com.sun.corba.se.impl.oa.poa.POAFactory; 133 import com.sun.corba.se.impl.orbutil.ORBClassLoader; 134 import com.sun.corba.se.impl.orbutil.ORBConstants; 135 import com.sun.corba.se.impl.orbutil.ORBUtility; 136 import com.sun.corba.se.impl.orbutil.StackImpl; 137 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl; 138 import com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolManagerImpl; 139 import com.sun.corba.se.impl.protocol.RequestDispatcherRegistryImpl; 140 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo; 141 import com.sun.corba.se.impl.transport.CorbaTransportManagerImpl; 142 import com.sun.corba.se.impl.legacy.connection.LegacyServerSocketManagerImpl; 143 import com.sun.corba.se.impl.util.Utility; 144 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 145 import com.sun.corba.se.impl.copyobject.CopierManagerImpl; 146 import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl; 147 148 151 public class ORBImpl extends com.sun.corba.se.spi.orb.ORB 152 { 153 protected TransportManager transportManager; 154 protected LegacyServerSocketManager legacyServerSocketManager; 155 156 private ThreadLocal OAInvocationInfoStack ; 157 158 private ThreadLocal clientInvocationInfoStack ; 159 160 private static IOR codeBaseIOR ; 162 163 private Vector dynamicRequests ; 165 private SynchVariable svResponseReceived ; 166 167 private java.lang.Object runObj = new java.lang.Object (); 168 private java.lang.Object shutdownObj = new java.lang.Object (); 169 private java.lang.Object waitForCompletionObj = new java.lang.Object (); 170 private static final byte STATUS_OPERATING = 1; 171 private static final byte STATUS_SHUTTING_DOWN = 2; 172 private static final byte STATUS_SHUTDOWN = 3; 173 private static final byte STATUS_DESTROYED = 4; 174 private byte status = STATUS_OPERATING; 175 176 private java.lang.Object invocationObj = new java.lang.Object (); 178 private int numInvocations = 0; 179 180 private ThreadLocal isProcessingInvocation = new ThreadLocal () { 183 protected java.lang.Object initialValue() { 184 return Boolean.FALSE; 185 } 186 }; 187 188 private Map typeCodeForClassMap ; 191 192 private Hashtable valueFactoryCache = new Hashtable (); 194 195 private ThreadLocal orbVersionThreadLocal ; 199 200 private RequestDispatcherRegistry requestDispatcherRegistry ; 201 202 private CopierManager copierManager ; 203 204 private int transientServerId ; 205 206 private ThreadGroup threadGroup ; 207 208 private ServiceContextRegistry serviceContextRegistry ; 209 210 private TOAFactory toaFactory ; 212 213 private POAFactory poaFactory ; 215 216 private PIHandler pihandler ; 219 220 private ORBData configData ; 221 222 private BadServerIdHandler badServerIdHandler ; 223 224 private ClientDelegateFactory clientDelegateFactory ; 225 226 private CorbaContactInfoListFactory corbaContactInfoListFactory ; 227 228 private Object resolverLock ; 232 233 private Resolver resolver ; 235 236 private LocalResolver localResolver ; 238 239 private Operation urlOperation ; 241 242 private CorbaServerRequestDispatcher insNamingDelegate ; 243 244 private TaggedComponentFactoryFinder taggedComponentFactoryFinder ; 245 246 private IdentifiableFactoryFinder taggedProfileFactoryFinder ; 247 248 private IdentifiableFactoryFinder taggedProfileTemplateFactoryFinder ; 249 250 private ObjectKeyFactory objectKeyFactory ; 251 252 private ThreadPoolManager threadpoolMgr; 253 254 private void dprint( String msg ) 255 { 256 ORBUtility.dprint( this, msg ) ; 257 } 258 259 274 public ORBData getORBData() 275 { 276 return configData ; 277 } 278 279 public PIHandler getPIHandler() 280 { 281 return pihandler ; 282 } 283 284 288 public ORBImpl() 289 { 290 } 292 293 public ORBVersion getORBVersion() 294 { 295 return (ORBVersion)(orbVersionThreadLocal.get()) ; 296 } 297 298 public void setORBVersion(ORBVersion verObj) 299 { 300 orbVersionThreadLocal.set(verObj); 301 } 302 303 306 307 private void preInit( String [] params, Properties props ) 310 { 311 pihandler = new PINoOpHandlerImpl( ); 319 320 try { 334 threadGroup = (ThreadGroup ) AccessController.doPrivileged( 339 new PrivilegedAction () { 340 public Object run() { 341 ThreadGroup tg = Thread.currentThread().getThreadGroup() ; 342 ThreadGroup ptg = tg ; 343 try { 344 while (ptg != null) { 345 tg = ptg; 346 ptg = tg.getParent(); 347 } 348 } catch (SecurityException se) { 349 } 351 return new ThreadGroup (tg, "ORB ThreadGroup"); 352 } 353 } 354 ); 355 } catch (SecurityException e) { 356 threadGroup = Thread.currentThread().getThreadGroup(); 358 } 359 360 transientServerId = (int)System.currentTimeMillis(); 374 375 orbVersionThreadLocal = new ThreadLocal () { 376 protected java.lang.Object initialValue() { 377 return ORBVersionFactory.getORBVersion() ; 379 } 380 }; 381 382 resolverLock = new java.lang.Object () ; 383 384 requestDispatcherRegistry = new RequestDispatcherRegistryImpl( 385 this, ORBConstants.DEFAULT_SCID); 386 copierManager = new CopierManagerImpl( this ) ; 387 388 taggedComponentFactoryFinder = 389 new TaggedComponentFactoryFinderImpl(this) ; 390 taggedProfileFactoryFinder = 391 new TaggedProfileFactoryFinderImpl(this) ; 392 taggedProfileTemplateFactoryFinder = 393 new TaggedProfileTemplateFactoryFinderImpl(this) ; 394 395 dynamicRequests = new Vector (); 396 svResponseReceived = new SynchVariable(); 397 398 OAInvocationInfoStack = 399 new ThreadLocal () { 400 protected java.lang.Object initialValue() 401 { 402 return new StackImpl(); 403 } 404 }; 405 406 clientInvocationInfoStack = 407 new ThreadLocal () { 408 protected java.lang.Object initialValue() { 409 return new StackImpl(); 410 } 411 }; 412 413 serviceContextRegistry = new ServiceContextRegistry( this ) ; 414 } 415 416 protected void setDebugFlags( String [] args ) 417 { 418 for (int ctr=0; ctr<args.length; ctr++ ) { 419 String token = args[ctr] ; 420 421 try { 424 Field fld = this.getClass().getField( token + "DebugFlag" ) ; 425 int mod = fld.getModifiers() ; 426 if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod )) 427 if (fld.getType() == boolean.class) 428 fld.setBoolean( this, true ) ; 429 } catch (Exception exc) { 430 } 432 } 433 } 434 435 private static class ConfigParser extends ParserImplBase { 438 public Class configurator = ORBConfiguratorImpl.class ; 441 442 public PropertyParser makeParser() 443 { 444 PropertyParser parser = new PropertyParser() ; 445 parser.add( ORBConstants.SUN_PREFIX + "ORBConfigurator", 446 OperationFactory.classAction(), "configurator" ) ; 447 return parser ; 448 } 449 } 450 451 private void postInit( String [] params, DataCollector dataCollector ) 452 { 453 configData = new ORBDataParserImpl( this, dataCollector) ; 457 458 setDebugFlags( configData.getORBDebugFlags() ) ; 461 462 getTransportManager(); 465 getLegacyServerSocketManager(); 466 467 ConfigParser parser = new ConfigParser() ; 469 parser.init( dataCollector ) ; 470 471 ORBConfigurator configurator = null ; 472 try { 473 configurator = 474 (ORBConfigurator)(parser.configurator.newInstance()) ; 475 } catch (Exception iexc) { 476 throw wrapper.badOrbConfigurator( iexc, parser.configurator.getName() ) ; 477 } 478 479 try { 483 configurator.configure( dataCollector, this ) ; 484 } catch (Exception exc) { 485 throw wrapper.orbConfiguratorError( exc ) ; 486 } 487 488 pihandler = new PIHandlerImpl( this, params) ; 490 pihandler.initialize() ; 491 492 getThreadPoolManager(); 495 496 super.getByteBufferPool(); 497 } 498 499 private synchronized POAFactory getPOAFactory() 500 { 501 if (poaFactory == null) { 502 poaFactory = (POAFactory)requestDispatcherRegistry.getObjectAdapterFactory( 503 ORBConstants.TRANSIENT_SCID ) ; 504 } 505 506 return poaFactory ; 507 } 508 509 private synchronized TOAFactory getTOAFactory() 510 { 511 if (toaFactory == null) { 512 toaFactory = (TOAFactory)requestDispatcherRegistry.getObjectAdapterFactory( 513 ORBConstants.TOA_SCID ) ; 514 } 515 516 return toaFactory ; 517 } 518 519 public void set_parameters( Properties props ) 520 { 521 preInit( null, props ) ; 522 DataCollector dataCollector = 523 DataCollectorFactory.create( props, getLocalHostName() ) ; 524 postInit( null, dataCollector ) ; 525 } 526 527 protected void set_parameters(Applet app, Properties props) 528 { 529 preInit( null, props ) ; 530 DataCollector dataCollector = 531 DataCollectorFactory.create( app, props, getLocalHostName() ) ; 532 postInit( null, dataCollector ) ; 533 } 534 535 protected void set_parameters (String [] params, Properties props) 536 { 537 preInit( params, props ) ; 538 DataCollector dataCollector = 539 DataCollectorFactory.create( params, props, getLocalHostName() ) ; 540 postInit( params, dataCollector ) ; 541 } 542 543 546 547 public synchronized org.omg.CORBA.portable.OutputStream create_output_stream() 548 { 549 checkShutdownState(); 550 return new EncapsOutputStream(this); 551 } 552 553 563 public synchronized org.omg.CORBA.Current get_current() 564 { 565 checkShutdownState(); 566 567 576 577 throw wrapper.genericNoImpl() ; 578 } 579 580 588 public synchronized NVList create_list(int count) 589 { 590 checkShutdownState(); 591 return new NVListImpl(this, count); 592 } 593 594 602 public synchronized NVList create_operation_list(org.omg.CORBA.Object oper) 603 { 604 checkShutdownState(); 605 throw wrapper.genericNoImpl() ; 606 } 607 608 613 public synchronized NamedValue create_named_value(String s, Any any, int flags) 614 { 615 checkShutdownState(); 616 return new NamedValueImpl(this, s, any, flags); 617 } 618 619 624 public synchronized org.omg.CORBA.ExceptionList create_exception_list() 625 { 626 checkShutdownState(); 627 return new ExceptionListImpl(); 628 } 629 630 635 public synchronized org.omg.CORBA.ContextList create_context_list() 636 { 637 checkShutdownState(); 638 return new ContextListImpl(this); 639 } 640 641 646 public synchronized org.omg.CORBA.Context get_default_context() 647 { 648 checkShutdownState(); 649 throw wrapper.genericNoImpl() ; 650 } 651 652 657 public synchronized org.omg.CORBA.Environment create_environment() 658 { 659 checkShutdownState(); 660 return new EnvironmentImpl(); 661 } 662 663 public synchronized void send_multiple_requests_oneway(Request [] req) 664 { 665 checkShutdownState(); 666 667 for (int i = 0; i < req.length; i++) { 669 req[i].send_oneway(); 670 } 671 } 672 673 678 public synchronized void send_multiple_requests_deferred(Request [] req) 679 { 680 checkShutdownState(); 681 682 for (int i = 0; i < req.length; i++) { 684 dynamicRequests.addElement(req[i]); 685 } 686 687 for (int i = 0; i < req.length; i++) { 689 AsynchInvoke invokeObject = new AsynchInvoke( this, 690 (com.sun.corba.se.impl.corba.RequestImpl)req[i], true); 691 new Thread (invokeObject).start(); 692 } 693 } 694 695 698 public synchronized boolean poll_next_response() 699 { 700 checkShutdownState(); 701 702 Request currRequest; 703 704 Enumeration ve = dynamicRequests.elements(); 706 while (ve.hasMoreElements() == true) { 707 currRequest = (Request )ve.nextElement(); 708 if (currRequest.poll_response() == true) { 709 return true; 710 } 711 } 712 return false; 713 } 714 715 720 public org.omg.CORBA.Request get_next_response() 721 throws org.omg.CORBA.WrongTransaction 722 { 723 synchronized( this ) { 724 checkShutdownState(); 725 } 726 727 while (true) { 728 synchronized ( dynamicRequests ) { 730 Enumeration elems = dynamicRequests.elements(); 731 while ( elems.hasMoreElements() ) { 732 Request currRequest = (Request )elems.nextElement(); 733 if ( currRequest.poll_response() ) { 734 currRequest.get_response(); 736 dynamicRequests.removeElement(currRequest); 737 return currRequest; 738 } 739 } 740 } 741 742 synchronized(this.svResponseReceived) { 744 while (!this.svResponseReceived.value()) { 745 try { 746 this.svResponseReceived.wait(); 747 } catch(java.lang.InterruptedException ex) { 748 } 750 } 751 this.svResponseReceived.reset(); 753 } 754 } 755 } 756 757 760 public void notifyORB() 761 { 762 synchronized (this.svResponseReceived) { 763 this.svResponseReceived.set(); 764 this.svResponseReceived.notify(); 765 } 766 } 767 768 773 public synchronized String object_to_string(org.omg.CORBA.Object obj) 774 { 775 checkShutdownState(); 776 777 if (obj == null) { 779 IOR nullIOR = IORFactories.makeIOR( this ) ; 780 return nullIOR.stringify(); 781 } 782 783 IOR ior = null ; 784 785 try { 786 ior = ORBUtility.connectAndGetIOR( this, obj ) ; 787 } catch (BAD_PARAM bp) { 788 if (bp.minor == ORBUtilSystemException.LOCAL_OBJECT_NOT_ALLOWED) { 790 throw omgWrapper.notAnObjectImpl( bp ) ; 791 } else 792 throw bp ; 796 } 797 798 return ior.stringify() ; 799 } 800 801 806 public org.omg.CORBA.Object string_to_object(String str) 807 { 808 Operation op ; 809 810 synchronized (this) { 811 checkShutdownState(); 812 op = urlOperation ; 813 } 814 815 if (str == null) 816 throw wrapper.nullParam() ; 817 818 synchronized (resolverLock) { 819 org.omg.CORBA.Object obj = (org.omg.CORBA.Object )op.operate( str ) ; 820 return obj ; 821 } 822 } 823 824 public synchronized IOR getFVDCodeBaseIOR() 827 { 828 if (codeBaseIOR != null) return codeBaseIOR; 830 831 CodeBase cb; 833 834 ValueHandler vh = ORBUtility.createValueHandler(this); 835 836 cb = (CodeBase)vh.getRunTimeCodeBase(); 837 return ORBUtility.connectAndGetIOR( this, cb ) ; 838 } 839 840 846 public synchronized TypeCode get_primitive_tc(TCKind tcKind) 847 { 848 checkShutdownState(); 849 return get_primitive_tc( tcKind.value() ) ; 850 } 851 852 860 public synchronized TypeCode create_struct_tc(String id, 861 String name, 862 StructMember [] members) 863 { 864 checkShutdownState(); 865 return new TypeCodeImpl(this, TCKind._tk_struct, id, name, members); 866 } 867 868 878 public synchronized TypeCode create_union_tc(String id, 879 String name, 880 TypeCode discriminator_type, 881 UnionMember [] members) 882 { 883 checkShutdownState(); 884 return new TypeCodeImpl(this, 885 TCKind._tk_union, 886 id, 887 name, 888 discriminator_type, 889 members); 890 } 891 892 900 public synchronized TypeCode create_enum_tc(String id, 901 String name, 902 String [] members) 903 { 904 checkShutdownState(); 905 return new TypeCodeImpl(this, TCKind._tk_enum, id, name, members); 906 } 907 908 917 public synchronized TypeCode create_alias_tc(String id, 918 String name, 919 TypeCode original_type) 920 { 921 checkShutdownState(); 922 return new TypeCodeImpl(this, TCKind._tk_alias, id, name, original_type); 923 } 924 925 933 public synchronized TypeCode create_exception_tc(String id, 934 String name, 935 StructMember [] members) 936 { 937 checkShutdownState(); 938 return new TypeCodeImpl(this, TCKind._tk_except, id, name, members); 939 } 940 941 948 public synchronized TypeCode create_interface_tc(String id, 949 String name) 950 { 951 checkShutdownState(); 952 return new TypeCodeImpl(this, TCKind._tk_objref, id, name); 953 } 954 955 961 public synchronized TypeCode create_string_tc(int bound) 962 { 963 checkShutdownState(); 964 return new TypeCodeImpl(this, TCKind._tk_string, bound); 965 } 966 967 973 public synchronized TypeCode create_wstring_tc(int bound) 974 { 975 checkShutdownState(); 976 return new TypeCodeImpl(this, TCKind._tk_wstring, bound); 977 } 978 979 987 public synchronized TypeCode create_sequence_tc(int bound, 988 TypeCode element_type) 989 { 990 checkShutdownState(); 991 return new TypeCodeImpl(this, TCKind._tk_sequence, bound, element_type); 992 } 993 994 995 1003 public synchronized TypeCode create_recursive_sequence_tc(int bound, 1004 int offset) 1005 { 1006 checkShutdownState(); 1007 return new TypeCodeImpl(this, TCKind._tk_sequence, bound, offset); 1008 } 1009 1010 1011 1019 public synchronized TypeCode create_array_tc(int length, 1020 TypeCode element_type) 1021 { 1022 checkShutdownState(); 1023 return new TypeCodeImpl(this, TCKind._tk_array, length, element_type); 1024 } 1025 1026 1027 public synchronized org.omg.CORBA.TypeCode create_native_tc(String id, 1028 String name) 1029 { 1030 checkShutdownState(); 1031 return new TypeCodeImpl(this, TCKind._tk_native, id, name); 1032 } 1033 1034 public synchronized org.omg.CORBA.TypeCode create_abstract_interface_tc( 1035 String id, 1036 String name) 1037 { 1038 checkShutdownState(); 1039 return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name); 1040 } 1041 1042 public synchronized org.omg.CORBA.TypeCode create_fixed_tc(short digits, short scale) 1043 { 1044 checkShutdownState(); 1045 return new TypeCodeImpl(this, TCKind._tk_fixed, digits, scale); 1046 } 1047 1048 public synchronized org.omg.CORBA.TypeCode create_value_tc(String id, 1049 String name, 1050 short type_modifier, 1051 TypeCode concrete_base, 1052 ValueMember [] members) 1053 { 1054 checkShutdownState(); 1055 return new TypeCodeImpl(this, TCKind._tk_value, id, name, 1056 type_modifier, concrete_base, members); 1057 } 1058 1059 public synchronized org.omg.CORBA.TypeCode create_recursive_tc(String id) { 1060 checkShutdownState(); 1061 return new TypeCodeImpl(this, id); 1062 } 1063 1064 public synchronized org.omg.CORBA.TypeCode create_value_box_tc(String id, 1065 String name, 1066 TypeCode boxed_type) 1067 { 1068 checkShutdownState(); 1069 return new TypeCodeImpl(this, TCKind._tk_value_box, id, name, 1070 boxed_type); 1071 } 1072 1073 1078 public synchronized Any create_any() 1079 { 1080 checkShutdownState(); 1081 return new AnyImpl(this); 1082 } 1083 1084 1087 1090 public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci) 1091 { 1092 if (typeCodeForClassMap == null) 1093 typeCodeForClassMap = Collections.synchronizedMap( 1094 new WeakHashMap (64)); 1095 if ( ! typeCodeForClassMap.containsKey(c)) 1097 typeCodeForClassMap.put(c, tci); 1098 } 1099 1100 public synchronized TypeCodeImpl getTypeCodeForClass(Class c) 1101 { 1102 if (typeCodeForClassMap == null) 1103 return null; 1104 return (TypeCodeImpl)typeCodeForClassMap.get(c); 1105 } 1106 1107 1111 1112 1121 public String [] list_initial_services() 1122 { 1123 Resolver res ; 1124 1125 synchronized( this ) { 1126 checkShutdownState(); 1127 res = resolver ; 1128 } 1129 1130 synchronized (resolverLock) { 1131 java.util.Set keys = res.list() ; 1132 return (String [])keys.toArray( new String [keys.size()] ) ; 1133 } 1134 } 1135 1136 1146 public org.omg.CORBA.Object resolve_initial_references( 1147 String identifier) throws InvalidName 1148 { 1149 Resolver res ; 1150 1151 synchronized( this ) { 1152 checkShutdownState(); 1153 res = resolver ; 1154 } 1155 1156 synchronized (resolverLock) { 1157 org.omg.CORBA.Object result = res.resolve( identifier ) ; 1158 1159 if (result == null) 1160 throw new InvalidName () ; 1161 else 1162 return result ; 1163 } 1164 } 1165 1166 1179 public void register_initial_reference( 1180 String id, org.omg.CORBA.Object obj ) throws InvalidName 1181 { 1182 CorbaServerRequestDispatcher insnd ; 1183 1184 if ((id == null) || (id.length() == 0)) 1185 throw new InvalidName () ; 1186 1187 synchronized (this) { 1188 checkShutdownState(); 1189 } 1190 1191 synchronized (resolverLock) { 1192 insnd = insNamingDelegate ; 1193 1194 java.lang.Object obj2 = localResolver.resolve( id ) ; 1195 if (obj2 != null) 1196 throw new InvalidName (id + " already registered") ; 1197 1198 localResolver.register( id, ClosureFactory.makeConstant( obj )) ; 1199 } 1200 1201 synchronized (this) { 1202 if (StubAdapter.isStub(obj)) 1203 requestDispatcherRegistry.registerServerRequestDispatcher( 1205 insnd, id ) ; 1206 } 1207 } 1208 1209 1213 1214 public void run() 1215 { 1216 synchronized (this) { 1217 checkShutdownState(); 1218 } 1219 1220 synchronized (runObj) { 1221 try { 1222 runObj.wait(); 1223 } catch ( InterruptedException ex ) {} 1224 } 1225 } 1226 1227 public void shutdown(boolean wait_for_completion) 1228 { 1229 synchronized (this) { 1230 checkShutdownState(); 1231 } 1232 1233 synchronized (shutdownObj) { 1235 checkShutdownState(); 1236 if (wait_for_completion && 1238 isProcessingInvocation.get() == Boolean.TRUE) { 1239 throw omgWrapper.shutdownWaitForCompletionDeadlock() ; 1240 } 1241 1242 status = STATUS_SHUTTING_DOWN; 1243 shutdownServants(wait_for_completion); 1247 if (wait_for_completion) { 1248 synchronized ( waitForCompletionObj ) { 1249 while (numInvocations > 0) { 1250 try { 1251 waitForCompletionObj.wait(); 1252 } catch (InterruptedException ex) {} 1253 } 1254 } 1255 } 1256 synchronized ( runObj ) { 1257 runObj.notifyAll(); 1258 } 1259 status = STATUS_SHUTDOWN; 1260 } 1261 } 1262 1263 1267 protected void shutdownServants(boolean wait_for_completion) { 1268 Iterator iter = requestDispatcherRegistry.getObjectAdapterFactories().iterator() ; 1269 while (iter.hasNext()) { 1270 ObjectAdapterFactory oaf = (ObjectAdapterFactory)iter.next() ; 1271 oaf.shutdown( wait_for_completion ) ; 1272 } 1273 } 1274 1275 public void checkShutdownState() 1278 { 1279 if (status == STATUS_DESTROYED) { 1280 throw wrapper.orbDestroyed() ; 1281 } 1282 1283 if (status == STATUS_SHUTDOWN) { 1284 throw omgWrapper.badOperationAfterShutdown() ; 1285 } 1286 } 1287 1288 public boolean isDuringDispatch() 1289 { 1290 Boolean value = (Boolean )(isProcessingInvocation.get()) ; 1291 return value.booleanValue() ; 1292 } 1293 1294 public void startingDispatch() 1295 { 1296 synchronized (invocationObj) { 1297 isProcessingInvocation.set(Boolean.TRUE); 1298 numInvocations++; 1299 } 1300 } 1301 1302 public void finishedDispatch() 1303 { 1304 synchronized (invocationObj) { 1305 numInvocations--; 1306 isProcessingInvocation.set(Boolean.FALSE); 1307 if (numInvocations == 0) { 1308 synchronized (waitForCompletionObj) { 1309 waitForCompletionObj.notifyAll(); 1310 } 1311 } else if (numInvocations < 0) { 1312 throw wrapper.numInvocationsAlreadyZero( 1313 CompletionStatus.COMPLETED_YES ) ; 1314 } 1315 } 1316 } 1317 1318 1323 public synchronized void destroy() 1324 { 1325 if (status == STATUS_OPERATING) { 1326 shutdown(true); 1327 } 1328 getCorbaTransportManager().close(); 1329 getPIHandler().destroyInterceptors() ; 1330 status = STATUS_DESTROYED; 1331 } 1332 1333 1342 public synchronized ValueFactory register_value_factory(String repositoryID, 1343 ValueFactory factory) 1344 { 1345 checkShutdownState(); 1346 1347 if ((repositoryID == null) || (factory == null)) 1348 throw omgWrapper.unableRegisterValueFactory() ; 1349 1350 return (ValueFactory )valueFactoryCache.put(repositoryID, factory); 1351 } 1352 1353 1358 public synchronized void unregister_value_factory(String repositoryID) 1359 { 1360 checkShutdownState(); 1361 1362 if (valueFactoryCache.remove(repositoryID) == null) 1363 throw wrapper.nullParam() ; 1364 } 1365 1366 1375 public synchronized ValueFactory lookup_value_factory(String repositoryID) 1376 { 1377 checkShutdownState(); 1378 1379 ValueFactory factory = 1380 (ValueFactory )valueFactoryCache.get(repositoryID); 1381 1382 if (factory == null) { 1383 try { 1384 factory = Utility.getFactory(null, null, null, repositoryID); 1385 } catch(org.omg.CORBA.MARSHAL ex) { 1386 throw wrapper.unableFindValueFactory( ex ) ; 1387 } 1388 } 1389 1390 return factory ; 1391 } 1392 1393 public OAInvocationInfo peekInvocationInfo() 1394 { 1395 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1396 return (OAInvocationInfo)(stack.peek()) ; 1397 } 1398 1399 public void pushInvocationInfo( OAInvocationInfo info ) 1400 { 1401 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1402 stack.push( info ) ; 1403 } 1404 1405 public OAInvocationInfo popInvocationInfo() 1406 { 1407 StackImpl stack = (StackImpl)(OAInvocationInfoStack.get()) ; 1408 return (OAInvocationInfo)(stack.pop()) ; 1409 } 1410 1411 1415 1416 private Object badServerIdHandlerAccessLock = new Object (); 1417 1418 public void initBadServerIdHandler() 1419 { 1420 synchronized (badServerIdHandlerAccessLock) { 1421 Class cls = configData.getBadServerIdHandler() ; 1422 if (cls != null) { 1423 try { 1424 Class [] params = new Class [] { org.omg.CORBA.ORB .class }; 1425 java.lang.Object [] args = new java.lang.Object []{this}; 1426 Constructor cons = cls.getConstructor(params); 1427 badServerIdHandler = 1428 (BadServerIdHandler) cons.newInstance(args); 1429 } catch (Exception e) { 1430 throw wrapper.errorInitBadserveridhandler( e ) ; 1431 } 1432 } 1433 } 1434 } 1435 1436 public void setBadServerIdHandler( BadServerIdHandler handler ) 1437 { 1438 synchronized (badServerIdHandlerAccessLock) { 1439 badServerIdHandler = handler; 1440 } 1441 } 1442 1443 public void handleBadServerId( ObjectKey okey ) 1444 { 1445 synchronized (badServerIdHandlerAccessLock) { 1446 if (badServerIdHandler == null) 1447 throw wrapper.badServerId() ; 1448 else 1449 badServerIdHandler.handle( okey ) ; 1450 } 1451 } 1452 1453 public synchronized org.omg.CORBA.Policy create_policy( int type, 1454 org.omg.CORBA.Any val ) throws org.omg.CORBA.PolicyError 1455 { 1456 checkShutdownState() ; 1457 1458 return pihandler.create_policy( type, val ) ; 1459 } 1460 1461 1464 public synchronized void connect(org.omg.CORBA.Object servant) 1465 { 1466 checkShutdownState(); 1467 if (getTOAFactory() == null) 1468 throw wrapper.noToa() ; 1469 1470 try { 1471 String codebase = javax.rmi.CORBA.Util.getCodebase( servant.getClass() ) ; 1472 getTOAFactory().getTOA( codebase ).connect( servant ) ; 1473 } catch ( Exception ex ) { 1474 throw wrapper.orbConnectError( ex ) ; 1475 } 1476 } 1477 1478 public synchronized void disconnect(org.omg.CORBA.Object obj) 1479 { 1480 checkShutdownState(); 1481 if (getTOAFactory() == null) 1482 throw wrapper.noToa() ; 1483 1484 try { 1485 getTOAFactory().getTOA().disconnect( obj ) ; 1486 } catch ( Exception ex ) { 1487 throw wrapper.orbConnectError( ex ) ; 1488 } 1489 } 1490 1491 public int getTransientServerId() 1492 { 1493 if( configData.getORBServerIdPropertySpecified( ) ) { 1494 return configData.getPersistentServerId( ); 1496 } 1497 return transientServerId; 1498 } 1499 1500 public RequestDispatcherRegistry getRequestDispatcherRegistry() 1501 { 1502 return requestDispatcherRegistry; 1503 } 1504 1505 public ServiceContextRegistry getServiceContextRegistry() 1506 { 1507 return serviceContextRegistry ; 1508 } 1509 1510 1521 public boolean isLocalHost( String hostName ) 1523 { 1524 return hostName.equals( configData.getORBServerHost() ) || 1525 hostName.equals( getLocalHostName() ) ; 1526 } 1527 1528 public boolean isLocalServerId( int subcontractId, int serverId ) 1529 { 1530 if ((subcontractId < ORBConstants.FIRST_POA_SCID) || 1531 (subcontractId > ORBConstants.MAX_POA_SCID)) 1532 return serverId == getTransientServerId( ) ; 1533 1534 if (ORBConstants.isTransient( subcontractId )) 1536 return (serverId == getTransientServerId()) ; 1537 else if (configData.getPersistentServerIdInitialized()) 1538 return (serverId == configData.getPersistentServerId()) ; 1539 else 1540 return false ; 1541 } 1542 1543 1546 1547 private String getHostName(String host) 1548 throws java.net.UnknownHostException 1549 { 1550 return InetAddress.getByName( host ).getHostAddress(); 1551 } 1552 1553 1565 1566 private static String localHostString = null; 1567 1568 private synchronized String getLocalHostName() 1569 { 1570 if (localHostString == null) { 1571 try { 1572 localHostString = InetAddress.getLocalHost().getHostAddress(); 1573 } catch (Exception ex) { 1574 throw wrapper.getLocalHostFailed( ex ) ; 1575 } 1576 } 1577 return localHostString ; 1578 } 1579 1580 1584 1585 1588 public synchronized boolean work_pending() 1589 { 1590 checkShutdownState(); 1591 throw wrapper.genericNoImpl() ; 1592 } 1593 1594 1596 public synchronized void perform_work() 1597 { 1598 checkShutdownState(); 1599 throw wrapper.genericNoImpl() ; 1600 } 1601 1602 public synchronized void set_delegate(java.lang.Object servant){ 1603 checkShutdownState(); 1604 1605 POAFactory poaFactory = getPOAFactory() ; 1606 if (poaFactory != null) 1607 ((org.omg.PortableServer.Servant )servant) 1608 ._set_delegate( poaFactory.getDelegateImpl() ) ; 1609 else 1610 throw wrapper.noPoa() ; 1611 } 1612 1613 1618 public ClientInvocationInfo createOrIncrementInvocationInfo() 1619 { 1620 StackImpl invocationInfoStack = 1621 (StackImpl) clientInvocationInfoStack.get(); 1622 ClientInvocationInfo clientInvocationInfo = null; 1623 if (!invocationInfoStack.empty()) { 1624 clientInvocationInfo = 1625 (ClientInvocationInfo) invocationInfoStack.peek(); 1626 } 1627 if ((clientInvocationInfo == null) || 1628 (!clientInvocationInfo.isRetryInvocation())) 1629 { 1630 clientInvocationInfo = new CorbaInvocationInfo(this); 1632 startingDispatch(); 1633 invocationInfoStack.push(clientInvocationInfo); 1634 } 1635 clientInvocationInfo.setIsRetryInvocation(false); 1637 clientInvocationInfo.incrementEntryCount(); 1638 return clientInvocationInfo; 1639 } 1640 1641 public void releaseOrDecrementInvocationInfo() 1642 { 1643 StackImpl invocationInfoStack = 1644 (StackImpl)clientInvocationInfoStack.get(); 1645 ClientInvocationInfo clientInvocationInfo = null; 1646 if (!invocationInfoStack.empty()) { 1647 clientInvocationInfo = 1648 (ClientInvocationInfo)invocationInfoStack.peek(); 1649 } else { 1650 throw wrapper.invocationInfoStackEmpty() ; 1651 } 1652 clientInvocationInfo.decrementEntryCount(); 1653 if (clientInvocationInfo.getEntryCount() == 0) { 1654 invocationInfoStack.pop(); 1655 finishedDispatch(); 1656 } 1657 } 1658 1659 public ClientInvocationInfo getInvocationInfo() 1660 { 1661 StackImpl invocationInfoStack = 1662 (StackImpl) clientInvocationInfoStack.get(); 1663 return (ClientInvocationInfo) invocationInfoStack.peek(); 1664 } 1665 1666 1671 private Object clientDelegateFactoryAccessorLock = new Object (); 1672 1673 public void setClientDelegateFactory( ClientDelegateFactory factory ) 1674 { 1675 synchronized (clientDelegateFactoryAccessorLock) { 1676 clientDelegateFactory = factory ; 1677 } 1678 } 1679 1680 public ClientDelegateFactory getClientDelegateFactory() 1681 { 1682 synchronized (clientDelegateFactoryAccessorLock) { 1683 return clientDelegateFactory ; 1684 } 1685 } 1686 1687 private Object corbaContactInfoListFactoryAccessLock = new Object (); 1688 1689 public void setCorbaContactInfoListFactory( CorbaContactInfoListFactory factory ) 1690 { 1691 synchronized (corbaContactInfoListFactoryAccessLock) { 1692 corbaContactInfoListFactory = factory ; 1693 } 1694 } 1695 1696 public synchronized CorbaContactInfoListFactory getCorbaContactInfoListFactory() 1697 { 1698 return corbaContactInfoListFactory ; 1699 } 1700 1701 1704 public void setResolver( Resolver resolver ) 1705 { 1706 synchronized (resolverLock) { 1707 this.resolver = resolver ; 1708 } 1709 } 1710 1711 1714 public Resolver getResolver() 1715 { 1716 synchronized (resolverLock) { 1717 return resolver ; 1718 } 1719 } 1720 1721 1724 public void setLocalResolver( LocalResolver resolver ) 1725 { 1726 synchronized (resolverLock) { 1727 this.localResolver = resolver ; 1728 } 1729 } 1730 1731 1734 public LocalResolver getLocalResolver() 1735 { 1736 synchronized (resolverLock) { 1737 return localResolver ; 1738 } 1739 } 1740 1741 1744 public void setURLOperation( Operation stringToObject ) 1745 { 1746 synchronized (resolverLock) { 1747 urlOperation = stringToObject ; 1748 } 1749 } 1750 1751 1754 public Operation getURLOperation() 1755 { 1756 synchronized (resolverLock) { 1757 return urlOperation ; 1758 } 1759 } 1760 1761 public void setINSDelegate( CorbaServerRequestDispatcher sdel ) 1762 { 1763 synchronized (resolverLock) { 1764 insNamingDelegate = sdel ; 1765 } 1766 } 1767 1768 public TaggedComponentFactoryFinder getTaggedComponentFactoryFinder() 1769 { 1770 return taggedComponentFactoryFinder ; 1771 } 1772 1773 public IdentifiableFactoryFinder getTaggedProfileFactoryFinder() 1774 { 1775 return taggedProfileFactoryFinder ; 1776 } 1777 1778 public IdentifiableFactoryFinder getTaggedProfileTemplateFactoryFinder() 1779 { 1780 return taggedProfileTemplateFactoryFinder ; 1781 } 1782 1783 private Object objectKeyFactoryAccessLock = new Object (); 1784 1785 public ObjectKeyFactory getObjectKeyFactory() 1786 { 1787 synchronized (objectKeyFactoryAccessLock) { 1788 return objectKeyFactory ; 1789 } 1790 } 1791 1792 public void setObjectKeyFactory( ObjectKeyFactory factory ) 1793 { 1794 synchronized (objectKeyFactoryAccessLock) { 1795 objectKeyFactory = factory ; 1796 } 1797 } 1798 1799 private Object transportManagerAccessorLock = new Object (); 1800 1801 public TransportManager getTransportManager() 1802 { 1803 synchronized (transportManagerAccessorLock) { 1804 if (transportManager == null) { 1805 transportManager = new CorbaTransportManagerImpl(this); 1806 } 1807 return transportManager; 1808 } 1809 } 1810 1811 public CorbaTransportManager getCorbaTransportManager() 1812 { 1813 return (CorbaTransportManager) getTransportManager(); 1814 } 1815 1816 private Object legacyServerSocketManagerAccessLock = new Object (); 1817 1818 public LegacyServerSocketManager getLegacyServerSocketManager() 1819 { 1820 synchronized (legacyServerSocketManagerAccessLock) { 1821 if (legacyServerSocketManager == null) { 1822 legacyServerSocketManager = new LegacyServerSocketManagerImpl(this); 1823 } 1824 return legacyServerSocketManager; 1825 } 1826 } 1827 1828 private Object threadPoolManagerAccessLock = new Object (); 1829 1830 public void setThreadPoolManager(ThreadPoolManager mgr) 1831 { 1832 synchronized (threadPoolManagerAccessLock) { 1833 threadpoolMgr = mgr; 1834 } 1835 } 1836 1837 public ThreadPoolManager getThreadPoolManager() 1838 { 1839 synchronized (threadPoolManagerAccessLock) { 1840 if (threadpoolMgr == null) { 1841 threadpoolMgr = new ThreadPoolManagerImpl( threadGroup ); 1842 } 1843 return threadpoolMgr; 1844 } 1845 } 1846 1847 public CopierManager getCopierManager() 1848 { 1849 return copierManager ; 1850 } 1851} 1853 1857class SynchVariable 1858{ 1859 public boolean _flag; 1861 1862 SynchVariable() 1864 { 1865 _flag = false; 1866 } 1867 1868 public void set() 1870 { 1871 _flag = true; 1872 } 1873 1874 public boolean value() 1876 { 1877 return _flag; 1878 } 1879 1880 public void reset() 1882 { 1883 _flag = false; 1884 } 1885} 1886 1887 1889 1890 | Popular Tags |