src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAManagerImpl.java

Print this page




  31 import java.util.HashSet;
  32 
  33 import org.omg.CORBA.LocalObject;
  34 import org.omg.CORBA.CompletionStatus ;
  35 
  36 import org.omg.PortableServer.POAManager;
  37 import org.omg.PortableServer.POAManagerPackage.State;
  38 import org.omg.PortableServer.POA;
  39 
  40 import org.omg.PortableInterceptor.DISCARDING ;
  41 import org.omg.PortableInterceptor.ACTIVE ;
  42 import org.omg.PortableInterceptor.HOLDING ;
  43 import org.omg.PortableInterceptor.INACTIVE ;
  44 import org.omg.PortableInterceptor.NON_EXISTENT ;
  45 
  46 import com.sun.corba.se.spi.protocol.PIHandler ;
  47 
  48 import com.sun.corba.se.impl.logging.POASystemException ;
  49 
  50 import com.sun.corba.se.impl.orbutil.ORBUtility ;
  51 import com.sun.corba.se.impl.transport.ManagedLocalsThread;
  52 
  53 /** POAManagerImpl is the implementation of the POAManager interface.
  54  *  Its public methods are activate(), hold_requests(), discard_requests()
  55  *  and deactivate().
  56  */
  57 
  58 public class POAManagerImpl extends org.omg.CORBA.LocalObject implements
  59     POAManager
  60 {
  61     private final POAFactory factory ;  // factory which contains global state
  62                                         // for all POAManagers
  63     private PIHandler pihandler ;       // for adapterManagerStateChanged
  64     private State state;                // current state of this POAManager
  65     private Set poas = new HashSet(4) ; // all poas controlled by this POAManager
  66     private int nInvocations=0;         // Number of invocations in progress
  67     private int nWaiters=0;             // Number of threads waiting for
  68                                         // invocations to complete
  69     private int myId = 0 ;              // This POAManager's ID
  70     private boolean debug ;
  71     private boolean explicitStateChange ; // initially false, set true as soon as


 341                 if ( state.value() == State._INACTIVE )
 342                     throw new org.omg.PortableServer.POAManagerPackage.AdapterInactive();
 343 
 344                 state = State.INACTIVE;
 345 
 346                 pihandler.adapterManagerStateChanged( myId, getORTState() ) ;
 347 
 348                 // Notify any invocations that were waiting because the previous
 349                 // state was HOLDING. Those invocations will then be rejected with
 350                 // an OBJ_ADAPTER exception. Also notify any threads that were waiting
 351                 // inside hold_requests() or discard_requests().
 352                 notifyWaiters();
 353             }
 354 
 355             POAManagerDeactivator deactivator = new POAManagerDeactivator( this,
 356                 etherealize_objects, debug ) ;
 357 
 358             if (wait_for_completion)
 359                 deactivator.run() ;
 360             else {
 361                 Thread thr = new ManagedLocalsThread(deactivator) ;
 362                 thr.start() ;
 363             }
 364         } finally {
 365             synchronized(this) {
 366                 if (debug) {
 367                     ORBUtility.dprint( this,
 368                         "Exiting deactivate on POAManager " + this ) ;
 369                 }
 370             }
 371         }
 372     }
 373 
 374     private class POAManagerDeactivator implements Runnable
 375     {
 376         private boolean etherealize_objects ;
 377         private POAManagerImpl pmi ;
 378         private boolean debug ;
 379 
 380         POAManagerDeactivator( POAManagerImpl pmi, boolean etherealize_objects,
 381             boolean debug )




  31 import java.util.HashSet;
  32 
  33 import org.omg.CORBA.LocalObject;
  34 import org.omg.CORBA.CompletionStatus ;
  35 
  36 import org.omg.PortableServer.POAManager;
  37 import org.omg.PortableServer.POAManagerPackage.State;
  38 import org.omg.PortableServer.POA;
  39 
  40 import org.omg.PortableInterceptor.DISCARDING ;
  41 import org.omg.PortableInterceptor.ACTIVE ;
  42 import org.omg.PortableInterceptor.HOLDING ;
  43 import org.omg.PortableInterceptor.INACTIVE ;
  44 import org.omg.PortableInterceptor.NON_EXISTENT ;
  45 
  46 import com.sun.corba.se.spi.protocol.PIHandler ;
  47 
  48 import com.sun.corba.se.impl.logging.POASystemException ;
  49 
  50 import com.sun.corba.se.impl.orbutil.ORBUtility ;

  51 
  52 /** POAManagerImpl is the implementation of the POAManager interface.
  53  *  Its public methods are activate(), hold_requests(), discard_requests()
  54  *  and deactivate().
  55  */
  56 
  57 public class POAManagerImpl extends org.omg.CORBA.LocalObject implements
  58     POAManager
  59 {
  60     private final POAFactory factory ;  // factory which contains global state
  61                                         // for all POAManagers
  62     private PIHandler pihandler ;       // for adapterManagerStateChanged
  63     private State state;                // current state of this POAManager
  64     private Set poas = new HashSet(4) ; // all poas controlled by this POAManager
  65     private int nInvocations=0;         // Number of invocations in progress
  66     private int nWaiters=0;             // Number of threads waiting for
  67                                         // invocations to complete
  68     private int myId = 0 ;              // This POAManager's ID
  69     private boolean debug ;
  70     private boolean explicitStateChange ; // initially false, set true as soon as


 340                 if ( state.value() == State._INACTIVE )
 341                     throw new org.omg.PortableServer.POAManagerPackage.AdapterInactive();
 342 
 343                 state = State.INACTIVE;
 344 
 345                 pihandler.adapterManagerStateChanged( myId, getORTState() ) ;
 346 
 347                 // Notify any invocations that were waiting because the previous
 348                 // state was HOLDING. Those invocations will then be rejected with
 349                 // an OBJ_ADAPTER exception. Also notify any threads that were waiting
 350                 // inside hold_requests() or discard_requests().
 351                 notifyWaiters();
 352             }
 353 
 354             POAManagerDeactivator deactivator = new POAManagerDeactivator( this,
 355                 etherealize_objects, debug ) ;
 356 
 357             if (wait_for_completion)
 358                 deactivator.run() ;
 359             else {
 360                 Thread thr = new sun.misc.ManagedLocalsThread(deactivator) ;
 361                 thr.start() ;
 362             }
 363         } finally {
 364             synchronized(this) {
 365                 if (debug) {
 366                     ORBUtility.dprint( this,
 367                         "Exiting deactivate on POAManager " + this ) ;
 368                 }
 369             }
 370         }
 371     }
 372 
 373     private class POAManagerDeactivator implements Runnable
 374     {
 375         private boolean etherealize_objects ;
 376         private POAManagerImpl pmi ;
 377         private boolean debug ;
 378 
 379         POAManagerDeactivator( POAManagerImpl pmi, boolean etherealize_objects,
 380             boolean debug )