package textbender.a.r.page; // Copyright 2006-2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.util.concurrent.atomic.AtomicBoolean; import textbender.g.lang.*; import textbender.g.util.logging.*; /** A run of the page daemon code. * The single instance of Run is available via Run.i(). *

* In Mozilla (1.7.13), each browser window has a separate classloader * for the page daemon code. In Mozilla therefore, * a run corresponds to a single browser window. * This may vary, depending on the browser. *

*/ public @ThreadSafe final class Run { /** The single instance of Run. */ public static Run i() { return instance; } private Run() {} // { // isOSWindows = System.getProperty( "os.name" ).matches( "(?i).*\\bWindows\\b.*" ); // } private final AtomicBoolean isStartedA = new AtomicBoolean(); /** Starts the run. * * @return false if start already commenced; true otherwise */ boolean start() { if( isStartedA.getAndSet( true )) { return false; } // already called // LoggerX.test( LoggerX.i( Run.class )); // PRIVATE LoggerX.i(getClass()).fine( "starting page daemon" ); new PageDaemons(); new PageDaemonsEDT(); return true; } // ------------------------------------------------------------------------------------ // /** Returns true if the operating system is Windows. // */ // public boolean isOSWindows() { return isOSWindows; } // // // private final boolean isOSWindows; // // // // /** Spool (supposedly) unwound just before this run ends, at VM shut-down. // */ // public Spool spool() { return spool; } // // // private final Spool spool = new SpoolT(); // // // { // Thread shutdownThread = new Thread() // { // public void run() { spool.unwind(); } // }; // Runtime.getRuntime().addShutdownHook( shutdownThread ); // } //// shutdown hook not called on Firefox 2 (or Mozilla 1.7) if the initial page is exited first ////////////////////////////////////////////////////////////////////////////////////////// // Last, so static fields above initialize, and are available during instantiation below private static final Run instance = new Run(); }