r1916 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish: datastore simulator/launcher
Author: chatellier Date: 2009-03-09 10:29:01 +0000 (Mon, 09 Mar 2009) New Revision: 1916 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/IsisH2Config.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulatorLauncher.java Log: Test de recover h2 (ne fonctionne pas). Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/IsisH2Config.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/IsisH2Config.java 2009-03-05 23:48:46 UTC (rev 1915) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/IsisH2Config.java 2009-03-09 10:29:01 UTC (rev 1916) @@ -1,21 +1,19 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ +/* ##% Copyright (C) 2002 - 2009 Code Lutin, Tony Chemit + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##% */ package fr.ifremer.isisfish.datastore; import fr.ifremer.isisfish.IsisConfig; @@ -29,13 +27,18 @@ import org.hibernate.dialect.H2Dialect; /** - * Isis H2 concrete Config implementation + * Isis H2 concrete Config implementation. * * @author chemit + * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class IsisH2Config { - static final private String commonUrl = + protected static final String COMMON_URL = // on peut aussi utiliser mysql ou postgresql "MODE=hsqldb;" + // Sets the default lock timeout (in milliseconds) in this database @@ -59,7 +62,7 @@ // on system.out: 0=off, 1=error, 2=info, 3=debug. "TRACE_LEVEL_SYSTEM_OUT=1"; - static final private String h2Url = + protected static final String H2_URL = "jdbc:h2:file:%s;" + // on peut aussi utiliser file, socket "FILE_LOCK=file;" + @@ -69,17 +72,27 @@ // changes is disabled (default), 2: logging of both data and index // changes are enabled "LOG=1;" + - commonUrl; - - static final private String h2memUrl = + COMMON_URL; + + /** + * H2 recover URL. + * + * Include 'recover=1' parameter. + */ + protected final static String H2_RECOVER_URL = + H2_URL + + ";recover=1"; + + protected static final String H2_MEM_URL = "jdbc:h2:mem:%s;" + "LOG=0;" + - commonUrl; + COMMON_URL; + /** * @param rootDir le repertoire de base du DataStorage * @return le repertoire de donnees d'un Data storage a partir de son repertoire de base */ - static public File getStorageDataDirectory(File rootDir) { + public static File getStorageDataDirectory(File rootDir) { return new File(rootDir, "data"); } @@ -94,7 +107,7 @@ * @param id l'identifiant de la base * @return l'objet config passe en parametre */ - static public Properties addMemDatabaseConfig(Properties config, String id) { + public static Properties addMemDatabaseConfig(Properties config, String id) { config.setProperty(Environment.USER, "sa"); config.setProperty(Environment.PASS, ""); @@ -103,23 +116,24 @@ // correct error : org.hibernate.HibernateException: No CurrentSessionContext configured! config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); - // config.setProperty(Environment.SHOW_SQL, "true"); + // config.setProperty(Environment.SHOW_SQL, "true"); - String url = String.format(h2memUrl, id); + String url = String.format(H2_MEM_URL, id); config.setProperty(Environment.URL, url); - + return config; } /** - * Ajoute differente information au parametre config qui indique comment - * se connecter a la base de donnees + * Ajoute differentes informations au parametre config qui indique comment + * se connecter a la base de donnees. * * @param config l'objet properties dans lequel il faut ajouter les informations - * @param directory le repertoire dans lequel la base de donn?es doit se trouver + * @param directory le repertoire dans lequel la base de données doit se trouver + * @param tryRecover only used with H2 database engine, add recover parameter when db is detected as corrumpted * @return l'objet config passe en parametre */ - static public Properties addDatabaseConfig(Properties config, File directory) { + public static Properties addDatabaseConfig(Properties config, File directory, boolean tryRecover) { File databasePath = getStorageDataDirectory(directory); databasePath.mkdirs(); @@ -127,7 +141,13 @@ addMemDatabaseConfig(config, ""); // pour h2 on remet STORAGE_DATA car il ne cree pas de repertoire - String url = String.format(h2Url, getStorageDataDirectory(databasePath).getPath()); + String url; + if (tryRecover) { + url = String.format(H2_RECOVER_URL, getStorageDataDirectory(databasePath).getPath()); + } + else { + url = String.format(H2_URL, getStorageDataDirectory(databasePath).getPath()); + } config.setProperty(Environment.URL, url); // migration configuration, seulement pour les fichiers, pas pour les bases memoires @@ -136,20 +156,20 @@ config.put(TopiaMigrationServiceImpl.MIGRATION_MODEL_NAMES, "IsisFish"); config.put(TopiaMigrationServiceImpl.MIGRATION_CALLBACKHANDLERS, SwingMigrationCallbackHandler.class.getName()); config.put("topia.service.migration", TopiaMigrationServiceImpl.class.getName()); - + return config; } /** - * Permet d'ajouter les differents mapping hibernate specifique a l'application + * Permet d'ajouter les differents mapping hibernate spécifique à l'application. * * @param config l'objet properties dans lequel il faut ajouter les informations * @return l'objet config passe en parametre */ - static public Properties addHibernateMapping(Properties config) { + public static Properties addHibernateMapping(Properties config) { config.setProperty("topia.persistence.classes", - IsisFishDAOHelper.entitiesList + IsisFishDAOHelper.getImplementationClassesAsString() ); return config; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2009-03-05 23:48:46 UTC (rev 1915) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2009-03-09 10:29:01 UTC (rev 1916) @@ -99,13 +99,14 @@ control.setDate(new Date()); control.setProgress(0); control.setStarted(true); - + // replace prescript if specified on method - if (simulationPrescript != null && !simulationPrescript.trim().isEmpty()) { + if (simulationPrescript != null + && !simulationPrescript.trim().isEmpty()) { param.setUsePreScript(true); param.setPreScript(simulationPrescript); } - + int lastYear = param.getNumberOfYear(); int lastDate = lastYear * Month.NUMBER_OF_MONTH; control.setProgressMax(lastDate); @@ -246,13 +247,14 @@ protected AspectClassLoader changeClassLoader(Thread thread, File directory) { try { URL[] classpath = new URL[] { directory.toURI().toURL(), - // poussin 20080821 - // il semble ne plus trouve les formules, est-ce mieux avec le compile dir ? + // poussin 20080821 : il semble ne plus trouve les formules, + // est-ce mieux avec le compile dir ? IsisFish.config.getCompileDirectory().toURI().toURL() }; //URL [] classpath = new URL[]{directory.toURL()}; AspectClassLoader loader = new AspectClassLoader(classpath, IsisFish.class.getClassLoader()); //new URLClassLoader(classpath); - //AspectClassLoader loader = new AspectClassLoader(classpath, ClassLoader.getSystemClassLoader()); //new URLClassLoader(classpath); + //AspectClassLoader loader = new AspectClassLoader(classpath, ClassLoader.getSystemClassLoader()); + //new URLClassLoader(classpath); thread.setContextClassLoader(loader); log.info("Classloader used for simulation: " + loader + " " + Arrays.toString(loader.getURLs())); @@ -491,7 +493,7 @@ return this.newObjects; } - /* (non-Javadoc) + /* * @see org.codelutin.topia.event.TopiaTransactionListener#commit(org.codelutin.topia.event.TopiaTransactionEvent) */ public void commit(TopiaTransactionEvent event) { Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2009-03-05 23:48:46 UTC (rev 1915) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2009-03-09 10:29:01 UTC (rev 1916) @@ -53,10 +53,12 @@ import org.codelutin.util.ListenerSet; import org.codelutin.util.ObjectUtil; import org.codelutin.util.ZipUtil; +import org.h2.jdbc.JdbcSQLException; import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.AnalysePlanStorage; +import fr.ifremer.isisfish.datastore.DataStorage; import fr.ifremer.isisfish.datastore.ExportStorage; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.RuleStorage; @@ -405,7 +407,7 @@ // init with default "id" must been changed for designPlan // simulation SimulationControl controlJustForZip = new SimulationControl(id); - + // on construit le zip de la simulation // in zip, there will be param "without" prescript File zip = prepareSimulationZipFile(controlJustForZip, param, true); @@ -426,12 +428,14 @@ // build new simulation id String subsimulationId = id + "_" + simulationIndex; - SimulationControl realSimulationControl = new SimulationControl(subsimulationId); - + SimulationControl realSimulationControl = new SimulationControl( + subsimulationId); + // new item, with zip - SimulationItem item = new SimulationItem(realSimulationControl, subParam); + SimulationItem item = new SimulationItem(realSimulationControl, + subParam); item.setSimulationZip(zip); - + SimulationJob job = new SimulationJob(this, item, priority); job.setLauncher(launcher); fireStartEvent(job); @@ -777,7 +781,7 @@ doNext = doNext && result; } catch (Exception eee) { log.error(_("Stop simulation plan, because can't call afterSimulation correctly on plan %s", - plan.getClass().getName()), eee); + plan.getClass().getName()), eee); doNext = false; } } @@ -860,7 +864,7 @@ new File(tmpDirectory, RuleStorage.RULE_PATH + File.separator + name + ".java")); } - // copie des regles reclam?es par les plans d'analyse + // copie des regles reclamées par les plans d'analyse for (String name : param.getExtraRules()) { FileUtil.copy(new File(RuleStorage.getRuleDirectory(), name + ".java"), Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulatorLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulatorLauncher.java 2009-03-05 23:48:46 UTC (rev 1915) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulatorLauncher.java 2009-03-09 10:29:01 UTC (rev 1916) @@ -25,8 +25,8 @@ import java.rmi.RemoteException; /** - * Interface devant etre implanter par les classes souhaitants etre utilisees - * comme plugin de simulation (CapArmor, SubProcess, ...) + * Interface devant etre implantée par les classes souhaitants etre utilisees + * comme plugin de simulation (InProcess, CapArmor, SubProcess, ...) * * @author poussin * @version $Revision: 1.0 $ @@ -43,20 +43,21 @@ * la simulation * @param control le control de la simulation * @param simulationZip le zip contenant la simulation prete a etre executee + * @param simulationPrescript script de pre simulation * * <b>IMPORTANT</b> Quoi qu'il arrive - * * @throws RemoteException Si pour l'execution de la simulation * on utilise des resources distantes (serveurs) et que ceux si non pas pu * etre contacte. Dans ce cas la simulation n'a pas ete faite et cette * exception est levee. */ public void simulate(SimulationService simulationService, - SimulationControl control, File simulationZip, String simulationPrescript) - throws RemoteException; + SimulationControl control, File simulationZip, + String simulationPrescript) throws RemoteException; /** - * Retourne le nombre maximal de thread de simulation simultane supporte + * Retourne le nombre maximal de thread de simulations simultanées supporté. + * * @return un nombre superieur a 0 */ public int maxSimulationThread();
participants (1)
-
chatellier@users.labs.libre-entreprise.org