com.partnersoft.system
Class AppManager

java.lang.Object
  extended by com.partnersoft.system.AppManager
All Implemented Interfaces:
Singleton

public class AppManager
extends java.lang.Object
implements Singleton

Tracks open Apps, and manages their startup and shutdown processes. After the last App closes, exits the JVM.

This is a fairly low-level facility; don't use it unless you know what you're doing. See AppLib for more user-friendly App methods.

Copyright 2004-2007 Partner Software, Inc.

Version:
$Id: AppManager.java 2328 2010-01-06 15:38:22Z paul $
Author:
Paul Reavis

Method Summary
 void addShutdownTask(java.lang.Runnable newTask)
          Adds a Runnable task that will be run before the system is shutdown.
 boolean appExists(java.lang.String appName)
          Returs true if the given String is a valid app name.
 java.util.List<java.lang.String> listApps()
          Lists available apps.
 void popAppContext(java.lang.String contextName)
          Pops the last named app context from the current thread's app stack.
 void popGuiAppContext(java.lang.String contextName)
          Removes a GUI app context from the list of active GUI contexts.
 void pushAppContext(java.lang.String contextName)
          Pushes a new, named app context onto the current thread's app stack.
 void pushGuiAppContext(java.lang.String contextName)
          Adds a new GUI app context to the list of active GUI contexts.
 void runApp(java.lang.String appName)
          Runs the named app script using runApp(Script).
 void runAppAndThrowException(java.lang.String appName)
          Runs the named app.
 void runAppThreaded(Script runme)
          Runs an app in a new thread.
 void runAppThreaded(java.lang.String appName)
          Runs the named app script in a separate thread.
 void shutdown()
          Shuts down all apps and exits the system.
static AppManager singleton()
          The singleton instance of AppManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

singleton

public static AppManager singleton()
The singleton instance of AppManager.

Returns:
the only instance of AppManager you need

appExists

public boolean appExists(java.lang.String appName)
Returs true if the given String is a valid app name.


listApps

public java.util.List<java.lang.String> listApps()
Lists available apps.


runApp

public void runApp(java.lang.String appName)
Runs the named app script using runApp(Script).

Parameters:
appName - name of app.
Throws:
java.lang.IllegalArgumentException - if there is no app of the given name.

runAppAndThrowException

public void runAppAndThrowException(java.lang.String appName)
                             throws java.lang.Throwable
Runs the named app. If any exceptions occur, rather than quashing them, it throws them up for you to deal with.

Parameters:
appName - name of app.
Throws:
java.lang.IllegalArgumentException - if there is no app of the given name.
java.lang.Throwable - if anything whatsoever happens

runAppThreaded

public void runAppThreaded(java.lang.String appName)
Runs the named app script in a separate thread.

Parameters:
appName - name of app.
Throws:
java.lang.IllegalArgumentException - if there is no app of the given name.

runAppThreaded

public void runAppThreaded(Script runme)
Runs an app in a new thread. During the run, pushes an app context for the script onto the thread's app stack.

Parameters:
runme - script to run

pushAppContext

public void pushAppContext(java.lang.String contextName)
Pushes a new, named app context onto the current thread's app stack. This is used in the logs to indicate depth of execution, and also to determine whether the Java VM can exit.

This method should only be used by classes in the app framework.

Parameters:
contextName - name of app context (usually the script name)

popAppContext

public void popAppContext(java.lang.String contextName)
Pops the last named app context from the current thread's app stack. The contextName given is used as a check to ensure that proper nesting occurs; an IllegalArgumentException will result if you close an app context out of turn.

IF this is the last app context on the stack, AND there are no other app contexts on other threads, AND no other GUI app contexts running, THEN the Java VM will exit normally.

This method should only be used by classes in the app framework.

Parameters:
contextName - name of app context (usually the script name)

pushGuiAppContext

public void pushGuiAppContext(java.lang.String contextName)
Adds a new GUI app context to the list of active GUI contexts. This list is maintained to ensure that the Java VM remains open while there are active GUI applications. Multiple contexts can be added with the same name. The popGuiAppContext(String) method should be called when the GUI closes (usually on window exit).

Parameters:
contextName - name of app context (usually the window or application name)

popGuiAppContext

public void popGuiAppContext(java.lang.String contextName)
Removes a GUI app context from the list of active GUI contexts. This list is maintained to ensure that the Java VM remains open while there are active GUI applications. Multiple contexts can be added with the same name; each is then removed separately by this method. The pushGuiAppContext(String) method must have been called previously. Call this method when the GUI closes (usually on window exit). IF this is the last GUI app context in the list, AND there are no other app contexts on other threads, THEN the Java VM will exit normally.

Parameters:
contextName - name of app context (usually the window or application name)

addShutdownTask

public void addShutdownTask(java.lang.Runnable newTask)
Adds a Runnable task that will be run before the system is shutdown.

Parameters:
newTask -

shutdown

public void shutdown()
Shuts down all apps and exits the system. Use this instead of System.exit() when you really have to shut things down.