FileDocCategorySizeDatePackage
MIDletProxy.javaAPI DocphoneME MR2 API (J2ME)15067Wed May 02 18:00:06 BST 2007com.sun.midp.main

MIDletProxy

public class MIDletProxy extends Object implements com.sun.midp.suspend.SuspendDependency
Represents the state of a running MIDlet and its Display so that objects do not have to be shared across Isolates. The states in this object are updated by the MIDletProxyList upon receiving a notification event. This class also provides methods for asynchronously changing a MIDlet's state.

Fields Summary
public static final int
MIDLET_ACTIVE
Constant for active state of a MIDlet.
public static final int
MIDLET_PAUSED
Constant for paused state of a MIDlet.
public static final int
MIDLET_DESTROYED
Constant for destroyed state of a MIDlet.
private static com.sun.midp.lcdui.ForegroundEventProducer
foregroundEventProducer
Cached reference to the ForegroundEventProducer.
private static com.sun.midp.midlet.MIDletEventProducer
midletEventProducer
Cached reference to the MIDletEventProducer.
private int
externalId
ID given to this midlet by an external application manager.
private int
isolateId
ID of the Isolate the MIDlet is running in.
private int
displayId
ID of the MIDlet's Display.
private int
suiteId
ID of the suite the MIDlet belongs to.
private String
className
Class name of the MIDlet.
private String
displayName
Display name of the MIDlet to show the user.
private int
midletState
MIDlet life cycle state. Will be either MIDLET_ACTIVE, MIDLET_PAUSED, or MIDLET_DESTROYED.
boolean
wasNotActive
Indicates that the midlet was just created.
private boolean
wantsForegroundState
True if the MIDlet want's its Display in the foreground.
private boolean
requestedForeground
True if the MIDlet has the foreground at least once.
private MIDletProxy
preempting
The display that is preempting this MIDlet.
private boolean
alertWaiting
True if alert is waiting for the foreground.
private MIDletProxy
preempted
The display to put in the foreground after this display stops preempting. If no display in this isolate had the foreground then this will be null.
private Timer
proxyTimer
Timer for the MIDlet proxy. Used when a midlet is hanging.
private MIDletProxyList
parent
Parent list.
Constructors Summary
MIDletProxy(MIDletProxyList theParentList, int theExternalAppId, int theIsolateId, int theSuiteId, String theClassName, String theDisplayName, int theMidletState)
Construct a new MIDletProxy.

param
theParentList parent MIDlet proxy list
param
theExternalAppId ID of given by an external application manager
param
theIsolateId ID of the Isolate the MIDlet is running in.
param
theSuiteId ID of the suite MIDlet
param
theClassName Class name of the MIDlet
param
theDisplayName Display name of the MIDlet to show the user
param
theMidletState MIDlet lifecycle state.


        parent = theParentList;
        externalId = theExternalAppId;
        isolateId = theIsolateId;
        suiteId = theSuiteId;
        className = theClassName;
        displayName = theDisplayName;
        midletState = theMidletState;
        wasNotActive = true;
    
Methods Summary
public voidactivateMidlet()
Asynchronously change the MIDlet's state to active. This method does NOT change the state in the proxy, but sends a activate MIDlet event to the MIDlet's Display. The state in the proxy is only update when the MIDlet sends a MIDlet activated event to the proxy list.

        if (midletState != MIDLET_DESTROYED) {
            wasNotActive = false;
            midletEventProducer.sendMIDletActivateEvent(isolateId, className);
        }
    
public voiddestroyMidlet()
Asynchronously change the MIDlet's state to destroyed. This method does NOT change the state in the proxy, but sends request to destroy MIDlet event to the AMS. The state in the proxy is only update when the MIDlet sends a MIDlet destroyed event to the proxy list.

        if (midletState != MIDLET_DESTROYED) {
            if (getTimer() != null) {
                // A destroy MIDlet event has been sent.
                return;
            }

            MIDletDestroyTimer.start(this, parent);

            midletEventProducer.sendMIDletDestroyEvent(isolateId, className);
        }
    
voiddestroyedNotification()
Process a MIDlet destroyed notification.

        setTimer(null);
        setMidletState(MIDLET_DESTROYED);
    
public java.lang.StringgetClassName()
Get the class name of the MIDlet.

return
class name of the MIDlet

        return className;
    
public intgetDisplayId()
Get the ID of the MIDlet's Display. Public for testing purposes.

return
ID of the MIDlet's Display

        return displayId;
    
public java.lang.StringgetDisplayName()
Get the Display name of the MIDlet.

return
Display name of the MIDlet

        return displayName;
    
public intgetExternalAppId()
Get the external application ID used for forwarding changes.

return
ID assigned by the external application manager

        return externalId;
    
public intgetIsolateId()
Get the ID of the Isolate the MIDlet is running in. Public for testing purposes.

return
ID of the Isolate the MIDlet is running in

        return isolateId;
    
public intgetMidletState()
Get the MIDlet lifecycle state.

return
MIDlet state

        return midletState;
    
com.sun.midp.main.MIDletProxygetPreemptedMidlet()
Get the proxy of the MIDlet that should get the foreground after preempting is done.

return
the preempted display or null for none

        return preempted;
    
