FileDocCategorySizeDatePackage
POAManagerImpl.javaAPI DocJava SE 5 API13900Fri Aug 26 14:54:26 BST 2005com.sun.corba.se.impl.oa.poa

POAManagerImpl

public class POAManagerImpl extends LocalObject implements POAManager
POAManagerImpl is the implementation of the POAManager interface. Its public methods are activate(), hold_requests(), discard_requests() and deactivate().

Fields Summary
private final POAFactory
factory
private PIHandler
pihandler
private State
state
private Set
poas
private int
nInvocations
private int
nWaiters
private int
myId
private boolean
debug
private boolean
explicitStateChange
Constructors Summary
POAManagerImpl(POAFactory factory, PIHandler pihandler)

	this.factory = factory ;
        factory.addPoaManager(this);
	this.pihandler = pihandler ;
	myId = factory.newPOAManagerId() ;
	state = State.HOLDING;
	debug = factory.getORB().poaDebugFlag ;
	explicitStateChange = false ;

	if (debug) {
	    ORBUtility.dprint( this, "Creating POAManagerImpl " + this ) ;
	}
    
Methods Summary
public synchronized voidactivate()
activate Spec: pages 3-14 thru 3-18

	explicitStateChange = true ;

	if (debug) {
	    ORBUtility.dprint( this, 
		"Calling activate on POAManager " + this ) ;
	}

	try {
	    if ( state.value() == State._INACTIVE )
		throw new org.omg.PortableServer.POAManagerPackage.AdapterInactive();

	    // set the state to ACTIVE
	    state = State.ACTIVE;
	    
	    pihandler.adapterManagerStateChanged( myId, getORTState() ) ;

	    // Notify any invocations that were waiting because the previous
	    // state was HOLDING, as well as notify any threads that were waiting
	    // inside hold_requests() or discard_requests(). 
	    notifyWaiters();
	} finally {
	    if (debug) {
		ORBUtility.dprint( this, 
		    "Exiting activate on POAManager " + this ) ;
	    }
	}
    
synchronized voidaddPOA(org.omg.PortableServer.POA poa)

	// XXX This is probably not the correct error
	if (state.value() == State._INACTIVE) {
	    POASystemException wrapper = factory.getWrapper();
	    throw wrapper.addPoaInactive( CompletionStatus.COMPLETED_NO ) ;
	}
	    
        poas.add(poa);
    
synchronized voidcheckIfActive()
The following methods are used on the invocation path.

	try {
	    if (debug) {
		ORBUtility.dprint( this,
		    "Calling checkIfActive for POAManagerImpl " + this ) ;
	    } 

	    checkState();
	} finally {
	    if (debug) {
		ORBUtility.dprint( this,
		    "Exiting checkIfActive for POAManagerImpl " + this ) ;
	    } 
	}
    
private voidcheckState()

	while ( state.value() != State._ACTIVE ) {
	    switch ( state.value() ) {
		case State._HOLDING:
		    while ( state.value() == State._HOLDING ) {
			countedWait() ;
		    }
		    break;

		case State._DISCARDING:
		    throw factory.getWrapper().poaDiscarding() ;

		case State._INACTIVE:
		    throw factory.getWrapper().poaInactive() ;
	    }
	}
    
private voidcountedWait()

	try {
	    if (debug) {
		ORBUtility.dprint( this, "Calling countedWait on POAManager " +
		    this + " nWaiters=" + nWaiters ) ;
	    }

	    nWaiters++ ;
	    wait(); 
	} catch ( java.lang.InterruptedException ex ) {
	    // NOP
	} finally {
	    nWaiters-- ;

	    if (debug) {
		ORBUtility.dprint( this, "Exiting countedWait on POAManager " +
		    this + " nWaiters=" + nWaiters ) ;
	    }
	}
    
public voiddeactivate(boolean etherealize_objects, boolean wait_for_completion)
deactivate Spec: pages 3-14 thru 3-18 Note: INACTIVE is a permanent state.

	explicitStateChange = true ;

	try {
	    synchronized( this ) {
		if (debug) {
		    ORBUtility.dprint( this, 
			"Calling deactivate on POAManager " + this ) ;
		}

		if ( state.value() == State._INACTIVE )
		    throw new org.omg.PortableServer.POAManagerPackage.AdapterInactive();

		state = State.INACTIVE;

		pihandler.adapterManagerStateChanged( myId, getORTState() ) ;

		// Notify any invocations that were waiting because the previous
		// state was HOLDING. Those invocations will then be rejected with
		// an OBJ_ADAPTER exception. Also notify any threads that were waiting
		// inside hold_requests() or discard_requests().
		notifyWaiters();
	    }

	    POAManagerDeactivator deactivator = new POAManagerDeactivator( this,
		etherealize_objects, debug ) ;

	    if (wait_for_completion)
		deactivator.run() ;
	    else {
		Thread thr = new Thread(deactivator) ;
		thr.start() ;
	    }
	} finally { 
	    synchronized(this) {
		if (debug) {
		    ORBUtility.dprint( this, 
			"Exiting deactivate on POAManager " + this ) ;
		}
	    }
	}
    
