package textbender.a.r.desk; // 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.io.*; import java.rmi.*; import java.util.concurrent.atomic.*; import textbender.g.hold.*; import textbender.g.io.*; import textbender.g.lang.*; import textbender.g.util.logging.*; /** A run of the desk daemon. * The single instance of Run is available via Run.i(). */ public @ThreadSafe final class Run { private Run() {} /** The single instance of Run. */ public static Run i() { return instance; } /** Starts the run from the command line, or from JNLP (e.g. Web Start). * * @param argumentArray of length zero (there ought to be no arguments) * * @throws IllegalStateException if called more than once */ public static void main( String[] argumentArray ) { Thread.setDefaultUncaughtExceptionHandler( ThreadX.UNCAUGHT_EXCEPTION_LOGGER ); // early if( argumentArray.length > 0 ) throw new IllegalArgumentException( "expecting no arguments, found: " + argumentArray[0] ); LoggerX.i(Run.class).info( "starting desk daemon" ); // LoggerX.test( LoggerX.i( Run.class )); // PRIVATE try{ instance.start(); } catch( Exception x ) { LoggerX.i(Run.class).log( LoggerX.SEVERE, /*message*/"", x ); System.exit( 1 ); } } /** Starts the run programmatically. * * @throws IllegalStateException if called more than once */ public void start() throws NotBoundException, IOException { if( wasStartCommencedA.getAndSet( true )) { throw new IllegalStateException(); } new DeskDaemon(); // its executor() thread will keep the VM running (if nothing else does) until Runtime.exit() is requested new HostServiceRegistry1(); new textbender.a.u.transfer.clipboard.Copier ( new textbender.a.u.transfer.PRTransferS() ); //ThreadX.trySleep( 2000 ); //System.exit( 2 ); //new textbender.a.u.transfer.PRTransferS(); new textbender.a.u.locusPoint.LocusPoint1(); new textbender.a.u.chromography.Chromography1(); } // ------------------------------------------------------------------------------------ public boolean isFileSystemCaseSensitive() { return isFileSystemCaseSensitive; } private final boolean isFileSystemCaseSensitive = FileX.testsCaseSensitive(); /** Spool 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() { // LoggerX.i(Run.class).info( "stopping desk daemon" ); ///// logging service unreliable, at this stage spool.unwind( new CatcherP() ); // throw new Error( "test error in shutdown thread" ); } }; shutdownThread.setUncaughtExceptionHandler( ThreadX.UNCAUGHT_EXCEPTION_PRINTER ); // instead of this run's default UNCAUGHT_EXCEPTION_LOGGER Runtime.getRuntime().addShutdownHook( shutdownThread ); // spool.add( new Hold() // { // public @ThreadSafe void release() { throw new RuntimeException( "test exception during shutdown" ); } // }); } /** Returns true if this run has started. */ public boolean wasStartCommenced() { return wasStartCommencedA.get(); } private AtomicBoolean wasStartCommencedA = new AtomicBoolean(); ////////////////////////////////////////////////////////////////////////////////////////// // Last, so static fields above initialize, and are available during instantiation below private static final Run instance = new Run(); }