com.sun.midp.main.MIDletProxygetPreemptingDisplay()
Get the proxy of the display that is preempting this MIDlet.

return
the preempting display

        return preempting;
    
public intgetSuiteId()
Get the ID of the MIDlet's suite.

return
ID of the MIDlet's suite

        return suiteId;
    
java.util.TimergetTimer()
Gets the timer object

return
Timer

        return proxyTimer;
    
static voidinitClass(com.sun.midp.lcdui.ForegroundEventProducer theForegroundEventProducer, com.sun.midp.midlet.MIDletEventProducer theMIDletEventProducer)
Initialize the MIDletProxy class. Should only be called by the MIDletProxyList.

param
theForegroundEventProducer reference to the event producer
param
theMIDletEventProducer reference to the event producer


                                    
      
         
          

        foregroundEventProducer = theForegroundEventProducer;
        midletEventProducer = theMIDletEventProducer;
    
public booleanisAlertWaiting()
Called to determine if alert is waiting for the foreground.

return
true if an alert of the MIDlet is waiting in background.

        return alertWaiting;
    
public booleannoDisplay()
Check if the MIDlet has not created its display.

return
true if the MIDlet has no display.

        return displayId == 0;
    
public booleannoDisplayable()
Check if the MIDlet has not set a displayable in its display. Used by foreground selector to determine if the MIDlet it is about to put in the foreground will draw the screen.

return
true if the MIDlet has no displayable.

        return !requestedForeground;
    
voidnotifyMIDletHasForeground(boolean hasForeground)
Notify the midlet's display of a foreground change. Called by the MIDlet proxy list to notify the old and new foreground displays of a foreground change.

param
hasForeground true if the target is being put in the foreground

        if (hasForeground) {
            alertWaiting = false;
            foregroundEventProducer.sendDisplayForegroundNotifyEvent(
                isolateId, displayId);
        } else {
            foregroundEventProducer.sendDisplayBackgroundNotifyEvent(
                isolateId, displayId);
        }
    
public voidpauseMidlet()
Asynchronously change the MIDlet's state to paused. This method does NOT change the state in the proxy, but sends a pause MIDlet event to the MIDlet's Display. The state in the proxy is only update when the MIDlet sends a MIDlet paused event to the proxy list.

        if (midletState != MIDLET_DESTROYED) {
            midletEventProducer.sendMIDletPauseEvent(isolateId, className);
        }
    
voidsetDisplayId(int id)
Sets the ID of the MIDlet's Display.

param
id of the MIDlet's Display

        displayId = id;
    
voidsetMidletState(int newMidletState)
Set the MIDlet cycle state. Called by the MIDlet proxy list when it receives an event from the MIDlet to update this value.

param
newMidletState new MIDlet state

        midletState = newMidletState;
    
voidsetPreemptedMidlet(com.sun.midp.main.MIDletProxy preemptedDisplay)
Set the proxy of the MIDlet that should get the foreground after preempting is done.

param
preemptedDisplay the preempted display

        preempted = preemptedDisplay;
    
voidsetPreemptingDisplay(com.sun.midp.main.MIDletProxy preemptingDisplay)
Set the proxy of the display that is preempting this MIDlet.

param
preemptingDisplay the preempting display

        // Turn on the user notification status for this proxy
        if (preemptingDisplay != null) {
            alertWaiting = true;
        } else {
            if (preempting != null) {
                /*
                 * There could be a proxy timer waiting to destroy the
                 * isolate if the user ended the alert with the end MIDlet
                 * button, so cancel the timer.
                 */
                preempting.setTimer(null);
            }

            alertWaiting = false;
        }

        preempting = preemptingDisplay;
    
voidsetTimer(java.util.Timer t)
Sets the timer object

param
t Timer object

        proxyTimer = t;
    
voidsetWantsForeground(boolean newWantsForeground, boolean isAlert)
Set the wants foreground state in the proxy. Called by the MIDlet proxy list when it receives an event from the MIDlet's display to update this value.

param
newWantsForeground new wants foreground value.
param
isAlert true if the displayable requesting the foreground, is an Alert, this parameter is ignored if newWantsForeground is false

        wantsForegroundState = newWantsForeground;

        if (newWantsForeground) {
            requestedForeground = true;
            alertWaiting = isAlert;
        } else {
            alertWaiting = false;
        }
    
public voidterminateNotPausedMidlet()
Terminates ther MIDlet if it is neither paused nor destroyed.

        if (midletState != MIDLET_DESTROYED && midletState != MIDLET_PAUSED) {
            MIDletProxyUtils.terminateMIDletIsolate(this, parent);
        }
    
public java.lang.StringtoString()
Print the state of the proxy.

return
printable representation of the state of this object

        return "MIDletProxy: suite id = " + suiteId +
            "\n    class name = " + className +
            "\n    display name = " + displayName +
            "\n    isolate id = " + isolateId +
            ", display id = " + displayId +
            ", midlet state = " + midletState +
            ", wantsForeground = " + wantsForegroundState +
            ", requestedForeground = " + requestedForeground +
            "\n    alertWaiting = " + alertWaiting;
    
public booleanwantsForeground()
Check if the MIDlet want's its Display in the foreground.

return
true if the MIDlet want's its Display in the foreground

        return wantsForegroundState;