r2938 - in isis-fish/trunk/src: main/java/fr/ifremer/isisfish/actions main/java/fr/ifremer/isisfish/datastore main/java/fr/ifremer/isisfish/simulator main/java/fr/ifremer/isisfish/simulator/launcher main/java/fr/ifremer/isisfish/ui/simulator test/java/fr/ifremer/isisfish/simulator
Author: chatellier Date: 2010-01-22 15:42:09 +0000 (Fri, 22 Jan 2010) New Revision: 2938 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/actions/SimulationAction.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java Log: Make all data storage isolated on simulation directory during a simulation Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/actions/SimulationAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/actions/SimulationAction.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/actions/SimulationAction.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2002-2009 Ifremer, Code Lutin, Benjamin Poussin + * Copyright (C) 2002-2010 Ifremer, Code Lutin, Benjamin Poussin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -81,8 +81,7 @@ } SimulationParameter params = new SimulationParameter(); - params.fromProperties(SimulationStorage.getSimulationDirectory(), - props); + params.fromProperties(props); // try to import region if needed String regionName = params.getRegionName(); @@ -142,6 +141,8 @@ } SimulationControl control = new SimulationControl(name); + control.setAutoSaveState(true); // needed for remote simulation + SimulationItem item = new SimulationItem(control, null); item.setSimulationZip(simulationZip); item.setSimulationPrescriptContent(simulationPrescriptContent); @@ -220,6 +221,8 @@ } SimulationControl control = new SimulationControl(name); + control.setAutoSaveState(true); // needed for remote simulation + SimulationItem item = new SimulationItem(control, null); item.setSimulationZip(simulationZip); item.setSimulationPrescriptContent(simulationPrescriptContent); Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2005 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * 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 @@ -67,9 +67,8 @@ static private Map<String, AnalysePlanStorage> plansCache = (Map<String, AnalysePlanStorage>) new ReferenceMap(); - /** - * Construit un nouveau AnalysePlan storage + * Construit un nouveau AnalysePlan storage. * * @param rootSrc repertoire root de stockage des plans * @param directory le repertoire ou devrait se trouver le plan @@ -80,12 +79,11 @@ } static public File getAnalysePlanDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, ANALYSE_PLAN_PATH); + File result = new File(getContextDatabaseDirectory(), ANALYSE_PLAN_PATH); result.mkdirs(); return result; } - + /** * Retourne le nom de toutes les plans existantes * @@ -97,22 +95,22 @@ } /** - * Retourne le storage pour le plan demandé + * Retourne le storage pour le plan demandé. * * @param name le nom du plan souhaité * @return Le storage pour le plan */ static public AnalysePlanStorage getAnalysePlan(String name) { - AnalysePlanStorage result = plansCache.get(name); + String cacheName = getContextDatabaseCacheKey(name); + AnalysePlanStorage result = plansCache.get(cacheName); if (result == null) { - result = new AnalysePlanStorage(IsisFish.config.getDatabaseDirectory(), + result = new AnalysePlanStorage(getContextDatabaseDirectory(), getAnalysePlanDirectory(), name); - plansCache.put(name, result); + plansCache.put(cacheName, result); } return result; } - /** * Retourne une nouvelle instance du plan. Compile le fichier si besoin * @@ -274,7 +272,6 @@ public static List<String> getRemoteAnalysePlanNames() { File dir = getAnalysePlanDirectory(); return getRemoteStorageNames(dir); - } /** Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 + * Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -77,8 +77,7 @@ } public static File getExportDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, EXPORT_PATH); + File result = new File(getContextDatabaseDirectory(), EXPORT_PATH); result.mkdirs(); return result; } @@ -101,11 +100,12 @@ * @return Le storage pour la regle */ public static ExportStorage getExport(String name) { - ExportStorage result = scriptsCache.get(name); + String cacheName = getContextDatabaseCacheKey(name); + ExportStorage result = scriptsCache.get(cacheName); if (result == null) { - result = new ExportStorage(IsisFish.config.getDatabaseDirectory(), + result = new ExportStorage(IsisFish.config.getContextDatabaseDirectory(), getExportDirectory(), name); - scriptsCache.put(name, result); + scriptsCache.put(cacheName, result); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* - * *##% Copyright (C) 2005 - 2009 + * *##% Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or modify it under @@ -73,18 +73,14 @@ * * @param directory region directory * @param name region name - * - * FIXME constructor is public for hack in - * {@link fr.ifremer.isisfish.simulator.SimulationParameter#fromProperties(File, java.util.Properties)} - * set protected when fix hack */ - public RegionStorage(File directory, String name) { + protected RegionStorage(File directory, String name) { super(directory, name); commentForNextCommitFile = new File(getDirectory(), "commentForNextCommit.txt"); } public static File getRegionDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); + File result = getContextDatabaseDirectory(); result = new File(result, REGION_PATH); result.mkdirs(); return result; @@ -160,14 +156,17 @@ @Override public void rename(String toName) throws StorageException { try { - regions.remove(getName()); + String cacheName = getContextDatabaseCacheKey(getName()); + regions.remove(cacheName); super.rename(toName); TopiaContext tx = getStorage().beginTransaction(); FisheryRegion region = getFisheryRegion(tx); region.setName(toName); tx.commitTransaction(); tx.closeContext(); - regions.put(toName, this); + + cacheName = getContextDatabaseCacheKey(toName); + regions.put(cacheName, this); // add storage modification event fireDataChanged(new StorageChangeEvent(this)); @@ -211,41 +210,48 @@ /** * Recupere le TopiaContext d'une region. * + * Call {@code getRegion(String, false)} outside simulation context. + * * @param name le nom de la region a recuperer * @return Le TopiaContext contenant la region, si la region n'existait null * est retourné */ static public RegionStorage getRegion(String name) { - RegionStorage result = regions.get(name); - if (result == null) { - // recherche du repertoire de la region en fonction de la config - File directory = getRegionDirectory(name); - log.info("Try to open region " + name + "(" + directory + ")"); - if (directory.exists()) { - result = new RegionStorage(directory, name); - regions.put(name, result); - } - } - return result; + RegionStorage regionStorage = getRegion(name, false); + return regionStorage; } /** * Recupere le TopiaContext d'une region. * - * @param directory root form where to load database (hack should be removed) * @param name le nom de la region a recuperer + * @param inSimulation this is a hack to known if simulation is requested + * from a simulation or not * @return Le TopiaContext contenant la region, si la region n'existait null * est retourné */ - static public RegionStorage getRegion(File directory, String name) { - RegionStorage result = regions.get(name); + static public RegionStorage getRegion(String name, boolean inSimulation) { + String cacheName = getContextDatabaseCacheKey(name); + RegionStorage result = regions.get(cacheName); if (result == null) { // recherche du repertoire de la region en fonction de la config - //File directory = getRegionDirectory(name); - log.info("Try to open region " + name + " in specific directory (" + directory + ")"); + File directory = null; + + // in simulation context, region is not located in "regions" directory + if (inSimulation) { + directory = getContextDatabaseDirectory(); + } + else { + directory = getRegionDirectory(name); + } + + if (log.isInfoEnabled()) { + log.info("Try to open region " + name + "(" + directory + ")"); + } + if (directory.exists()) { result = new RegionStorage(directory, name); - regions.put(name, result); + regions.put(cacheName, result); } } return result; @@ -293,7 +299,8 @@ throw new StorageException("Can't create new Region", eee); } - regions.put(name, result); + String cacheName = getContextDatabaseCacheKey(name); + regions.put(cacheName, result); // add storage modification event fireDataChanged(new StorageChangeEvent(result)); @@ -311,7 +318,8 @@ // add storage modification event fireDataChanged(new StorageChangeEvent(this)); - regions.remove(getName()); + String cacheName = getContextDatabaseCacheKey(getName()); + regions.remove(cacheName); } /** Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 + * Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or modify it under @@ -83,8 +83,7 @@ } static public File getRuleDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, RULE_PATH); + File result = new File(getContextDatabaseDirectory(), RULE_PATH); result.mkdirs(); return result; } @@ -106,11 +105,12 @@ * @return Le storage pour la regle */ static public RuleStorage getRule(String name) { - RuleStorage result = rulesCache.get(name); + String cacheName = getContextDatabaseCacheKey(name); + RuleStorage result = rulesCache.get(cacheName); if (result == null) { - result = new RuleStorage(IsisFish.config.getDatabaseDirectory(), + result = new RuleStorage(getContextDatabaseDirectory(), getRuleDirectory(), name); - rulesCache.put(name, result); + rulesCache.put(cacheName, result); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 + * Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -75,8 +75,7 @@ } static public File getScriptDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, SCRIPT_PATH); + File result = new File(getContextDatabaseDirectory(), SCRIPT_PATH); result.mkdirs(); return result; } @@ -98,11 +97,12 @@ * @return Le storage pour la regle */ static public ScriptStorage getScript(String name) { - ScriptStorage result = scriptsCache .get(name); + String cacheName = getContextDatabaseCacheKey(name); + ScriptStorage result = scriptsCache.get(cacheName); if (result == null) { - result = new ScriptStorage(IsisFish.config.getDatabaseDirectory(), + result = new ScriptStorage(getContextDatabaseDirectory(), getScriptDirectory(), name); - scriptsCache.put(name, result); + scriptsCache.put(cacheName, result); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2009 Ifremer, Code Lutin + * Copyright (C) 2009-2010 Ifremer, Code Lutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -69,8 +69,7 @@ } public static File getSensitivityExportDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, SENSITIVITY_EXPORT_PATH); + File result = new File(getContextDatabaseDirectory(), SENSITIVITY_EXPORT_PATH); result.mkdirs(); return result; } @@ -93,11 +92,12 @@ * @return Le storage pour la regle */ public static SensitivityExportStorage getSensitivityExport(String name) { - SensitivityExportStorage result = sensitivityExportsCache.get(name); + String cacheName = getContextDatabaseCacheKey(name); + SensitivityExportStorage result = sensitivityExportsCache.get(cacheName); if (result == null) { - result = new SensitivityExportStorage(IsisFish.config.getDatabaseDirectory(), + result = new SensitivityExportStorage(getContextDatabaseDirectory(), getSensitivityExportDirectory(), name); - sensitivityExportsCache.put(name, result); + sensitivityExportsCache.put(cacheName, result); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,4 +1,4 @@ -/* *##% Copyright (C) 2009 Ifremer, Code Lutin +/* *##% Copyright (C) 2009-2010 Ifremer, Code Lutin * * 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 @@ -89,8 +89,7 @@ * @return sensitivity storage directory */ public static File getSensitivityDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, SENSITIVITY_PATH); + File result = new File(getContextDatabaseDirectory(), SENSITIVITY_PATH); result.mkdirs(); return result; } @@ -112,11 +111,11 @@ * @return Le {@link SensitivityStorage} pour le calculateur */ public static SensitivityStorage getSensitivity(String name) { - SensitivityStorage result = sensitivityCache.get(name); + String cacheName = getContextDatabaseCacheKey(name); + SensitivityStorage result = sensitivityCache.get(cacheName); if (result == null) { - result = new SensitivityStorage(IsisFish.config - .getDatabaseDirectory(), getSensitivityDirectory(), name); - sensitivityCache.put(name, result); + result = new SensitivityStorage(getContextDatabaseDirectory(), getSensitivityDirectory(), name); + sensitivityCache.put(cacheName, result); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 + * Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -107,6 +107,7 @@ * @return simulation directory */ public static File getSimulationDirectory() { + // warning, here, do not use getContextDatabaseDirectory() File result = IsisFish.config.getDatabaseDirectory(); result = new File(result, SIMULATION_PATH); if (!result.exists()) { @@ -137,6 +138,7 @@ * @return sensitivity result directory */ public static File getSensitivityResultsDirectory() { + // warning, here, do not use getContextDatabaseDirectory() File result = IsisFish.config.getDatabaseDirectory(); result = new File(result, SENSITIVITY_RESULTS); if (!result.exists()) { @@ -309,7 +311,8 @@ } /** - * Modifie les parametres de la simulation + * Modifie les parametres de la simulation. + * * @param parameter les nouveaux parametres */ public void setParameter(SimulationParameter parameter) { @@ -331,25 +334,10 @@ /** * Get parameter property. - * - * This method open database. - * - * @return Parameter property. - */ - public SimulationParameter getParameter() { - return getParameter(null); - } - - /** - * Get parameter property. - * - * This method open database. * - * @param directory if not null, region will be forced to this directory - * * @return Parameter property. */ - public SimulationParameter getParameter(File directory) { + public SimulationParameter getParameter() { if (parameter == null) { Properties prop = new Properties(); File file = getSimulationParametersFile(); @@ -365,7 +353,7 @@ prop.load(in); in.close(); parameter = new SimulationParameter(); - parameter.fromProperties(directory, prop); + parameter.fromProperties(prop); } catch (IOException eee) { throw new IsisFishRuntimeException(_( "isisfish.error.read.simulation.parameters", file), eee); @@ -375,31 +363,6 @@ } /** - * Get parameter property. - * - * @return Parameter property. - * - * @deprecated restore getParameter() mecanism - */ - public Properties getPropertiesParameter() { - - Properties prop = new Properties(); - File file = getSimulationParametersFile(); - - try { - FileInputStream in = new FileInputStream(file); - prop.load(in); - in.close(); - - } catch (IOException eee) { - throw new IsisFishRuntimeException(_( - "isisfish.error.read.simulation.parameters", file), eee); - } - - return prop; - } - - /** * Permet de force la relecture des parametres et donc que les scripts * soit charge dans le bon classloader * @@ -420,7 +383,7 @@ prop.load(in); in.close(); parameter = new SimulationParameter(); - parameter.fromProperties(getDirectory(), prop); + parameter.fromProperties(prop); } catch (IOException eee) { throw new IsisFishRuntimeException(_( "isisfish.error.read.simulation.parameters", file), eee); Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 + * Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -53,7 +53,7 @@ /** * Constructeur. - * + * * @param rootSrc */ protected SimulatorStorage(File rootSrc, File directory, String name) { @@ -61,17 +61,16 @@ } public static File getSimulatorDirectory() { - File result = IsisFish.config.getDatabaseDirectory(); - result = new File(result, SIMULATOR_PATH); + File result = new File(getContextDatabaseDirectory(), SIMULATOR_PATH); result.mkdirs(); return result; } /** - * Retourne une nouvelle instance de la regle. Compile le fichier si besoin + * Retourne une nouvelle instance du simulateur. Compile le fichier si besoin. * - * @return new rule instance + * @return new simulator instance * @throws IsisFishException */ public Simulator getNewSimulatorInstance() throws IsisFishException { @@ -80,17 +79,20 @@ } /** - * Retourne le storage pour la regle demandée + * Retourne le storage pour le simulateur demandée. * + * {@link SimulatorStorage} is cached by name. + * * @param name le nom de la regle souhaitée * @return Le storage pour la regle */ static public SimulatorStorage getSimulator(String name) { - SimulatorStorage result = simulatorsCache .get(name); + String cacheName = getContextDatabaseCacheKey(name); + SimulatorStorage result = simulatorsCache.get(cacheName); if (result == null) { - result = new SimulatorStorage(IsisFish.config.getDatabaseDirectory(), + result = new SimulatorStorage(getContextDatabaseDirectory(), getSimulatorDirectory(), name); - simulatorsCache.put(name, result); + simulatorsCache.put(cacheName, result); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2006 - 2009 + * Copyright (C) 2006 - 2010 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -71,6 +71,33 @@ } /** + * Return context root directory to use for all data files depending on + * context (simulation/no simulation). + * + * In simulation context, must look for files in simulation directory + * instead of isis database. + * + * TODO better place in other storage, but needed for region anad java scrits + */ + protected static File getContextDatabaseDirectory() { + return IsisFish.config.getContextDatabaseDirectory(); + } + + /** + * Get cache storage key to use depending on context storage used. + * + * Two simulation must have their own cache. + * + * @return context cache key + * + * TODO better place in other storage, but needed for region anad java scrits + */ + protected static String getContextDatabaseCacheKey(String key) { + String result = getContextDatabaseDirectory().getAbsolutePath() + key; + return result; + } + + /** * Get {@link VCS}. * * @return VCS Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -302,6 +302,10 @@ } /** + * Script directory to use. + * + * Used to chnage isis-database-3 directory in running simulation context. + * * @param scriptDirectory */ public void setScriptDirectory(File scriptDirectory) { Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2006 - 2009 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * 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 @@ -192,8 +192,6 @@ /** La region corespondant au parametre {@link #regionName}. */ protected transient RegionStorage region; - /** [HACK] Directory form where region have to be loaded. */ - protected transient File directory; /** * Permet de verifier que tous les parametres sont bon. Si ce n'est pas le @@ -270,21 +268,15 @@ /** * Load region conresponding to {@link #regionName}. * - * Contains a hack to load region from a specific directory - * instead of regions direcory ({@link #directory}). - * * @return the region */ public RegionStorage getRegion() { if (region == null || !region.getName().equals(getRegionName())) { - // hack - if (directory != null) { - // ATTENTION: directory pointe sur le repertoire de la simulation et non de la region - this.region = new RegionStorage(directory, regionName); - } else { - region = RegionStorage.getRegion(getRegionName()); - } + // bien faire attention ici que la bonne region est ouverte + // - isis-database-3 dans le cas d'une region normale + // - simulation dans le cas d'une simulation + region = RegionStorage.getRegion(getRegionName(), true); } else { if (log.isDebugEnabled()) { log.debug(_("Region %s already inited", getRegionName())); @@ -1530,9 +1522,6 @@ public SimulationParameter copy() { SimulationParameter result = new SimulationParameter(); - // just need to copy directory and properties now - result.directory = directory; - if (propertiesParameters != null) { result.propertiesParameters = new SortedProperties(); // I think that iteration work better than parameters in contructor @@ -1598,12 +1587,12 @@ public SimulationParameter deepCopy() { Properties props = toProperties(); SimulationParameter newInstance = new SimulationParameter(); - newInstance.fromProperties(null, props); + newInstance.fromProperties(props); return newInstance; } /** - * The toString() methode call getters. + * The toString() method call getters. * * So make instances of rules/export/plans... */ @@ -1895,16 +1884,14 @@ /** * Load properties from file. - * - * @param directory if not null, region will be forced to this directory + * * @param props property to read */ - public void fromProperties(File directory, Properties props) { + public void fromProperties(Properties props) { // save properties (use full to read again parameter) // for exports, or rules.... this.propertiesParameters = props; - this.directory = directory; } 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 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2002 - 2009 Ifremer, Code Lutin, Benjamin Poussin + * Copyright (C) 2002 - 2010 Ifremer, Code Lutin, Benjamin Poussin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -119,10 +119,9 @@ log.debug("Timing : after import zip : " + new java.util.Date()); } + // WARNING: make sure to not open Region before being in simulation context // add missing control informations - // TODO again region database directory hack - // force region reading in simulation directory - SimulationParameter param = simulation.getParameter(simulation.getFile()); + SimulationParameter param = simulation.getParameter(); control.setDate(new Date()); control.setProgress(0); control.setStarted(true); @@ -330,8 +329,10 @@ // - SimulationContext.get(); // - context.setSimulationControl() classLoader = changeClassLoader(Thread.currentThread(), rootDirectory); - context.setClassLoader(classLoader); + + // this directory is used to change isis-database root directory + // is simulation context context.setScriptDirectory(rootDirectory); context.setSimulationStorage(simulation); Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2005 - 2009 + * Copyright (C) 2005 - 2010 * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -168,7 +168,7 @@ fos = new FileInputStream(f); Properties proper = new Properties(); proper.load(fos); - param.fromProperties(null, proper); + param.fromProperties(proper); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Can't import simulation", e); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java 2010-01-22 15:39:11 UTC (rev 2937) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java 2010-01-22 15:42:09 UTC (rev 2938) @@ -99,7 +99,7 @@ // make transform Properties props = params.toProperties(); SimulationParameter params2 = new SimulationParameter(); - params2.fromProperties(null, props); + params2.fromProperties(props); Assert.assertEquals("3.2.0.4", params2.getIsisFishVersion()); Assert.assertEquals("desc", params2.getDescription()); @@ -123,7 +123,7 @@ Properties props = new SortedProperties(); props.load(basicFileStream); SimulationParameter param = new SimulationParameter(); - param.fromProperties(null, props); + param.fromProperties(props); Assert.assertEquals("3.2.0.6", param.getIsisFishVersion()); @@ -155,11 +155,11 @@ Properties props = new SortedProperties(); props.load(basicFileStream); SimulationParameter param = new SimulationParameter(); - param.fromProperties(null, props); + param.fromProperties(props); Properties props2 = param.toProperties(); SimulationParameter param2 = new SimulationParameter(); - param2.fromProperties(null, props2); + param2.fromProperties(props2); // test rules Assert.assertNull(param.rules); @@ -188,11 +188,11 @@ Properties props = new SortedProperties(); props.load(basicFileStream); SimulationParameter param = new SimulationParameter(); - param.fromProperties(null, props); + param.fromProperties(props); Properties props2 = param.toProperties(); SimulationParameter param2 = new SimulationParameter(); - param2.fromProperties(null, props2); + param2.fromProperties(props2); // test analyse plans Assert.assertNull(param.analysePlans); @@ -213,7 +213,7 @@ Properties props = new SortedProperties(); props.load(basicFileStream); SimulationParameter param = new SimulationParameter(); - param.fromProperties(null, props); + param.fromProperties(props); // force some properties instantiation param.getAnalysePlans(); @@ -243,7 +243,7 @@ props.load(basicFileStream); SimulationParameter param = new SimulationParameter(); - param.fromProperties(null, props); + param.fromProperties(props); String toString = param.toString(); if (log.isInfoEnabled()) {
participants (1)
-
chatellier@users.labs.libre-entreprise.org