1 7 8 package com.sun.corba.se.impl.oa.poa; 9 10 import java.util.Collection ; 11 import java.util.Set ; 12 import java.util.HashSet ; 13 import java.util.Map ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 17 import org.omg.CORBA.Policy ; 18 import org.omg.CORBA.SystemException ; 19 20 import org.omg.PortableServer.POA ; 21 import org.omg.PortableServer.Servant ; 22 import org.omg.PortableServer.POAManager ; 23 import org.omg.PortableServer.AdapterActivator ; 24 import org.omg.PortableServer.ServantManager ; 25 import org.omg.PortableServer.ForwardRequest ; 26 import org.omg.PortableServer.ThreadPolicy ; 27 import org.omg.PortableServer.LifespanPolicy ; 28 import org.omg.PortableServer.IdUniquenessPolicy ; 29 import org.omg.PortableServer.IdAssignmentPolicy ; 30 import org.omg.PortableServer.ImplicitActivationPolicy ; 31 import org.omg.PortableServer.ServantRetentionPolicy ; 32 import org.omg.PortableServer.RequestProcessingPolicy ; 33 import org.omg.PortableServer.ThreadPolicyValue ; 34 import org.omg.PortableServer.LifespanPolicyValue ; 35 import org.omg.PortableServer.IdUniquenessPolicyValue ; 36 import org.omg.PortableServer.IdAssignmentPolicyValue ; 37 import org.omg.PortableServer.ImplicitActivationPolicyValue ; 38 import org.omg.PortableServer.ServantRetentionPolicyValue ; 39 import org.omg.PortableServer.RequestProcessingPolicyValue ; 40 import org.omg.PortableServer.POAPackage.AdapterAlreadyExists ; 41 import org.omg.PortableServer.POAPackage.AdapterNonExistent ; 42 import org.omg.PortableServer.POAPackage.InvalidPolicy ; 43 import org.omg.PortableServer.POAPackage.WrongPolicy ; 44 import org.omg.PortableServer.POAPackage.WrongAdapter ; 45 import org.omg.PortableServer.POAPackage.NoServant ; 46 import org.omg.PortableServer.POAPackage.ServantAlreadyActive ; 47 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ; 48 import org.omg.PortableServer.POAPackage.ServantNotActive ; 49 import org.omg.PortableServer.POAPackage.ObjectNotActive ; 50 51 import org.omg.PortableInterceptor.ObjectReferenceFactory ; 52 import org.omg.PortableInterceptor.ObjectReferenceTemplate ; 53 import org.omg.PortableInterceptor.NON_EXISTENT ; 54 55 import org.omg.IOP.TAG_INTERNET_IOP ; 56 57 import com.sun.corba.se.spi.copyobject.CopierManager ; 58 import com.sun.corba.se.spi.copyobject.ObjectCopier ; 59 import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ; 60 import com.sun.corba.se.spi.oa.OADestroyed ; 61 import com.sun.corba.se.spi.oa.OAInvocationInfo ; 62 import com.sun.corba.se.spi.oa.ObjectAdapter ; 63 import com.sun.corba.se.spi.oa.ObjectAdapterBase ; 64 import com.sun.corba.se.spi.oa.ObjectAdapterFactory ; 65 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ; 66 import com.sun.corba.se.spi.ior.ObjectId ; 67 import com.sun.corba.se.spi.ior.ObjectAdapterId ; 68 import com.sun.corba.se.spi.ior.IOR ; 69 import com.sun.corba.se.spi.ior.IORFactories ; 70 import com.sun.corba.se.spi.ior.IORTemplate ; 71 import com.sun.corba.se.spi.ior.IORTemplateList ; 72 import com.sun.corba.se.spi.ior.TaggedProfile ; 73 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ; 74 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; 75 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ; 76 import com.sun.corba.se.spi.orb.ORB ; 77 import com.sun.corba.se.spi.protocol.ForwardException ; 78 import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor; 79 80 import com.sun.corba.se.impl.ior.POAObjectKeyTemplate ; 81 import com.sun.corba.se.impl.ior.ObjectAdapterIdArray ; 82 import com.sun.corba.se.impl.orbutil.ORBUtility; 83 import com.sun.corba.se.impl.orbutil.ORBConstants; 84 import com.sun.corba.se.impl.orbutil.concurrent.Sync ; 85 import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ; 86 import com.sun.corba.se.impl.orbutil.concurrent.ReentrantMutex ; 87 import com.sun.corba.se.impl.orbutil.concurrent.CondVar ; 88 89 98 public class POAImpl extends ObjectAdapterBase implements POA 99 { 100 private boolean debug ; 101 102 114 115 133 152 private static final int STATE_START = 0 ; private static final int STATE_INIT = 1 ; private static final int STATE_INIT_DONE = 2 ; private static final int STATE_RUN = 3 ; private static final int STATE_DESTROYING = 4 ; private static final int STATE_DESTROYED = 5 ; 159 private String stateToString() 160 { 161 switch (state) { 162 case STATE_START : 163 return "START" ; 164 case STATE_INIT : 165 return "INIT" ; 166 case STATE_INIT_DONE : 167 return "INIT_DONE" ; 168 case STATE_RUN : 169 return "RUN" ; 170 case STATE_DESTROYING : 171 return "DESTROYING" ; 172 case STATE_DESTROYED : 173 return "DESTROYED" ; 174 default : 175 return "UNKNOWN(" + state + ")" ; 176 } 177 } 178 179 private int state ; 181 182 private POAPolicyMediator mediator; 186 187 private int numLevels; private ObjectAdapterId poaId ; private String name; 192 private POAManagerImpl manager; private int uniquePOAId ; private POAImpl parent; private Map children; 200 private AdapterActivator activator; 201 private int invocationCount ; 203 206 Sync poaMutex ; 209 210 private CondVar adapterActivatorCV ; 212 213 private CondVar invokeCV ; 215 216 private CondVar beingDestroyedCV ; 218 219 protected ThreadLocal isDestroying ; 222 223 public String toString() 226 { 227 return "POA[" + poaId.toString() + 228 ", uniquePOAId=" + uniquePOAId + 229 ", state=" + stateToString() + 230 ", invocationCount=" + invocationCount + "]" ; 231 } 232 233 boolean getDebug() 235 { 236 return debug ; 237 } 238 239 static POAFactory getPOAFactory( ORB orb ) 241 { 242 return (POAFactory)orb.getRequestDispatcherRegistry(). 243 getObjectAdapterFactory( ORBConstants.TRANSIENT_SCID ) ; 244 } 245 246 static POAImpl makeRootPOA( ORB orb ) 248 { 249 POAManagerImpl poaManager = new POAManagerImpl( getPOAFactory( orb ), 250 orb.getPIHandler() ) ; 251 252 POAImpl result = new POAImpl( ORBConstants.ROOT_POA_NAME, 253 null, orb, STATE_START ) ; 254 result.initialize( poaManager, Policies.rootPOAPolicies ) ; 255 256 return result ; 257 } 258 259 int getPOAId() 261 { 262 return uniquePOAId ; 263 } 264 265 266 void lock() 268 { 269 SyncUtil.acquire( poaMutex ) ; 270 271 if (debug) { 272 ORBUtility.dprint( this, "LOCKED poa " + this ) ; 273 } 274 } 275 276 void unlock() 278 { 279 if (debug) { 280 ORBUtility.dprint( this, "UNLOCKED poa " + this ) ; 281 } 282 283 poaMutex.release() ; 284 } 285 286 Policies getPolicies() 288 { 289 return mediator.getPolicies() ; 290 } 291 292 private POAImpl( String name, POAImpl parent, ORB orb, int initialState ) 294 { 295 super( orb ) ; 296 297 debug = orb.poaDebugFlag ; 298 299 if (debug) { 300 ORBUtility.dprint( this, "Creating POA with name=" + name + 301 " parent=" + parent ) ; 302 } 303 304 this.state = initialState ; 305 this.name = name ; 306 this.parent = parent; 307 children = new HashMap (); 308 activator = null ; 309 310 uniquePOAId = getPOAFactory( orb ).newPOAId() ; 313 314 if (parent == null) { 315 numLevels = 1 ; 317 } else { 318 numLevels = parent.numLevels + 1 ; 320 321 parent.children.put(name, this); 322 } 323 324 String [] names = new String [ numLevels ] ; 327 POAImpl poaImpl = this ; 328 int ctr = numLevels - 1 ; 329 while (poaImpl != null) { 330 names[ctr--] = poaImpl.name ; 331 poaImpl = poaImpl.parent ; 332 } 333 334 poaId = new ObjectAdapterIdArray( names ) ; 335 336 invocationCount = 0; 337 338 poaMutex = new ReentrantMutex( orb.poaConcurrencyDebugFlag ) ; 339 340 adapterActivatorCV = new CondVar( poaMutex, 341 orb.poaConcurrencyDebugFlag ) ; 342 invokeCV = new CondVar( poaMutex, 343 orb.poaConcurrencyDebugFlag ) ; 344 beingDestroyedCV = new CondVar( poaMutex, 345 orb.poaConcurrencyDebugFlag ) ; 346 347 isDestroying = new ThreadLocal () { 348 protected java.lang.Object initialValue() { 349 return Boolean.FALSE; 350 } 351 }; 352 } 353 354 private void initialize( POAManagerImpl manager, Policies policies ) 356 { 357 if (debug) { 358 ORBUtility.dprint( this, "Initializing poa " + this + 359 " with POAManager=" + manager + " policies=" + policies ) ; 360 } 361 362 this.manager = manager; 363 manager.addPOA(this); 364 365 mediator = POAPolicyMediatorFactory.create( policies, this ) ; 366 367 int serverid = mediator.getServerId() ; 369 int scid = mediator.getScid() ; 370 String orbId = getORB().getORBData().getORBId(); 371 372 ObjectKeyTemplate oktemp = new POAObjectKeyTemplate( getORB(), 373 scid, serverid, orbId, poaId ) ; 374 375 if (debug) { 376 ORBUtility.dprint( this, "Initializing poa: oktemp=" + oktemp ) ; 377 } 378 379 boolean objectAdapterCreated = true; 384 initializeTemplate( oktemp, objectAdapterCreated, 387 policies, 388 null, null, oktemp.getObjectAdapterId() 391 ) ; 392 393 if (state == STATE_START) 394 state = STATE_RUN ; 395 else if (state == STATE_INIT) 396 state = STATE_INIT_DONE ; 397 else 398 throw lifecycleWrapper().illegalPoaStateTrans() ; 399 } 400 401 private boolean waitUntilRunning() 403 { 404 if (debug) { 405 ORBUtility.dprint( this, 406 "Calling waitUntilRunning on poa " + this ) ; 407 } 408 409 while (state < STATE_RUN) { 410 try { 411 adapterActivatorCV.await() ; 412 } catch (InterruptedException exc) { 413 } 415 } 416 417 if (debug) { 418 ORBUtility.dprint( this, 419 "Exiting waitUntilRunning on poa " + this ) ; 420 } 421 422 return (state == STATE_RUN) ; 425 } 426 427 private boolean destroyIfNotInitDone() 439 { 440 try { 441 lock() ; 442 443 if (debug) { 444 ORBUtility.dprint( this, 445 "Calling destroyIfNotInitDone on poa " + this ) ; 446 } 447 448 boolean success = (state == STATE_INIT_DONE) ; 449 450 if (success) 451 state = STATE_RUN ; 452 else { 453 DestroyThread destroyer = new DestroyThread( false, debug ); 457 destroyer.doIt( this, true ) ; 458 } 459 460 return success ; 461 } finally { 462 adapterActivatorCV.broadcast() ; 463 464 if (debug) { 465 ORBUtility.dprint( this, 466 "Exiting destroyIfNotInitDone on poa " + this ) ; 467 } 468 469 unlock() ; 470 } 471 } 472 473 private byte[] internalReferenceToId( 474 org.omg.CORBA.Object reference ) throws WrongAdapter 475 { 476 IOR ior = ORBUtility.getIOR( reference ) ; 477 IORTemplateList thisTemplate = ior.getIORTemplates() ; 478 479 ObjectReferenceFactory orf = getCurrentFactory() ; 480 IORTemplateList poaTemplate = 481 IORFactories.getIORTemplateList( orf ) ; 482 483 if (!poaTemplate.isEquivalent( thisTemplate )) 484 throw new WrongAdapter (); 485 486 Iterator iter = ior.iterator() ; 491 if (!iter.hasNext()) 492 throw iorWrapper().noProfilesInIor() ; 493 TaggedProfile prof = (TaggedProfile)(iter.next()) ; 494 ObjectId oid = prof.getObjectId() ; 495 496 return oid.getId(); 497 } 498 499 static class DestroyThread extends Thread { 502 private boolean wait ; 503 private boolean etherealize ; 504 private boolean debug ; 505 private POAImpl thePoa ; 506 507 public DestroyThread( boolean etherealize, boolean debug ) 508 { 509 this.etherealize = etherealize ; 510 this.debug = debug ; 511 } 512 513 public void doIt( POAImpl thePoa, boolean wait ) 514 { 515 if (debug) { 516 ORBUtility.dprint( this, 517 "Calling DestroyThread.doIt(thePOA=" + thePoa + 518 " wait=" + wait + " etherealize=" + etherealize ) ; 519 } 520 521 this.thePoa = thePoa ; 522 this.wait = wait ; 523 524 if (wait) { 525 run() ; 526 } else { 527 try { setDaemon(true); } catch (Exception e) {} 531 start() ; 532 } 533 } 534 535 public void run() 536 { 537 Set destroyedPOATemplates = new HashSet () ; 538 539 performDestroy( thePoa, destroyedPOATemplates ); 540 541 Iterator iter = destroyedPOATemplates.iterator() ; 542 ObjectReferenceTemplate [] orts = new ObjectReferenceTemplate [ 543 destroyedPOATemplates.size() ] ; 544 int index = 0 ; 545 while (iter.hasNext()) 546 orts[ index++ ] = (ObjectReferenceTemplate )iter.next(); 547 548 thePoa.getORB().getPIHandler().adapterStateChanged( orts, 549 NON_EXISTENT.value ) ; 550 } 551 552 private boolean prepareForDestruction( POAImpl poa, 556 Set destroyedPOATemplates ) 557 { 558 POAImpl[] childPoas = null ; 559 560 try { 563 poa.lock() ; 564 565 if (debug) { 566 ORBUtility.dprint( this, 567 "Calling performDestroy on poa " + poa ) ; 568 } 569 570 if (poa.state <= STATE_RUN) { 571 poa.state = STATE_DESTROYING ; 572 } else { 573 if (wait) 582 while (poa.state != STATE_DESTROYED) { 583 try { 584 poa.beingDestroyedCV.await() ; 585 } catch (InterruptedException exc) { 586 } 588 } 589 590 return false ; 591 } 592 593 poa.isDestroying.set(Boolean.TRUE); 594 595 childPoas = (POAImpl[])poa.children.values().toArray( 598 new POAImpl[0] ); 599 } finally { 600 poa.unlock() ; 601 } 602 603 607 for (int ctr=0; ctr<childPoas.length; ctr++ ) { 608 performDestroy( childPoas[ctr], destroyedPOATemplates ) ; 609 } 610 611 return true ; 612 } 613 614 public void performDestroy( POAImpl poa, Set destroyedPOATemplates ) 615 { 616 if (!prepareForDestruction( poa, destroyedPOATemplates )) 617 return ; 618 619 625 POAImpl parent = poa.parent ; 626 boolean isRoot = parent == null ; 627 628 try { 629 if (!isRoot) 633 parent.lock() ; 634 635 try { 636 poa.lock() ; 637 638 completeDestruction( poa, parent, 639 destroyedPOATemplates ) ; 640 } finally { 641 poa.unlock() ; 642 643 if (isRoot) 644 poa.manager.getFactory().registerRootPOA() ; 649 } 650 } finally { 651 if (!isRoot) { 652 parent.unlock() ; 653 poa.parent = null ; 654 } 655 } 656 } 657 658 private void completeDestruction( POAImpl poa, POAImpl parent, 659 Set destroyedPOATemplates ) 660 { 661 if (debug) { 662 ORBUtility.dprint( this, 663 "Calling completeDestruction on poa " + poa ) ; 664 } 665 666 try { 667 while (poa.invocationCount != 0) { 668 try { 669 poa.invokeCV.await() ; 670 } catch (InterruptedException ex) { 671 } 673 } 674 675 if (poa.mediator != null) { 676 if (etherealize) 677 poa.mediator.etherealizeAll(); 678 679 poa.mediator.clearAOM() ; 680 } 681 682 if (poa.manager != null) 683 poa.manager.removePOA(poa); 684 685 if (parent != null) 686 parent.children.remove( poa.name ) ; 687 688 destroyedPOATemplates.add( poa.getAdapterTemplate() ) ; 689 } catch (Throwable thr) { 690 if (thr instanceof ThreadDeath ) 691 throw (ThreadDeath )thr ; 692 693 poa.lifecycleWrapper().unexpectedException( thr, poa.toString() ) ; 694 } finally { 695 poa.state = STATE_DESTROYED ; 696 poa.beingDestroyedCV.broadcast(); 697 poa.isDestroying.set(Boolean.FALSE); 698 699 if (debug) { 700 ORBUtility.dprint( this, 701 "Exiting completeDestruction on poa " + poa ) ; 702 } 703 } 704 } 705 } 706 707 void etherealizeAll() 708 { 709 try { 710 lock() ; 711 712 if (debug) { 713 ORBUtility.dprint( this, 714 "Calling etheralizeAll on poa " + this ) ; 715 } 716 717 mediator.etherealizeAll() ; 718 } finally { 719 if (debug) { 720 ORBUtility.dprint( this, 721 "Exiting etheralizeAll on poa " + this ) ; 722 } 723 724 unlock() ; 725 } 726 } 727 728 732 736 public POA create_POA(String name, POAManager 737 theManager, Policy [] policies) throws AdapterAlreadyExists , 738 InvalidPolicy 739 { 740 try { 741 lock() ; 742 743 if (debug) { 744 ORBUtility.dprint( this, "Calling create_POA(name=" + name + 745 " theManager=" + theManager + " policies=" + policies + 746 ") on poa " + this ) ; 747 } 748 749 if (state > STATE_RUN) 752 throw omgLifecycleWrapper().createPoaDestroy() ; 753 754 POAImpl poa = (POAImpl)(children.get(name)) ; 755 756 if (poa == null) { 757 poa = new POAImpl( name, this, getORB(), STATE_START ) ; 758 } 759 760 try { 761 poa.lock() ; 762 763 if (debug) { 764 ORBUtility.dprint( this, 765 "Calling create_POA: new poa is " + poa ) ; 766 } 767 768 if ((poa.state != STATE_START) && (poa.state != STATE_INIT)) 769 throw new AdapterAlreadyExists (); 770 771 POAManagerImpl newManager = (POAManagerImpl)theManager ; 772 if (newManager == null) 773 newManager = new POAManagerImpl( manager.getFactory(), 774 manager.getPIHandler() ); 775 776 int defaultCopierId = 777 getORB().getCopierManager().getDefaultId() ; 778 Policies POAPolicies = 779 new Policies( policies, defaultCopierId ) ; 780 781 poa.initialize( newManager, POAPolicies ) ; 782 783 return poa; 784 } finally { 785 poa.unlock() ; 786 } 787 } finally { 788 unlock() ; 789 } 790 } 791 792 796 public POA find_POA(String name, boolean activate) 797 throws AdapterNonExistent 798 { 799 POAImpl found = null ; 800 AdapterActivator act = null ; 801 802 lock() ; 803 804 if (debug) { 805 ORBUtility.dprint( this, "Calling find_POA(name=" + name + 806 " activate=" + activate + ") on poa " + this ) ; 807 } 808 809 found = (POAImpl) children.get(name); 810 811 if (found != null) { 812 if (debug) { 813 ORBUtility.dprint( this, 814 "Calling find_POA: found poa " + found ) ; 815 } 816 817 try { 818 found.lock() ; 819 820 unlock() ; 823 824 if (!found.waitUntilRunning()) 829 throw omgLifecycleWrapper().poaDestroyed() ; 830 831 } finally { 835 found.unlock() ; 836 } 837 } else { 838 try { 839 if (debug) { 840 ORBUtility.dprint( this, 841 "Calling find_POA: no poa found" ) ; 842 } 843 844 if (activate && (activator != null)) { 845 found = new POAImpl( name, this, getORB(), STATE_INIT ) ; 859 860 if (debug) { 861 ORBUtility.dprint( this, 862 "Calling find_POA: created poa " + found ) ; 863 } 864 865 act = activator ; 866 } else { 867 throw new AdapterNonExistent (); 868 } 869 } finally { 870 unlock() ; 871 } 872 } 873 874 877 881 if (act != null) { 882 boolean status = false ; 883 boolean adapterResult = false ; 884 885 if (debug) { 886 ORBUtility.dprint( this, 887 "Calling find_POA: calling AdapterActivator" ) ; 888 } 889 890 try { 891 synchronized (act) { 894 status = act.unknown_adapter(this, name); 895 } 896 } catch (SystemException exc) { 897 throw omgLifecycleWrapper().adapterActivatorException( exc, 898 name, poaId.toString() ) ; 899 } catch (Throwable thr) { 900 lifecycleWrapper().unexpectedException( thr, this.toString() ) ; 903 904 if (thr instanceof ThreadDeath ) 905 throw (ThreadDeath )thr ; 906 } finally { 907 adapterResult = found.destroyIfNotInitDone() ; 913 } 914 915 if (status) { 916 if (!adapterResult) 917 throw omgLifecycleWrapper().adapterActivatorException( name, 918 poaId.toString() ) ; 919 } else { 920 if (debug) { 921 ORBUtility.dprint( this, 922 "Calling find_POA: AdapterActivator returned false" ) ; 923 } 924 925 throw new AdapterNonExistent (); 928 } 929 } 930 931 return found; 932 } 933 934 938 public void destroy(boolean etherealize, boolean wait_for_completion) 939 { 940 if (wait_for_completion && getORB().isDuringDispatch()) { 942 throw lifecycleWrapper().destroyDeadlock() ; 943 } 944 945 DestroyThread destroyer = new DestroyThread( etherealize, debug ); 946 destroyer.doIt( this, wait_for_completion ) ; 947 } 948 949 953 public ThreadPolicy create_thread_policy( 954 ThreadPolicyValue value) 955 { 956 return new ThreadPolicyImpl(value); 957 } 958 959 963 public LifespanPolicy create_lifespan_policy( 964 LifespanPolicyValue value) 965 { 966 return new LifespanPolicyImpl(value); 967 } 968 969 973 public IdUniquenessPolicy create_id_uniqueness_policy( 974 IdUniquenessPolicyValue value) 975 { 976 return new IdUniquenessPolicyImpl(value); 977 } 978 979 983 public IdAssignmentPolicy create_id_assignment_policy( 984 IdAssignmentPolicyValue value) 985 { 986 return new IdAssignmentPolicyImpl(value); 987 } 988 989 993 public ImplicitActivationPolicy create_implicit_activation_policy( 994 ImplicitActivationPolicyValue value) 995 { 996 return new ImplicitActivationPolicyImpl(value); 997 } 998 999 1003 public ServantRetentionPolicy create_servant_retention_policy( 1004 ServantRetentionPolicyValue value) 1005 { 1006 return new ServantRetentionPolicyImpl(value); 1007 } 1008 1009 1013 public RequestProcessingPolicy create_request_processing_policy( 1014 RequestProcessingPolicyValue value) 1015 { 1016 return new RequestProcessingPolicyImpl(value); 1017 } 1018 1019 1023 public String the_name() 1024 { 1025 try { 1026 lock() ; 1027 1028 return name; 1029 } finally { 1030 unlock() ; 1031 } 1032 } 1033 1034 1038 public POA the_parent() 1039 { 1040 try { 1041 lock() ; 1042 1043 return parent; 1044 } finally { 1045 unlock() ; 1046 } 1047 } 1048 1049 1052 public org.omg.PortableServer.POA [] the_children() 1053 { 1054 try { 1055 lock() ; 1056 1057 Collection coll = children.values() ; 1058 int size = coll.size() ; 1059 POA [] result = new POA [ size ] ; 1060 int index = 0 ; 1061 Iterator iter = coll.iterator() ; 1062 while (iter.hasNext()) { 1063 POA poa = (POA )(iter.next()) ; 1064 result[ index++ ] = poa ; 1065 } 1066 1067 return result ; 1068 } finally { 1069 unlock() ; 1070 } 1071 } 1072 1073 1077 public POAManager the_POAManager() 1078 { 1079 try { 1080 lock() ; 1081 1082 return manager; 1083 } finally { 1084 unlock() ; 1085 } 1086 } 1087 1088 1092 public AdapterActivator the_activator() 1093 { 1094 try { 1095 lock() ; 1096 1097 return activator; 1098 } finally { 1099 unlock() ; 1100 } 1101 } 1102 1103 1107 public void the_activator(AdapterActivator activator) 1108 { 1109 try { 1110 lock() ; 1111 1112 if (debug) { 1113 ORBUtility.dprint( this, "Calling the_activator on poa " + 1114 this + " activator=" + activator ) ; 1115 } 1116 1117 this.activator = activator; 1118 } finally { 1119 unlock() ; 1120 } 1121 } 1122 1123 1127 public ServantManager get_servant_manager() throws WrongPolicy 1128 { 1129 try { 1130 lock() ; 1131 1132 return mediator.getServantManager() ; 1133 } finally { 1134 unlock() ; 1135 } 1136 } 1137 1138 1142 public void set_servant_manager(ServantManager servantManager) 1143 throws WrongPolicy 1144 { 1145 try { 1146 lock() ; 1147 1148 if (debug) { 1149 ORBUtility.dprint( this, "Calling set_servant_manager on poa " + 1150 this + " servantManager=" + servantManager ) ; 1151 } 1152 1153 mediator.setServantManager( servantManager ) ; 1154 } finally { 1155 unlock() ; 1156 } 1157 } 1158 1159 1163 public Servant get_servant() throws NoServant , WrongPolicy 1164 { 1165 try { 1166 lock() ; 1167 1168 return mediator.getDefaultServant() ; 1169 } finally { 1170 unlock() ; 1171 } 1172 } 1173 1174 1178 public void set_servant(Servant defaultServant) 1179 throws WrongPolicy 1180 { 1181 try { 1182 lock() ; 1183 1184 if (debug) { 1185 ORBUtility.dprint( this, "Calling set_servant on poa " + 1186 this + " defaultServant=" + defaultServant ) ; 1187 } 1188 1189 mediator.setDefaultServant( defaultServant ) ; 1190 } finally { 1191 unlock() ; 1192 } 1193 } 1194 1195 1199 public byte[] activate_object(Servant servant) 1200 throws ServantAlreadyActive , WrongPolicy 1201 { 1202 try { 1203 lock() ; 1204 1205 if (debug) { 1206 ORBUtility.dprint( this, 1207 "Calling activate_object on poa " + this + 1208 " (servant=" + servant + ")" ) ; 1209 } 1210 1211 byte[] id = mediator.newSystemId(); 1215 1216 try { 1217 mediator.activateObject( id, servant ) ; 1218 } catch (ObjectAlreadyActive oaa) { 1219 } 1223 1224 return id ; 1225 } finally { 1226 if (debug) { 1227 ORBUtility.dprint( this, 1228 "Exiting activate_object on poa " + this ) ; 1229 } 1230 1231 unlock() ; 1232 } 1233 } 1234 1235 1239 public void activate_object_with_id(byte[] id, 1240 Servant servant) 1241 throws ObjectAlreadyActive , ServantAlreadyActive , WrongPolicy 1242 { 1243 try { 1244 lock() ; 1245 1246 if (debug) { 1247 ORBUtility.dprint( this, 1248 "Calling activate_object_with_id on poa " + this + 1249 " (servant=" + servant + " id=" + id + ")" ) ; 1250 } 1251 1252 byte[] idClone = (byte[])(id.clone()) ; 1255 1256 mediator.activateObject( idClone, servant ) ; 1257 } finally { 1258 if (debug) { 1259 ORBUtility.dprint( this, 1260 "Exiting activate_object_with_id on poa " + this ) ; 1261 } 1262 1263 unlock() ; 1264 } 1265 } 1266 1267 1271 public void deactivate_object(byte[] id) 1272 throws ObjectNotActive , WrongPolicy 1273 { 1274 try { 1275 lock() ; 1276 1277 if (debug) { 1278 ORBUtility.dprint( this, 1279 "Calling deactivate_object on poa " + this + 1280 " (id=" + id + ")" ) ; 1281 } 1282 1283 mediator.deactivateObject( id ) ; 1284 } finally { 1285 if (debug) { 1286 ORBUtility.dprint( this, 1287 "Exiting deactivate_object on poa " + this ) ; 1288 } 1289 1290 unlock() ; 1291 } 1292 } 1293 1294 1298 public org.omg.CORBA.Object create_reference(String repId) 1299 throws WrongPolicy 1300 { 1301 try { 1302 lock() ; 1303 1304 if (debug) { 1305 ORBUtility.dprint( this, "Calling create_reference(repId=" + 1306 repId + ") on poa " + this ) ; 1307 } 1308 1309 return makeObject( repId, mediator.newSystemId()) ; 1310 } finally { 1311 unlock() ; 1312 } 1313 } 1314 1315 1319 public org.omg.CORBA.Object 1320 create_reference_with_id(byte[] oid, String repId) 1321 { 1322 try { 1323 lock() ; 1324 1325 if (debug) { 1326 ORBUtility.dprint( this, 1327 "Calling create_reference_with_id(oid=" + 1328 oid + " repId=" + repId + ") on poa " + this ) ; 1329 } 1330 1331 byte[] idClone = (byte[])(oid.clone()) ; 1334 1335 return makeObject( repId, idClone ) ; 1336 } finally { 1337 unlock() ; 1338 } 1339 } 1340 1341 1345 public byte[] servant_to_id(Servant servant) 1346 throws ServantNotActive , WrongPolicy 1347 { 1348 try { 1349 lock() ; 1350 1351 if (debug) { 1352 ORBUtility.dprint( this, "Calling servant_to_id(servant=" + 1353 servant + ") on poa " + this ) ; 1354 } 1355 1356 return mediator.servantToId( servant ) ; 1357 } finally { 1358 unlock() ; 1359 } 1360 } 1361 1362 1366 public org.omg.CORBA.Object servant_to_reference(Servant servant) 1367 throws ServantNotActive , WrongPolicy 1368 { 1369 try { 1370 lock() ; 1371 1372 if (debug) { 1373 ORBUtility.dprint( this, 1374 "Calling servant_to_reference(servant=" + 1375 servant + ") on poa " + this ) ; 1376 } 1377 1378 byte[] oid = mediator.servantToId(servant); 1379 String repId = servant._all_interfaces( this, oid )[0] ; 1380 return create_reference_with_id(oid, repId); 1381 } finally { 1382 unlock() ; 1383 } 1384 } 1385 1386 1390 public Servant reference_to_servant(org.omg.CORBA.Object reference) 1391 throws ObjectNotActive , WrongPolicy , WrongAdapter 1392 { 1393 try { 1394 lock() ; 1395 1396 if (debug) { 1397 ORBUtility.dprint( this, 1398 "Calling reference_to_servant(reference=" + 1399 reference + ") on poa " + this ) ; 1400 } 1401 1402 if ( state >= STATE_DESTROYING ) { 1403 throw lifecycleWrapper().adapterDestroyed() ; 1404 } 1405 1406 byte [] id = internalReferenceToId(reference); 1409 1410 return mediator.idToServant( id ) ; 1411 } finally { 1412 unlock() ; 1413 } 1414 } 1415 1416 1420 public byte[] reference_to_id(org.omg.CORBA.Object reference) 1421 throws WrongAdapter , WrongPolicy 1422 { 1423 try { 1424 lock() ; 1425 1426 if (debug) { 1427 ORBUtility.dprint( this, "Calling reference_to_id(reference=" + 1428 reference + ") on poa " + this ) ; 1429 } 1430 1431 if( state >= STATE_DESTROYING ) { 1432 throw lifecycleWrapper().adapterDestroyed() ; 1433 } 1434 1435 return internalReferenceToId( reference ) ; 1436 } finally { 1437 unlock() ; 1438 } 1439 } 1440 1441 1445 public Servant id_to_servant(byte[] id) 1446 throws ObjectNotActive , WrongPolicy 1447 { 1448 try { 1449 lock() ; 1450 1451 if (debug) { 1452 ORBUtility.dprint( this, "Calling id_to_servant(id=" + 1453 id + ") on poa " + this ) ; 1454 } 1455 1456 if( state >= STATE_DESTROYING ) { 1457 throw lifecycleWrapper().adapterDestroyed() ; 1458 } 1459 return mediator.idToServant( id ) ; 1460 } finally { 1461 unlock() ; 1462 } 1463 } 1464 1465 1469 public org.omg.CORBA.Object id_to_reference(byte[] id) 1470 throws ObjectNotActive , WrongPolicy 1471 1472 { 1473 try { 1474 lock() ; 1475 1476 if (debug) { 1477 ORBUtility.dprint( this, "Calling id_to_reference(id=" + 1478 id + ") on poa " + this ) ; 1479 } 1480 1481 if( state >= STATE_DESTROYING ) { 1482 throw lifecycleWrapper().adapterDestroyed() ; 1483 } 1484 1485 Servant s = mediator.idToServant( id ) ; 1486 String repId = s._all_interfaces( this, id )[0] ; 1487 return makeObject(repId, id ); 1488 } finally { 1489 unlock() ; 1490 } 1491 } 1492 1493 1497 public byte[] id() 1498 { 1499 try { 1500 lock() ; 1501 1502 return getAdapterId() ; 1503 } finally { 1504 unlock() ; 1505 } 1506 } 1507 1508 1512 public Policy getEffectivePolicy( int type ) 1513 { 1514 return mediator.getPolicies().get_effective_policy( type ) ; 1515 } 1516 1517 public int getManagerId() 1518 { 1519 return manager.getManagerId() ; 1520 } 1521 1522 public short getState() 1523 { 1524 return manager.getORTState() ; 1525 } 1526 1527 public String [] getInterfaces( java.lang.Object servant, byte[] objectId ) 1528 { 1529 Servant serv = (Servant )servant ; 1530 return serv._all_interfaces( this, objectId ) ; 1531 } 1532 1533 protected ObjectCopierFactory getObjectCopierFactory() 1534 { 1535 int copierId = mediator.getPolicies().getCopierId() ; 1536 CopierManager cm = getORB().getCopierManager() ; 1537 return cm.getObjectCopierFactory( copierId ) ; 1538 } 1539 1540 public void enter() throws OADestroyed 1541 { 1542 try { 1543 lock() ; 1544 1545 if (debug) { 1546 ORBUtility.dprint( this, "Calling enter on poa " + this ) ; 1547 } 1548 1549 while ((state == STATE_DESTROYING) && 1555 (isDestroying.get() == Boolean.FALSE)) { 1556 try { 1557 beingDestroyedCV.await(); 1558 } catch (InterruptedException ex) { 1559 } 1561 } 1562 1563 if (!waitUntilRunning()) 1564 throw new OADestroyed() ; 1565 1566 invocationCount++; 1567 } finally { 1568 if (debug) { 1569 ORBUtility.dprint( this, "Exiting enter on poa " + this ) ; 1570 } 1571 1572 unlock() ; 1573 } 1574 1575 manager.enter(); 1576 } 1577 1578 public void exit() 1579 { 1580 try { 1581 lock() ; 1582 1583 if (debug) { 1584 ORBUtility.dprint( this, "Calling exit on poa " + this ) ; 1585 } 1586 1587 invocationCount--; 1588 1589 if ((invocationCount == 0) && (state == STATE_DESTROYING)) { 1590 invokeCV.broadcast(); 1591 } 1592 } finally { 1593 if (debug) { 1594 ORBUtility.dprint( this, "Exiting exit on poa " + this ) ; 1595 } 1596 1597 unlock() ; 1598 } 1599 1600 manager.exit(); 1601 } 1602 1603 public void getInvocationServant( OAInvocationInfo info ) 1604 { 1605 try { 1606 lock() ; 1607 1608 if (debug) { 1609 ORBUtility.dprint( this, 1610 "Calling getInvocationServant on poa " + this ) ; 1611 } 1612 1613 java.lang.Object servant = null ; 1614 1615 try { 1616 servant = mediator.getInvocationServant( info.id(), 1617 info.getOperation() ); 1618 } catch (ForwardRequest freq) { 1619 throw new ForwardException( getORB(), freq.forward_reference ) ; 1620 } 1621 1622 info.setServant( servant ) ; 1623 } finally { 1624 if (debug) { 1625 ORBUtility.dprint( this, 1626 "Exiting getInvocationServant on poa " + this ) ; 1627 } 1628 1629 unlock() ; 1630 } 1631 } 1632 1633 public org.omg.CORBA.Object getLocalServant( byte[] objectId ) 1634 { 1635 return null ; 1636 } 1637 1638 1643 public void returnServant() 1644 { 1645 try { 1646 lock() ; 1647 1648 if (debug) { 1649 ORBUtility.dprint( this, 1650 "Calling returnServant on poa " + this ) ; 1651 } 1652 1653 mediator.returnServant(); 1654 } catch (Throwable thr) { 1655 if (debug) { 1656 ORBUtility.dprint( this, 1657 "Exception " + thr + " in returnServant on poa " + this ) ; 1658 } 1659 1660 if (thr instanceof Error ) 1661 throw (Error )thr ; 1662 else if (thr instanceof RuntimeException ) 1663 throw (RuntimeException )thr ; 1664 1665 } finally { 1666 if (debug) { 1667 ORBUtility.dprint( this, 1668 "Exiting returnServant on poa " + this ) ; 1669 } 1670 1671 unlock() ; 1672 } 1673 } 1674} 1675 | Popular Tags |