public synchronized voiddiscard_requests(boolean wait_for_completion)
discard_requests Spec: pages 3-14 thru 3-18

	explicitStateChange = true ;

	if (debug) {
	    ORBUtility.dprint( this, 
		"Calling hold_requests on POAManager " + this ) ;
	}
	 
	try {
	    if ( state.value() == State._INACTIVE )
		throw new org.omg.PortableServer.POAManagerPackage.AdapterInactive();

	    // set the state to DISCARDING
	    state = State.DISCARDING;

	    pihandler.adapterManagerStateChanged( myId, getORTState() ) ;

	    // Notify any invocations that were waiting because the previous
	    // state was HOLDING. Those invocations will henceforth be rejected with
	    // a TRANSIENT exception. Also notify any threads that were waiting
	    // inside hold_requests().
	    notifyWaiters(); 

	    if ( wait_for_completion ) {
		while ( state.value() == State._DISCARDING && nInvocations > 0 ) {
		    countedWait() ;
		}
	    }
	} finally {
	    if (debug) {
		ORBUtility.dprint( this, 
		    "Exiting hold_requests on POAManager " + this ) ;
	    }
	}
    
synchronized voidenter()

	try {
	    if (debug) {
		ORBUtility.dprint( this,
		    "Calling enter for POAManagerImpl " + this ) ;
	    } 

	    checkState();
	    nInvocations++;
	} finally {
	    if (debug) {
		ORBUtility.dprint( this,
		    "Exiting enter for POAManagerImpl " + this ) ;
	    } 
	}
    
synchronized voidexit()

	try {
	    if (debug) {
		ORBUtility.dprint( this,
		    "Calling exit for POAManagerImpl " + this ) ;
	    } 

	    nInvocations--; 

	    if ( nInvocations == 0 ) {
		// This notifies any threads that were in the 
		// wait_for_completion loop in hold/discard/deactivate().
		notifyWaiters();
	    }
	} finally {
	    if (debug) {
		ORBUtility.dprint( this,
		    "Exiting exit for POAManagerImpl " + this ) ;
	    } 
	}
    
com.sun.corba.se.impl.oa.poa.POAFactorygetFactory()

	return factory ;
    
public intgetManagerId()

	return myId ;
    
public shortgetORTState()

	switch (state.value()) {
	    case State._HOLDING    : return HOLDING.value ;
	    case State._ACTIVE     : return ACTIVE.value ;
	    case State._INACTIVE   : return INACTIVE.value ;
	    case State._DISCARDING : return DISCARDING.value ;
	    default		   : return NON_EXISTENT.value ;
	}
    
com.sun.corba.se.spi.protocol.PIHandlergetPIHandler()

	return pihandler ;
    
public org.omg.PortableServer.POAManagerPackage.Stateget_state()
Added according to the spec CORBA V2.3; this returns the state of the POAManager

	return state;
    
public synchronized voidhold_requests(boolean wait_for_completion)
hold_requests Spec: pages 3-14 thru 3-18

	explicitStateChange = true ;

	if (debug) {
	    ORBUtility.dprint( this, 
		"Calling hold_requests on POAManager " + this ) ;
	}

	try {
	    if ( state.value() == State._INACTIVE )
		throw new org.omg.PortableServer.POAManagerPackage.AdapterInactive();
	    // set the state to HOLDING
	    state  = State.HOLDING;

	    pihandler.adapterManagerStateChanged( myId, getORTState() ) ;

	    // Notify any threads that were waiting in the wait() inside
	    // discard_requests. This will cause discard_requests to return
	    // (which is in conformance with the spec).
	    notifyWaiters(); 

	    if ( wait_for_completion ) {
		while ( state.value() == State._HOLDING && nInvocations > 0 ) {
		    countedWait() ;
		}
	    }
	} finally {
	    if (debug) {
		ORBUtility.dprint( this, 
		    "Exiting hold_requests on POAManager " + this ) ;
	    }
	}
    
public synchronized voidimplicitActivation()
Activate the POAManager if no explicit state change has ever been previously invoked.

	if (!explicitStateChange)
	    try {
		activate() ;
	    } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ai) {
		// ignore the exception.
	    }
    
private voidnotifyWaiters()

	if (debug) {
	    ORBUtility.dprint( this, "Calling notifyWaiters on POAManager " +
		this + " nWaiters=" + nWaiters ) ;
	}

	if (nWaiters >0)
	    notifyAll() ;
    
synchronized voidremovePOA(org.omg.PortableServer.POA poa)

        poas.remove(poa);
        if ( poas.isEmpty() ) {
            factory.removePoaManager(this);
	}
    
private java.lang.StringstateToString(org.omg.PortableServer.POAManagerPackage.State state)

 // initially false, set true as soon as 
					// one of activate, hold_request, 
					// discard_request, or deactivate is called.

         
    
	switch (state.value()) {
	    case State._HOLDING : return "State[HOLDING]" ;
	    case State._ACTIVE : return "State[ACTIVE]" ;
	    case State._DISCARDING : return "State[DISCARDING]" ;
	    case State._INACTIVE : return "State[INACTIVE]" ;
	}

	return "State[UNKNOWN]" ;
    
public java.lang.StringtoString()

	return "POAManagerImpl[myId=" + myId + 
	    " state=" + stateToString(state) +
	    " nInvocations=" + nInvocations + 
	    " nWaiters=" + nWaiters + "]" ;