|
| United States Worldwide |
|
Using AWT and Swing with OPJUnlike other persistence mechanisms, OPJ includes support for the persistence of user-interface objects. If an application suspends (or terminates unexpectedly because of computer failure), with active windows, then the goal of persistent computation requires that the windows should be present when the application eventually resumes.By default, if an application has active windows when a checkpoint occurs, the windows are treated as roots of persistence, and will be recreated when the application resumes. This is one case where the absence of persistence threads can cause a problem if, as is typical, the main application class creates the windows. This will result in duplicate windows appearing on subsequent runs. There are two ways to work around this problem. The first is to use a boolean flag to indicate whether this is the first run, e.g.
public class Main {
private static boolean firstRun = true;
public static void main(String[] args) {
if (firstRun) {
// create windows
firstRun = false;
}
// use windows
}
}
Note that this solution will also work when running in a non-persistent context, as
firstRun will always be true.
The second solution, which is convenient if the source code cannot be modified, is to exploit the opj command line option "-mainonce". This option encapsulates the notion of "firstRun" in the system itself, avoiding the execution of "main" completely on subsequent runs. Effectively it is as if the entire body of the main method was guarded by the test of "firstRun". Of course, this only works if the code in main conforms to the model, and doesn't execute any other code that needs to be run on every resumption.. As an example, the SwingSet demo program can be executed successfully this way, and provides a good example of the effect of persistent user interfaces. To run the SwingSet demo, execute the following, where $OPJ is the path to your installation: % setenv PATH $OPJ/bin:$PATH % cd $OPJ/demo/jfc/SwingSet % opj -config $OPJ/sample_store_configs/tmp.pjc -jar SwingSet.jar -mainonce -mainroot SwingSetThis will bring up the main demo window after which you can select some of the components and experiment with their capabilities. When you exit the demo with "File->Exit", the state of the demo will be checkpointed. Resuming the demo with exactly the same command line will the demo return to the same window state. We must stress that the code of this demo is completely unchanged from the one in the standard JDK distribution.
Last changed: Mar 1st 1999 Questions and comments to forest-info@sunlabs.com | ||||||||||||||||||||||