FileDocCategorySizeDatePackage
AbstractSubsystem.javaAPI DocphoneME MR2 API (J2ME)6467Wed May 02 18:00:10 BST 2007com.sun.midp.suspend

AbstractSubsystem

public abstract class AbstractSubsystem extends Object implements Subsystem
An abstract subsystem that may contain other subsystems. Contained subsytems are suspended after this subsystem suspend and resumed prior to the subsystem resuming.

Fields Summary
static com.sun.midp.security.SecurityToken
classSecurityToken
Security token for provileged access to internal API's. Note it must stay package private.
final Object
lock
State transition synchronization lock.
int
state
Current subsystem state.
private final Vector
subsystems
Subsystems this one depends on.
private final Vector
dependencies
A set of suspend dependencies. System is considered to be suspended when all the subsystems are suspended and all the dependencies removed.
Constructors Summary
Methods Summary
public voidaddSuspendDependency(SuspendDependency dep)
Adds a dependency that prevents from system suspend.

param
dep dependency to add

        synchronized (lock) {
            if (!dependencies.contains(dep)) {
                dependencies.addElement(dep);
            }
        }

    
public final intgetState()
Returns the current state.

return
current state if the subsystem


                   
        
        return state;
    
public voidregisterSubsystem(Subsystem s)
Registers a subsystem this one depends on.

param
s subsystem this one depends on.

        synchronized (subsystems) {
            if (!subsystems.contains(s)) {
                subsystems.addElement(s);
            }
        }
    
public voidremoveSuspendDependency(SuspendDependency dep)
Removes dependency that does not prevent from system suspend any more. Then invokes suspend notification if there are no dependencies left.

param
dep dependency to remove

        synchronized (lock) {
            dependencies.removeElement(dep);
            updateSuspendStatus();
        }
    
public final voidresume()
If the current state is SUSPENDED, changes the state to RESUMING, performs object-specific activation operations and then changes the state to ACTIVE.

        synchronized (lock) {
            if (state == SUSPENDED) {
                state = RESUMING;
                
                Enumeration subs = subsystems.elements();
                while (subs.hasMoreElements()) {
                    ((Subsystem)subs.nextElement()).resume();
                }
            
                resumeImpl();
                state = ACTIVE;
                resumed();
            }
        }
    
protected voidresumeImpl()
Performs object-specific activation operations. Default implementation makes nothing.

voidresumed()
Confirms subsystem has been resumed. Listeners/waiters can be invoked here.

public voidsuspend()
If the current state is ACTIVE, changes the state to SUSPENDING, and initiates suspend routine. The suspend routine is pstponed until all suspend dependences are removed. If there are no dependencies currently, the suspend routine is invoked immediately.

        synchronized (lock) {
            if (state == ACTIVE) {
                state = SUSPENDING;
                updateSuspendStatus();
            }
        }
    
protected voidsuspendImpl()
Performs object-specific suspend operations. Default implementation makes nothing.

voidsuspended()
Confirms subsystem has been suspended. Listeners/waiters can be invoked here.

public voidunregisterSubsystem(Subsystem s)
Unregisters a subsystem this one depends on.

param
s subsystem this one depends on.

        synchronized (subsystems) {
            subsystems.removeElement(s);
        }
    
protected voidupdateSuspendStatus()
Checks if there are dependencies that prevent from system suspend, if there are no ones, and the state is SUSPENDING suspend routine. The suspend routine performs first object-specific ations then invokes suspend() methods for all registered subsytems.

        synchronized (lock) {
            if (state == SUSPENDING && 0 == dependencies.size()) {
                suspendImpl();

                Enumeration subs = subsystems.elements();
                while (subs.hasMoreElements()) {
                    ((Subsystem)subs.nextElement()).suspend();
                }

                state = SUSPENDED;
                suspended();
            }
        }