Mercurial > projects > mde
diff mde/scheduler/Init.d @ 25:2c28ee04a4ed
Some minor and some futile efforts.
Played around with init functions, had problems, gave up and put them back.
Removed idea for multiple init stages; it's not good for performance or simplicity.
Adjusted exception messages.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 03 Apr 2008 17:26:52 +0100 |
parents | 32eff0e01c05 |
children | 611f7b9063c6 |
line wrap: on
line diff
--- a/mde/scheduler/Init.d Thu Mar 27 16:15:21 2008 +0000 +++ b/mde/scheduler/Init.d Thu Apr 03 17:26:52 2008 +0100 @@ -22,7 +22,7 @@ *************************************************************************************************/ module mde.scheduler.Init; -import mde.scheduler.InitStage; +import mde.scheduler.InitFunctions; import mde.scheduler.exception; import mde.options; @@ -36,7 +36,7 @@ import tango.util.log.Log : Log, Logger; import tango.util.log.ConsoleAppender : ConsoleAppender; -version = SwitchAppender; +//version = SwitchAppender; version (SwitchAppender) { // My own variation, currently just a test import tango.util.log.SwitchingFileAppender : SwitchingFileAppender; } else { @@ -92,6 +92,7 @@ */ scope class Init { + //private bool failure = false; // set true on failure during init, so that clean private static Logger logger; static this() { logger = Log.getLogger ("mde.scheduler.Init.Init"); @@ -121,7 +122,7 @@ try { Options.load(); } catch (optionsLoadException e) { - throw new InitException ("Loading options failed; message: " ~ e.msg); + throw new InitException ("Loading options failed: " ~ e.msg); } // Now re-set the logging level: @@ -135,28 +136,12 @@ * Current method is to try using threads, and on failure assume no threads were actually * created and run functions in a non-threaded manner. */ - // init2 - cleanupStages ~= &cleanup2; // add appropriate cleanup stage try { - debug logger.trace ("Init: init2"); - if (runStageThreaded (init2)) runStageForward (init2); + if (runStageThreaded (init)) runStageForward (init); } catch (InitStageException) { // This init stage failed. - debug logger.trace ("Init: init2 failed"); - runCleanupStages(); - throw new InitException ("Initialisation failed during stage init2"); - } - - // init4 - cleanupStages ~= &cleanup4; // add appropriate cleanup stage - try { - debug logger.trace ("Init: init4"); - if (runStageThreaded (init4)) runStageForward (init4); - } - catch (InitStageException) { // This init stage failed. - debug logger.trace ("Init: init4 failed"); - runCleanupStages(); - throw new InitException ("Initialisation failed during stage init4"); + // FIXME: check DTOR still runs + throw new InitException ("An init function failed (see above message(s))"); } //END Init @@ -168,11 +153,16 @@ { debug logger.trace ("Cleanup: starting"); - // cleanup1: Options.save(); // save options... do so here for now - // cleanup2, 4: - runCleanupStages(); + // General cleanup: + try { + if (runStageThreaded (cleanup)) runStageReverse (cleanup); + } + catch (InitStageException) { + // Nothing else to do but report: + logger.error ("One or more cleanup functions failed!"); + } debug logger.trace ("Cleanup: done"); } @@ -259,22 +249,6 @@ } //END runStage... - private { - InitStage*[] cleanupStages; // All cleanup stages needing to be run later. - void runCleanupStages () { - foreach_reverse (s; cleanupStages) { - try { - runStageReverse (*s); - } - catch (InitStageException) { - // We're cleaning up anyway, just report and continue - logger.error ("Cleanup function failed! Continuing..."); - } - } - cleanupStages = []; // All have been run, don't want them getting run again - } - } - debug (mdeUnitTest) unittest { /* Fake init and cleanup. Use unittest-specific init and cleanup InitStages to avoid * messing other init/cleanup up. */