r2426 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher
Author: chatellier Date: 2009-06-24 14:49:12 +0000 (Wed, 24 Jun 2009) New Revision: 2426 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java Log: Add surrounding try/catch on monitor main loop. Close simulation storage after post simulation operations. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-06-24 13:02:42 UTC (rev 2425) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-06-24 14:49:12 UTC (rev 2426) @@ -40,6 +40,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaException; import org.codelutin.util.FileUtil; import fr.ifremer.isisfish.IsisFish; @@ -350,70 +351,88 @@ while (true) { + // quoi qu'il arrive, le thread ne doit jamais s'arreter try { - Thread.sleep(1000); - } catch (InterruptedException e) { + waitAndCheckProgression(); + } + catch (Exception e) { if (log.isErrorEnabled()) { - log.error("Monitor thread has been interrupted", e); + log.error("An exception occurs durring monitoring", e); } } + } + } - // log - if (log.isDebugEnabled()) { - log.debug("Simulation monitor wake up"); + /** + * Wait one second, and check for first + * simulation progression, if first simulation time + * is reached. + */ + protected void waitAndCheckProgression() { + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + if (log.isErrorEnabled()) { + log.error("Monitor thread has been interrupted", e); } + } - // take first job in map - if (!checkSet.isEmpty()) { - SimpleEntry<Date, SimulationJob> firstEntry = checkSet.first(); - Date date = firstEntry.getKey(); - Date now = new Date(); + // log + if (log.isDebugEnabled()) { + log.debug("Simulation monitor wake up"); + } - if (date.before(now)) { - // first key date in map is over... - // check is needed - SimulationJob job = firstEntry.getValue(); - SimulatorLauncher launcher = job.getLauncher(); + // take first job in map + if (!checkSet.isEmpty()) { + SimpleEntry<Date, SimulationJob> firstEntry = checkSet.first(); + Date date = firstEntry.getKey(); + Date now = new Date(); - if (log.isInfoEnabled()) { - log.info("Check simulation progression : " + job.getId()); - } + if (date.before(now)) { + // first key date in map is over... + // check is needed + SimulationJob job = firstEntry.getValue(); + SimulatorLauncher launcher = job.getLauncher(); - // retourne true if : - // - simulation is finished - // - simulation end has been asked - boolean jobIsFinished = checkProgression(job, launcher); + if (log.isInfoEnabled()) { + log.info("Check simulation progression : " + job.getId()); + } - // always remove this simulation from map - checkSet.remove(firstEntry); + // retourne true if : + // - simulation is finished + // - simulation end has been asked + boolean jobIsFinished = checkProgression(job, launcher); - // if not finished, re-add it at end - if (jobIsFinished) { + // always remove this simulation from map + checkSet.remove(firstEntry); - if (log.isInfoEnabled()) { - log.info("Job " + job.getId() + " finished"); - } + // if not finished, re-add it at end + if (jobIsFinished) { - doPostSimulationOperation(job, launcher); + if (log.isInfoEnabled()) { + log.info("Job " + job.getId() + " finished"); } - // Si le job est reelement fini - // et que les post operation ont réussie - else { - // next check date - long nextJobTimeMs = date.getTime() - + launcher.getCheckProgressionInterval() * 1000; - Date nextJobDate = new Date(nextJobTimeMs); - checkSet.add(new SimpleEntry<Date, SimulationJob>(nextJobDate, job)); - } + doPostSimulationOperation(job, launcher); + } - } else { - //checkScheduler.schedule(this, date); - if (log.isDebugEnabled()) { - log.debug("Time to check not reached, skip check, " - + date + " < " + now); - } + // Si le job est reelement fini + // et que les post operation ont réussie + else { + // next check date + long nextJobTimeMs = date.getTime() + + launcher.getCheckProgressionInterval() * 1000; + Date nextJobDate = new Date(nextJobTimeMs); + checkSet.add(new SimpleEntry<Date, SimulationJob>(nextJobDate, job)); } + + } else { + //checkScheduler.schedule(this, date); + if (log.isDebugEnabled()) { + log.debug("Time to check not reached, skip check, " + + date + " < " + now); + } } } } @@ -516,6 +535,16 @@ } } + // close storage after simulation + // and after all post actions + try { + simulation.closeStorage(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.debug("Can't close simulation storage", e); + } + } + // notify simulation ended // to not check later... // don't do in finally, getSimulationStorage may fail (md5 on ssh) @@ -538,7 +567,7 @@ * Export result, and delete simulation if "onlyExport" has * been selected. * - * @return <tt>true</tt> if simulation is styll available (not delete by onlyExport) + * @return <tt>true</tt> if simulation is still available (not delete by onlyExport) */ protected boolean exportResult(SimulationJob job, SimulationStorage simulation) { @@ -621,7 +650,7 @@ } } } - + return simulationAvailble; }
participants (1)
-
chatellier@users.labs.libre-entreprise.org