Isis-fish-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
August 2012
- 4 participants
- 44 discussions
r3754 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by bpoussin@users.forge.codelutin.com 31 Aug '12
by bpoussin@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: bpoussin
Date: 2012-08-31 20:17:43 +0200 (Fri, 31 Aug 2012)
New Revision: 3754
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3754
Log:
avec un peu de cache, ca va beaucoup mieux :)
13min -> 50s
y'a plus qu'a verifier reellement les resultats :)
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:16:11 UTC (rev 3753)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 18:17:43 UTC (rev 3754)
@@ -27,6 +27,7 @@
import fr.ifremer.isisfish.IsisFishDAOHelper;
import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.entities.ActiveRule;
import fr.ifremer.isisfish.entities.ActiveRuleDAO;
import fr.ifremer.isisfish.entities.Population;
@@ -47,11 +48,14 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import org.apache.commons.collections.BidiMap;
+import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -109,6 +113,8 @@
static final private String SEP = ":";
protected TopiaContext tx;
+ /** en cle les representation interne (get) en valeur les valeurs decoree (getKey) */
+ protected BidiMap cache = new DualHashBidiMap();
public EntitySemanticsDecorator() {
}
@@ -118,47 +124,54 @@
}
public Object decorate(Object internalValue) {
- Object result = internalValue;
- if (internalValue instanceof String) {
- if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int monthNumber = Integer.parseInt(val);
- result = new Month(monthNumber);
- } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int stepNumber = Integer.parseInt(val);
- result = new TimeStep(stepNumber);
- } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
- if (tx == null) {
- result = StringUtils.substringAfter((String)internalValue, SEP);
- } else {
- try {
- String id = StringUtils.substringBefore((String)internalValue, SEP);
- result = tx.findByTopiaId(id);
- } catch (TopiaException eee) {
- log.info("Fallback use string representation because"
- + " i can't decorate (String->Entity): "
- + internalValue, eee);
- // si on arrive pas a convertir cette fois-ci, on
- // renvoi internalValue pour que le undecorate est toutes les infos
- // et donc que la prochaine fois on y arrive peut etre
+ Object result = cache.get(internalValue);
+ if (result == null && internalValue != null) {
+ result = internalValue;
+ if (internalValue instanceof String) {
+ if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int monthNumber = Integer.parseInt(val);
+ result = new Month(monthNumber);
+ } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int stepNumber = Integer.parseInt(val);
+ result = new TimeStep(stepNumber);
+ } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
+ if (tx == null) {
+ result = StringUtils.substringAfter((String)internalValue, SEP);
+ } else {
+ try {
+ String id = StringUtils.substringBefore((String)internalValue, SEP);
+ result = tx.findByTopiaId(id);
+ } catch (TopiaException eee) {
+ log.info("Fallback use string representation because"
+ + " i can't decorate (String->Entity): "
+ + internalValue, eee);
+ // si on arrive pas a convertir cette fois-ci, on
+ // renvoi internalValue pour que le undecorate est toutes les infos
+ // et donc que la prochaine fois on y arrive peut etre
+ }
}
}
}
+ cache.put(internalValue, result);
}
return result;
}
public Object undecorate(Object decoratedValue) {
- String result;
- if (decoratedValue instanceof Month) {
- result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
- } else if (decoratedValue instanceof TimeStep) {
- result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
- } else if (decoratedValue instanceof TopiaEntity) {
- result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
- } else {
- result = String.valueOf(decoratedValue);
+ Object result = cache.getKey(decoratedValue);
+ if (result == null && decoratedValue != null) {
+ if (decoratedValue instanceof Month) {
+ result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
+ } else if (decoratedValue instanceof TimeStep) {
+ result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
+ } else if (decoratedValue instanceof TopiaEntity) {
+ result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
+ } else {
+ result = String.valueOf(decoratedValue);
+ }
+ cache.put(result, decoratedValue);
}
return result;
}
@@ -575,6 +588,19 @@
return getMatrix(step, newName, null);
}
+ /**
+ * Retourne la matrice stocke pour un pas de temps
+ * @param step le pas de temps que l'on souhaite
+ * @param pop la population pour lequelle on souhaite le resultat
+ * @param name le nom des resultats dont on veut la matrice
+ * @return La matrice demandée ou null si aucune matrice ne correspond a
+ * la demande.
+ */
+ public MatrixND getMatrix(TimeStep step, Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName, tx);
+ }
+
public MatrixND getMatrix(TimeStep step, String name) {
return getMatrix(step, name, null);
}
@@ -588,6 +614,7 @@
ResultMapped r = getResult(step, name);
MatrixND mat = null;
if (r != null) {
+ tx = getTx(tx);
mat = r.getMatrix(tx);
}
return mat;
@@ -704,6 +731,7 @@
if (resultMat != null) {
// on decore la matrice resultat au dernier moment, tous les calcules
// ce font avec les strings
+ tx = getTx(tx);
resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
}
return resultMat;
@@ -763,6 +791,29 @@
return result;
}
+ /**
+ * Try to find better tx. If argument is not null, return it. otherwize
+ * try to get tx in SimulationContext.
+ *
+ * @param tx
+ * @return
+ */
+ protected TopiaContext getTx(TopiaContext tx) {
+ TopiaContext result = tx;
+ if (tx == null) {
+ // si on a pas de tx, on recherche si on est dans une simulation
+ // pour recuperer la tx de la simulation
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ try {
+ result = SimulationContext.get().getDB();
+ } catch (TopiaException eee) {
+ throw new IsisFishRuntimeException("Can't get database from SimulationContext", eee);
+ }
+ }
+ }
+ return result;
+ }
+
/*
* @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
*/
1
0
r3753 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by bpoussin@users.forge.codelutin.com 31 Aug '12
by bpoussin@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: bpoussin
Date: 2012-08-31 18:16:11 +0200 (Fri, 31 Aug 2012)
New Revision: 3753
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3753
Log:
petit oubli du add :(
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:16:11 UTC (rev 3753)
@@ -253,6 +253,7 @@
sems[i] = undecorate;
for (Object o : l) {
o = deco.undecorate(o);
+ undecorate.add(o);
raf.writeUTF(o.toString()); // ecriture de chaque dimension
}
}
1
0
r3752 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com 31 Aug '12
by echatellier@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: echatellier
Date: 2012-08-31 18:11:36 +0200 (Fri, 31 Aug 2012)
New Revision: 3752
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3752
Log:
Extract common interface for ResultStorage
Added:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
Copied: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java (from rev 3750, trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -0,0 +1,811 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.datastore;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.util.ArrayUtil;
+import org.nuiton.util.HashList;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.entities.ActiveRule;
+import fr.ifremer.isisfish.entities.ActiveRuleDAO;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.Result;
+import fr.ifremer.isisfish.entities.ResultDAO;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationException;
+import fr.ifremer.isisfish.simulator.SimulationPlan;
+import fr.ifremer.isisfish.simulator.SimulationResultGetter;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * Cette classe permet de conserver des résultats de simulation. Elle permet
+ * ensuite de les récupérer.
+ *
+ * Created: 29 sept. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ResultDatabaseStorage implements SimulationResultGetter, ResultStorage { // ResultDatabaseStorage
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ResultDatabaseStorage.class);
+
+ protected SimulationStorage simulation = null;
+ // transient protected HashMap<String, MatrixND> globalMatrix = new HashMap<String, MatrixND>();
+ transient protected ReferenceMap cacheContext = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
+
+ /** cache to maintains some result. key: String(date + ':' + name), value: matrix
+ * TODO: cache will be more efficient if it keep at min the number of result by year */
+ transient protected ReferenceMap cache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
+ /** contains all available result as string: String(date + ':' + name) */
+ transient protected Set<String> availableResult = null;
+ /** result enabled */
+ transient protected Set<String> enabledResult = null;
+
+ /**
+ * Les ResultStorage ne doivent pas etre instancier directement, mais
+ * recuperer a partir d'un
+ * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
+ *
+ * @param simulation storage to get result
+ */
+ public ResultDatabaseStorage(SimulationStorage simulation) {
+ this.simulation = simulation;
+ }
+
+ protected void putInCache(TimeStep step, String name, MatrixND mat, TopiaContext context) {
+ String key = step.getStep() + ":" + name;
+ putInCache(key, mat, context);
+ }
+
+ protected void putInCache(String name, MatrixND mat, TopiaContext context) {
+ if (mat != null) {
+ cache.put(name, mat);
+ cacheContext.put(name, context);
+ }
+ }
+
+ /**
+ * Result can be removed from cache when computed result (from multiple step)
+ * become invalidated by new step result.
+ *
+ * @param name result name to remove
+ */
+ protected void removeInCache(String name) {
+ cache.remove(name);
+ cacheContext.remove(name);
+ }
+
+ protected MatrixND getInCache(TimeStep step, String name) {
+ // do not use toString for step (depend on i18n)
+ String key = step.getStep() + ":" + name;
+ MatrixND result = getInCache(key);
+ return result;
+ }
+
+ protected MatrixND getInCache(String name) {
+ MatrixND result = null;
+ TopiaContext context = (TopiaContext) cacheContext.get(name);
+ if (context != null && !context.isClosed()) {
+ // on verifie que le context existe encore car on peut vouloir
+ // naviguer dans les semantics
+ result = (MatrixND) cache.get(name);
+ }
+ return result;
+ }
+
+ /**
+ * Retourne le nom de tous les resultats disponibles le nom est constitué
+ * de la date et du nom du resultat.
+ *
+ * @return available results
+ */
+ protected Set<String> getAvailableResult() {
+ if (availableResult == null) {
+ availableResult = new HashSet<String>();
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+
+ List<String> result = (List<String>) tx.findAll("Select " + Result.PROPERTY_RESULT_STEP + "||':'||name from fr.ifremer.isisfish.entities.Result");
+ if (mustClose) {
+ tx.closeContext();
+ }
+ availableResult.addAll(result);
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result available", eee);
+ }
+ }
+ }
+ return availableResult;
+ }
+
+ /**
+ * Verifie si un resultat est disponible pour une date donnée.
+ *
+ * @param step
+ * @param name
+ * @return {@code true} if result is available
+ */
+ protected boolean isAvailableResult(TimeStep step, String name) {
+ String key = step.getStep() + ":" + name;
+ boolean result = getAvailableResult().contains(key);
+ return result;
+ }
+
+ /**
+ * Ajoute un resultat comme etant disponible pour une date donnée.
+ *
+ * @param step
+ * @param name
+ */
+ protected void addAvailableResult(TimeStep step, String name) {
+ String key = step.getStep() + ":" + name;
+ getAvailableResult().add(key);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#isEnabled(java.lang.String)
+ */
+ @Override
+ public boolean isEnabled(String name) {
+ name = name.trim();
+ if (enabledResult == null) {
+ enabledResult = new HashSet<String>();
+
+ Collection<String> resultEnabled = simulation.getParameter()
+ .getResultEnabled();
+ enabledResult.addAll(resultEnabled);
+
+ // test on export
+ List<String> exportNames = simulation.getParameter().getExportNames();
+ if (exportNames != null) {
+ for (String exportName : exportNames) {
+ ExportStorage storage = ExportStorage.getExport(exportName);
+ try {
+ Export export = storage.getNewExportInstance();
+ for (String resultName : export.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ } catch (IsisFishException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("isisfish.error.instanciate.export",
+ exportName), eee);
+ }
+ }
+ }
+ }
+
+ // test on sensitivity export
+ List<SensitivityExport> sensitivityExports = simulation
+ .getParameter().getSensitivityExport();
+ if (sensitivityExports != null) {
+ for (SensitivityExport sensitivityExport : sensitivityExports) {
+ for (String resultName : sensitivityExport.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+
+ // test on rules
+ List<Rule> rules = simulation.getParameter().getRules();
+ if (rules != null) {
+ for (Rule rule : rules) {
+ for (String resultName : rule.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+
+ // test on plans
+ List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
+ if (plans != null) {
+ for (SimulationPlan plan : plans) {
+ for (String resultName : plan.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+ log.info("Enabled result: " + enabledResult);
+ }
+ boolean result = enabledResult.contains(name);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), pop, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), pop, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, java.lang.String, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, pop, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, java.lang.String, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name + " " + pop, mat);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name, mat);
+ }
+ }
+
+ protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ doAddResult(step, name, mat, tx);
+ if (mustClose) {
+ tx.commitTransaction();
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ log.warn("Can't add result '" + name + "' at step " + step, eee);
+ }
+ }
+
+ protected void doAddResult(TimeStep step, String name, MatrixND mat,
+ TopiaContext tx) throws IsisFishException {
+ // si la matrice n'a pas de semantique on refuse
+ for (int i = 0; i < mat.getDimCount(); i++) {
+ // la semantique n'est pas bonne des qu'il y a un null dedans
+ if (mat.getSemantic(i).contains(null)) {
+ throw new SimulationException(
+ "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
+ + i + " " + mat.getDimensionName(i));
+ }
+ }
+
+ // on fait une copie pour avoir reellement des resultats independant
+ // FIXME echatellier 20120829 : faire une copie optimiser
+ // suivant l'implementation du vector plutot qu'un parcourt
+ // via un iterateur de semantiques (plus couteux)
+ MatrixND newMat = mat.copy();
+ try {
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+ Result result = resultPS.create();
+ result.setResultStep(step);
+ result.setName(name);
+ result.setMatrix(newMat);
+ resultPS.update(result);
+
+ addAvailableResult(step, name);
+ putInCache(step, name, newMat, tx);
+
+ // depuis isis fish 4.1.1, le commit est automatique à chaque
+ // résultat (gain de performance de 20% avec le clearCache)
+ tx.commitTransaction();
+ // vide le cache hibernate. Sans cela, les resultats ne sont
+ // jamais supprimé du cache car la session n'est close
+ // qu'à la fin de la simulation
+ tx.clearCache();
+
+ // remove from cache result computed by #getMatrix(name)
+ // beacause, if a new step is added, result become false
+ // but DO NOT REMOVE result named step + name
+ removeInCache(name);
+
+ } catch (TopiaException eee) {
+ log.warn("Can't add result '" + name + "' at step " + step, eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addActiveRule(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.rule.Rule)
+ */
+ @Override
+ public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ ActiveRuleDAO ps = IsisFishDAOHelper.getActiveRuleDAO(tx);
+ ActiveRule result = ps.create();
+ result.setActiveRuleStep(step);
+ result.setName(RuleStorage.getName(rule));
+ result.setParam(RuleStorage.getParamAsString(rule));
+ ps.update(result);
+ if (mustClose) {
+ tx.commitTransaction();
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ throw new IsisFishException("Can't add result", eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getResultName()
+ */
+ @Override
+ public List<String> getResultName() {
+
+ List<String> result = null;
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+
+ result = (List<String>) resultPS.getContext()
+ .findAll("Select distinct name from fr.ifremer.isisfish.entities.Result order by name");
+ if (mustClose) {
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result name", eee);
+ }
+ }
+ if (result == null) {
+ result = new ArrayList<String>();
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, String name) {
+ MatrixND mat = getInCache(step, name);
+ if (mat == null && isAvailableResult(step, name)) {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ mat = getMatrix(step, name, tx);
+ if (mustClose) {
+ // FIXME transaction never closed
+ // quand peut on fermer la transaction ?
+ // lorsque plus aucune matrice ne l'utilise.
+ // donc mettre la matrice et la connexion dans une map
+ // la matrice dans une weak reference. Des que la matrice
+ // est liberer faire un close sur la transaction
+ } else {
+ // echatellier 20120829 : vidage du cache hibernate
+ // sinon on fait trop de lecture que la meme transaction
+ // et le cache hibernate se remplit sans se vider
+ tx.clearCache();
+ }
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't return matrix '" + name + "' for step "
+ + step, eee);
+ }
+ }
+ }
+ return mat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
+ MatrixND mat = getInCache(step, name);
+ if (mat == null && isAvailableResult(step, name)) {
+ try {
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+ Result result = resultPS.findByProperties(
+ Result.PROPERTY_RESULT_STEP, step,
+ Result.PROPERTY_NAME, name);
+ if (result != null) {
+ mat = result.getMatrix();
+ putInCache(step, name, mat, tx);
+ }
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't return matrix '" + name + "' for step "
+ + step, eee);
+ }
+ }
+ }
+ return mat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(newName);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, tx);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(String name) {
+ MatrixND resultMat = null;
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ resultMat = getMatrix(name, tx);
+ if (mustClose) {
+ // FIXME transaction never closed
+ // quand peut on fermer la transaction ?
+ // lorsque plus aucune matrice ne l'utilise.
+ // donc mettre la matrice et la connexion dans une map
+ // la matrice dans une weak reference. Des que la matrice
+ // est liberer faire un close sur la transaction
+ } else {
+ // echatellier 20120829 : vidage du cache hibernate
+ // sinon on fait trop de lecture que la meme transaction
+ // et le cache hibernate se remplit sans se vider
+ tx.clearCache();
+ }
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result: " + name, eee);
+ }
+ }
+ return resultMat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(String name, TopiaContext tx) {
+ log.debug("Get result: " + name);
+
+ MatrixND resultMat = getInCache(name);
+ if (resultMat != null) {
+ return resultMat;
+ }
+
+ // recuperation des resultats qui nous interesse
+ List<Result> results = null;
+ try {
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+ results = resultPS.findAllByName(name);
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result: " + name, eee);
+ }
+ }
+
+ // s'il n'y pas de resultat, on retourne null
+ if (results == null || results.size() == 0) {
+ return null;
+ }
+
+ // Creation des listes pour chaque dimension
+
+ // creation de la liste de date
+ TimeStep lastStep = getLastStep();
+ List<TimeStep> steps = new ArrayList<TimeStep>();
+ TimeStep step = new TimeStep(0);
+ steps.add(step);
+ while (step.before(lastStep)) {
+ step = step.next();
+ steps.add(step);
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("Steps list : " + steps);
+ }
+
+ // recuperation des dimensions des matrices
+ MatrixND mat = (MatrixND) results.get(0).getMatrix();
+
+ // recuperation des noms des dimensions
+ String[] dimNames = new String[1 + mat.getDimCount()];
+ dimNames[0] = _("isisfish.common.date");
+ for (int i = 1; i < dimNames.length; i++) {
+ dimNames[i] = mat.getDimensionName(i - 1);
+ }
+
+ // creation de la semantique pour la matrice resultat. +1 pour les dates
+ List[] sem = new List[1 + mat.getDimCount()];
+ sem[0] = steps;
+
+ for (int i = 1; i < sem.length; i++) {
+ sem[i] = new HashList();
+ }
+
+ for (Result result : results) {
+ MatrixND mattmp = result.getMatrix();
+ if (log.isTraceEnabled()) {
+ log.trace("Ajout de la semantics: "
+ + Arrays.asList(mattmp.getSemantics()));
+ }
+
+ for (int s = 0; s < mattmp.getDimCount(); s++) {
+ sem[s + 1].addAll(mattmp.getSemantic(s));
+ }
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("La semantique final est: " + Arrays.asList(sem));
+ }
+
+ // creation de la matrice resultat
+ resultMat = MatrixFactory.getInstance().create(name, sem, dimNames);
+
+ // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
+ for (Result result : results) {
+ TimeStep d = result.getResultStep();
+ mat = result.getMatrix();
+ // on met ce resultat dans la matrice result si besoin
+ if (mat != null) {
+ // on recupere dans la matrice resultat l'endroit on il faut
+ // mettre la matrice
+ MatrixND submat = resultMat.getSubMatrix(0, d, 1);
+ // on met les valeur de mat dans la sous matrice extraite
+ for (MatrixIterator mi = mat.iterator(); mi.next();) {
+ submat.setValue(
+ ArrayUtil.concat(new Object[] { d },
+ mi.getSemanticsCoordinates()), mi.getValue());
+ }
+ }
+ }
+
+ putInCache(name, resultMat, tx);
+ return resultMat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getLastStep()
+ */
+ @Override
+ public TimeStep getLastStep() {
+ int monthNumber = simulation.getParameter().getNumberOfYear()
+ * Month.NUMBER_OF_MONTH;
+ TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(SimulationContext context, TimeStep step, String name,
+ MatrixND mat) throws IsisFishException {
+ try {
+ doAddResult(step, name, mat, context.getDbResult());
+ } catch (TopiaException eee) {
+ log.warn(_("Can't add result '%1$s' at date %2$s", name, step), eee);
+ }
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(step, name, context.getDbResult());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(name, context.getDbResult());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void afterSimulation(SimulationContext context) {
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void beforeSimulation(SimulationContext context) {
+ }
+
+ // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // rules.add(rule);
+ // }
+
+ // /**
+ // * Retourne pour une date données tous les RegleParam qui ont été activé
+ // * a la date demandé.
+ // * @return une list de {@link fr.ifremer.nodb.RegleParam}
+ // */
+ // public List getActivatedRule(ResultStorage self, Date date){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // return rules;
+ // }
+
+} // ResultDatabaseStorage
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 14:12:18 UTC (rev 3751)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2012 Ifremer, Code Lutin, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -83,7 +83,7 @@
* par : $Author$
*/
public class ResultMappedStorage implements SimulationResultListener,
- SimulationResultGetter { // ResultStorage
+ SimulationResultGetter, ResultStorage { // ResultStorage
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(ResultMappedStorage.class);
@@ -209,7 +209,6 @@
sems[i].add(s);
}
}
-
int size = (int) raf.getFilePointer();
int dataOffset = offset + size;
@@ -602,6 +601,15 @@
String newName = name + " " + pop;
return getMatrix(newName, null);
}
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, tx);
+ }
/**
* Retourne une matrice contenant tous les pas de temps.
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-31 14:12:18 UTC (rev 3751)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -1,214 +1,22 @@
-/*
- * #%L
- * IsisFish
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
- * %%
- * 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, see
- * <http://www.gnu.org/licenses/gpl-2.0.html>.
- * #L%
- */
-
package fr.ifremer.isisfish.datastore;
-import static org.nuiton.i18n.I18n._;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.HibernateException;
-import org.nuiton.math.matrix.MatrixFactory;
-import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImpl;
-import org.nuiton.util.ArrayUtil;
-import org.nuiton.util.HashList;
-import fr.ifremer.isisfish.IsisFishDAOHelper;
import fr.ifremer.isisfish.IsisFishException;
-import fr.ifremer.isisfish.entities.ActiveRule;
-import fr.ifremer.isisfish.entities.ActiveRuleDAO;
import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.entities.Result;
-import fr.ifremer.isisfish.entities.ResultDAO;
import fr.ifremer.isisfish.export.Export;
import fr.ifremer.isisfish.export.SensitivityExport;
import fr.ifremer.isisfish.rule.Rule;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationException;
import fr.ifremer.isisfish.simulator.SimulationPlan;
-import fr.ifremer.isisfish.simulator.SimulationResultGetter;
import fr.ifremer.isisfish.simulator.SimulationResultListener;
import fr.ifremer.isisfish.types.TimeStep;
-import fr.ifremer.isisfish.types.Month;
-/**
- * Cette classe permet de conserver des résultats de simulation. Elle permet
- * ensuite de les récupérer.
- *
- * Created: 29 sept. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class ResultStorage implements SimulationResultListener,
- SimulationResultGetter { // ResultStorage
+public interface ResultStorage extends SimulationResultListener {
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(ResultStorage.class);
-
- protected SimulationStorage simulation = null;
- // transient protected HashMap<String, MatrixND> globalMatrix = new HashMap<String, MatrixND>();
- transient protected ReferenceMap cacheContext = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
-
- /** cache to maintains some result. key: String(date + ':' + name), value: matrix
- * TODO: cache will be more efficient if it keep at min the number of result by year */
- transient protected ReferenceMap cache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
- /** contains all available result as string: String(date + ':' + name) */
- transient protected Set<String> availableResult = null;
- /** result enabled */
- transient protected Set<String> enabledResult = null;
-
/**
- * Les ResultStorage ne doivent pas etre instancier directement, mais
- * recuperer a partir d'un
- * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
- *
- * @param simulation storage to get result
- */
- public ResultStorage(SimulationStorage simulation) {
- this.simulation = simulation;
- }
-
- protected void putInCache(TimeStep step, String name, MatrixND mat, TopiaContext context) {
- String key = step.getStep() + ":" + name;
- putInCache(key, mat, context);
- }
-
- protected void putInCache(String name, MatrixND mat, TopiaContext context) {
- if (mat != null) {
- cache.put(name, mat);
- cacheContext.put(name, context);
- }
- }
-
- /**
- * Result can be removed from cache when computed result (from multiple step)
- * become invalidated by new step result.
- *
- * @param name result name to remove
- */
- protected void removeInCache(String name) {
- cache.remove(name);
- cacheContext.remove(name);
- }
-
- protected MatrixND getInCache(TimeStep step, String name) {
- // do not use toString for step (depend on i18n)
- String key = step.getStep() + ":" + name;
- MatrixND result = getInCache(key);
- return result;
- }
-
- protected MatrixND getInCache(String name) {
- MatrixND result = null;
- TopiaContext context = (TopiaContext) cacheContext.get(name);
- if (context != null && !context.isClosed()) {
- // on verifie que le context existe encore car on peut vouloir
- // naviguer dans les semantics
- result = (MatrixND) cache.get(name);
- }
- return result;
- }
-
- /**
- * Retourne le nom de tous les resultats disponibles le nom est constitué
- * de la date et du nom du resultat.
- *
- * @return available results
- */
- protected Set<String> getAvailableResult() {
- if (availableResult == null) {
- availableResult = new HashSet<String>();
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
-
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
-
- List<String> result = (List<String>) tx.findAll("Select " + Result.PROPERTY_RESULT_STEP + "||':'||name from fr.ifremer.isisfish.entities.Result");
- if (mustClose) {
- tx.closeContext();
- }
- availableResult.addAll(result);
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result available", eee);
- }
- }
- }
- return availableResult;
- }
-
- /**
- * Verifie si un resultat est disponible pour une date donnée.
- *
- * @param step
- * @param name
- * @return {@code true} if result is available
- */
- protected boolean isAvailableResult(TimeStep step, String name) {
- String key = step.getStep() + ":" + name;
- boolean result = getAvailableResult().contains(key);
- return result;
- }
-
- /**
- * Ajoute un resultat comme etant disponible pour une date donnée.
- *
- * @param step
- * @param name
- */
- protected void addAvailableResult(TimeStep step, String name) {
- String key = step.getStep() + ":" + name;
- getAvailableResult().add(key);
- }
-
- /**
* Permet de savoir si lorsque l'on ajoutera ce resultat, il sera
* sauvé ou non.
*
@@ -223,241 +31,41 @@
* @param name result name
* @return {@code true} if result is enabled
*/
- public boolean isEnabled(String name) {
- name = name.trim();
- if (enabledResult == null) {
- enabledResult = new HashSet<String>();
+ public boolean isEnabled(String name);
- Collection<String> resultEnabled = simulation.getParameter()
- .getResultEnabled();
- enabledResult.addAll(resultEnabled);
+ public void addResult(TimeStep step, MatrixND mat) throws IsisFishException;
- // test on export
- List<String> exportNames = simulation.getParameter().getExportNames();
- if (exportNames != null) {
- for (String exportName : exportNames) {
- ExportStorage storage = ExportStorage.getExport(exportName);
- try {
- Export export = storage.getNewExportInstance();
- for (String resultName : export.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- } catch (IsisFishException eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("isisfish.error.instanciate.export",
- exportName), eee);
- }
- }
- }
- }
+ public void addResult(TimeStep step, Population pop, MatrixND mat)
+ throws IsisFishException;
- // test on sensitivity export
- List<SensitivityExport> sensitivityExports = simulation
- .getParameter().getSensitivityExport();
- if (sensitivityExports != null) {
- for (SensitivityExport sensitivityExport : sensitivityExports) {
- for (String resultName : sensitivityExport.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
+ public void addResult(boolean force, TimeStep step, MatrixND mat)
+ throws IsisFishException;
- // test on rules
- List<Rule> rules = simulation.getParameter().getRules();
- if (rules != null) {
- for (Rule rule : rules) {
- for (String resultName : rule.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
+ public void addResult(boolean force, TimeStep step, Population pop,
+ MatrixND mat) throws IsisFishException;
- // test on plans
- List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
- if (plans != null) {
- for (SimulationPlan plan : plans) {
- for (String resultName : plan.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
- log.info("Enabled result: " + enabledResult);
- }
- boolean result = enabledResult.contains(name);
- return result;
- }
+ public void addResult(TimeStep step, String name, Population pop,
+ MatrixND mat) throws IsisFishException;
- public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), mat);
- }
+ public void addResult(TimeStep step, String name, MatrixND mat)
+ throws IsisFishException;
- public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), pop, mat);
- }
+ public void addResult(boolean force, TimeStep step, String name,
+ Population pop, MatrixND mat) throws IsisFishException;
- public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), mat);
- }
+ public void addResult(boolean force, TimeStep step, String name,
+ MatrixND mat) throws IsisFishException;
- public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), pop, mat);
- }
+ public void addActiveRule(TimeStep step, Rule rule)
+ throws IsisFishException;
- public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, pop, mat);
- }
-
- public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, mat);
- }
-
- public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name + " " + pop, mat);
- }
- }
-
- public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name, mat);
- }
- }
-
- protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- doAddResult(step, name, mat, tx);
- if (mustClose) {
- tx.commitTransaction();
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- log.warn("Can't add result '" + name + "' at step " + step, eee);
- }
- }
-
- protected void doAddResult(TimeStep step, String name, MatrixND mat,
- TopiaContext tx) throws IsisFishException {
- // si la matrice n'a pas de semantique on refuse
- for (int i = 0; i < mat.getDimCount(); i++) {
- // la semantique n'est pas bonne des qu'il y a un null dedans
- if (mat.getSemantic(i).contains(null)) {
- throw new SimulationException(
- "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
- + i + " " + mat.getDimensionName(i));
- }
- }
-
- // on fait une copie pour avoir reellement des resultats independant
- // FIXME echatellier 20120829 : faire une copie optimiser
- // suivant l'implementation du vector plutot qu'un parcourt
- // via un iterateur de semantiques (plus couteux)
- MatrixND newMat = mat.copy();
- try {
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
- Result result = resultPS.create();
- result.setResultStep(step);
- result.setName(name);
- result.setMatrix(newMat);
- resultPS.update(result);
-
- addAvailableResult(step, name);
- putInCache(step, name, newMat, tx);
-
- // depuis isis fish 4.1.1, le commit est automatique à chaque
- // résultat (gain de performance de 20% avec le clearCache)
- tx.commitTransaction();
- // vide le cache hibernate. Sans cela, les resultats ne sont
- // jamais supprimé du cache car la session n'est close
- // qu'à la fin de la simulation
- tx.clearCache();
-
- // remove from cache result computed by #getMatrix(name)
- // beacause, if a new step is added, result become false
- // but DO NOT REMOVE result named step + name
- removeInCache(name);
-
- } catch (TopiaException eee) {
- log.warn("Can't add result '" + name + "' at step " + step, eee);
- }
- }
-
- public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- ActiveRuleDAO ps = IsisFishDAOHelper.getActiveRuleDAO(tx);
- ActiveRule result = ps.create();
- result.setActiveRuleStep(step);
- result.setName(RuleStorage.getName(rule));
- result.setParam(RuleStorage.getParamAsString(rule));
- ps.update(result);
- if (mustClose) {
- tx.commitTransaction();
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- throw new IsisFishException("Can't add result", eee);
- }
- }
-
/**
* Retourne la liste de tous les résultats. Si le résultat est categorisé
* par une population alors le nom de la population est automatiquement
* ajouté au nom du résultat.
*/
- public List<String> getResultName() {
+ public List<String> getResultName();
- List<String> result = null;
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
-
- result = (List<String>) resultPS.getContext()
- .findAll("Select distinct name from fr.ifremer.isisfish.entities.Result order by name");
- if (mustClose) {
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result name", eee);
- }
- }
- if (result == null) {
- result = new ArrayList<String>();
- }
- return result;
- }
-
/**
* Retourne la matrice stocke pour un pas de temps
* @param step le pas de temps que l'on souhaite
@@ -466,50 +74,10 @@
* @return La matrice demandée ou null si aucune matrice ne correspond a
* la demande.
*/
- public MatrixND getMatrix(TimeStep step, Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(step, newName);
- }
+ public MatrixND getMatrix(TimeStep step, Population pop, String name);
- public MatrixND getMatrix(TimeStep step, String name) {
- MatrixND mat = getInCache(step, name);
- if (mat == null && isAvailableResult(step, name)) {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
+ public MatrixND getMatrix(TimeStep step, String name);
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- mat = getMatrix(step, name, tx);
- if (mustClose) {
- // FIXME transaction never closed
- // quand peut on fermer la transaction ?
- // lorsque plus aucune matrice ne l'utilise.
- // donc mettre la matrice et la connexion dans une map
- // la matrice dans une weak reference. Des que la matrice
- // est liberer faire un close sur la transaction
- } else {
- // echatellier 20120829 : vidage du cache hibernate
- // sinon on fait trop de lecture que la meme transaction
- // et le cache hibernate se remplit sans se vider
- tx.clearCache();
- }
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't return matrix '" + name + "' for step "
- + step, eee);
- }
- }
- }
- return mat;
- }
-
/**
* Retourne la matrice stocke pour un pas de temps.
*
@@ -519,37 +87,14 @@
* @return La matrice demandée ou {@code null} si aucune matrice ne correspond a
* la demande.
*/
- public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
- MatrixND mat = getInCache(step, name);
- if (mat == null && isAvailableResult(step, name)) {
- try {
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
- Result result = resultPS.findByProperties(
- Result.PROPERTY_RESULT_STEP, step,
- Result.PROPERTY_NAME, name);
- if (result != null) {
- mat = result.getMatrix();
- putInCache(step, name, mat, tx);
- }
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't return matrix '" + name + "' for step "
- + step, eee);
- }
- }
- }
- return mat;
- }
+ public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx);
/**
* Retourne une matrice contenant tous les pas de temps.
* @param pop la population pour lequel on souhaite la matrice
* @param name le nom des resultats dont on veut une matrice globale.
*/
- public MatrixND getMatrix(Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(newName);
- }
+ public MatrixND getMatrix(Population pop, String name);
/**
* Retourne une matrice contenant tous les pas de temps.
@@ -558,245 +103,25 @@
* @param tx la transaction a utiliser
* @since 4.1.0.0
*/
- public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
- String newName = name + " " + pop;
- return getMatrix(newName, tx);
- }
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx);
/**
* Retourne une matrice contenant tous les pas de temps.
* @param name le nom des resultats dont on veut une matrice globale.
*/
- public MatrixND getMatrix(String name) {
- MatrixND resultMat = null;
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
+ public MatrixND getMatrix(String name);
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- resultMat = getMatrix(name, tx);
- if (mustClose) {
- // FIXME transaction never closed
- // quand peut on fermer la transaction ?
- // lorsque plus aucune matrice ne l'utilise.
- // donc mettre la matrice et la connexion dans une map
- // la matrice dans une weak reference. Des que la matrice
- // est liberer faire un close sur la transaction
- } else {
- // echatellier 20120829 : vidage du cache hibernate
- // sinon on fait trop de lecture que la meme transaction
- // et le cache hibernate se remplit sans se vider
- tx.clearCache();
- }
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result: " + name, eee);
- }
- }
- return resultMat;
- }
-
/**
* Retourne une matrice contenant tous les pas de temps.
* @param name le nom des resultats dont on veut une matrice globale.
* @param tx TopiaContext a utiliser pour recuperer les resultats et donc les semantiques
*/
- public MatrixND getMatrix(String name, TopiaContext tx) {
- log.debug("Get result: " + name);
+ public MatrixND getMatrix(String name, TopiaContext tx);
- MatrixND resultMat = getInCache(name);
- if (resultMat != null) {
- return resultMat;
- }
-
- // recuperation des resultats qui nous interesse
- List<Result> results = null;
- try {
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
- results = resultPS.findAllByName(name);
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result: " + name, eee);
- }
- }
-
- // s'il n'y pas de resultat, on retourne null
- if (results == null || results.size() == 0) {
- return null;
- }
-
- // Creation des listes pour chaque dimension
-
- // creation de la liste de date
- TimeStep lastStep = getLastStep();
- List<TimeStep> steps = new ArrayList<TimeStep>();
- TimeStep step = new TimeStep(0);
- steps.add(step);
- while (step.before(lastStep)) {
- step = step.next();
- steps.add(step);
- }
-
- if (log.isTraceEnabled()) {
- log.trace("Steps list : " + steps);
- }
-
- // recuperation des dimensions des matrices
- MatrixND mat = (MatrixND) results.get(0).getMatrix();
-
- // recuperation des noms des dimensions
- String[] dimNames = new String[1 + mat.getDimCount()];
- dimNames[0] = _("isisfish.common.date");
- for (int i = 1; i < dimNames.length; i++) {
- dimNames[i] = mat.getDimensionName(i - 1);
- }
-
- // creation de la semantique pour la matrice resultat. +1 pour les dates
- List[] sem = new List[1 + mat.getDimCount()];
- sem[0] = steps;
-
- for (int i = 1; i < sem.length; i++) {
- sem[i] = new HashList();
- }
-
- for (Result result : results) {
- MatrixND mattmp = result.getMatrix();
- if (log.isTraceEnabled()) {
- log.trace("Ajout de la semantics: "
- + Arrays.asList(mattmp.getSemantics()));
- }
-
- for (int s = 0; s < mattmp.getDimCount(); s++) {
- sem[s + 1].addAll(mattmp.getSemantic(s));
- }
- }
-
- if (log.isTraceEnabled()) {
- log.trace("La semantique final est: " + Arrays.asList(sem));
- }
-
- // creation de la matrice resultat
- resultMat = MatrixFactory.getInstance().create(name, sem, dimNames);
-
- // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
- for (Result result : results) {
- TimeStep d = result.getResultStep();
- mat = result.getMatrix();
- // on met ce resultat dans la matrice result si besoin
- if (mat != null) {
- // on recupere dans la matrice resultat l'endroit on il faut
- // mettre la matrice
- MatrixND submat = resultMat.getSubMatrix(0, d, 1);
- // on met les valeur de mat dans la sous matrice extraite
- for (MatrixIterator mi = mat.iterator(); mi.next();) {
- submat.setValue(
- ArrayUtil.concat(new Object[] { d },
- mi.getSemanticsCoordinates()), mi.getValue());
- }
- }
- }
-
- putInCache(name, resultMat, tx);
- return resultMat;
- }
-
/**
* Get last simulation date.
*
* @return last simulation date
*/
- public TimeStep getLastStep() {
- int monthNumber = simulation.getParameter().getNumberOfYear()
- * Month.NUMBER_OF_MONTH;
- TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(SimulationContext context, TimeStep step, String name,
- MatrixND mat) throws IsisFishException {
- try {
- doAddResult(step, name, mat, context.getDbResult());
- } catch (TopiaException eee) {
- log.warn(_("Can't add result '%1$s' at date %2$s", name, step), eee);
- }
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
- MatrixND result = null;
- try {
- result = getMatrix(step, name, context.getDbResult());
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("Can't get result: %1$s", name), eee);
- }
- }
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, String name) {
- MatrixND result = null;
- try {
- result = getMatrix(name, context.getDbResult());
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("Can't get result: %1$s", name), eee);
- }
- }
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void afterSimulation(SimulationContext context) {
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void beforeSimulation(SimulationContext context) {
- }
-
- // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
- // List rules = (List)activatedRules.get(date);
- // if(rules == null){
- // activatedRules.put(date, rules = new LinkedList());
- // }
- // rules.add(rule);
- // }
-
- // /**
- // * Retourne pour une date données tous les RegleParam qui ont été activé
- // * a la date demandé.
- // * @return une list de {@link fr.ifremer.nodb.RegleParam}
- // */
- // public List getActivatedRule(ResultStorage self, Date date){
- // List rules = (List)activatedRules.get(date);
- // if(rules == null){
- // activatedRules.put(date, rules = new LinkedList());
- // }
- // return rules;
- // }
-
-} // ResultStorage
+ public TimeStep getLastStep();
+}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-08-31 14:12:18 UTC (rev 3751)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -444,15 +444,20 @@
}
/**
- * Get simulation {@link ResultStorage}.
+ * Get simulation {@link ResultDatabaseStorage}.
*
- * @return le {@link ResultStorage} a utiliser pour cette simulation
+ * @return le {@link ResultDatabaseStorage} a utiliser pour cette simulation
+ * @throws StorageException
*/
- public ResultStorage getResultStorage() {
+ public ResultStorage getResultStorage() throws StorageException {
if (resultStorage == null) {
- // FIXME poussin 20120831 en fonction de la version de la base
// instancier un ResultStorage ou un ResultMappedStorage
- resultStorage = new ResultStorage(this);
+ //resultStorage = new ResultDatabaseStorage(this);
+ try {
+ resultStorage = new ResultMappedStorage(this);
+ } catch (IOException ex) {
+ throw new StorageException("Can't get storage", ex);
+ }
}
return resultStorage;
}
1
0
r3751 - in trunk/src/main: java/fr/ifremer/isisfish/mexico java/fr/ifremer/isisfish/ui/sensitivity resources/i18n
by echatellier@users.forge.codelutin.com 31 Aug '12
by echatellier@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: echatellier
Date: 2012-08-31 16:12:18 +0200 (Fri, 31 Aug 2012)
New Revision: 3751
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3751
Log:
fixes #1450 : Add option to export factor list into mexico xml file
Modified:
trunk/src/main/java/fr/ifremer/isisfish/mexico/MexicoHelper.java
trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java
trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
Modified: trunk/src/main/java/fr/ifremer/isisfish/mexico/MexicoHelper.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/mexico/MexicoHelper.java 2012-08-31 13:09:22 UTC (rev 3750)
+++ trunk/src/main/java/fr/ifremer/isisfish/mexico/MexicoHelper.java 2012-08-31 14:12:18 UTC (rev 3751)
@@ -45,6 +45,8 @@
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.logging.Log;
@@ -59,6 +61,7 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.xml.sax.InputSource;
import fr.ifremer.isisfish.IsisFishDAOHelper;
@@ -106,7 +109,20 @@
designPlanXml = MexicoHelper.formatXML(designPlanXml);
return designPlanXml;
+ }
+ /**
+ * Convert design plan to xml and write it to given file.
+ *
+ * @param designPlan
+ */
+ public static void writeDesignPlanToFile(File file, DesignPlan designPlan) {
+ String content = getDesignPlanAsXML(designPlan);
+ try {
+ FileUtils.writeStringToFile(file, content);
+ } catch (IOException ex) {
+ throw new IsisFishRuntimeException("Can't export factors to xml file", ex);
+ }
}
/**
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2012-08-31 13:09:22 UTC (rev 3750)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2012-08-31 14:12:18 UTC (rev 3751)
@@ -29,6 +29,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -51,6 +53,8 @@
import jaxx.runtime.context.JAXXInitialContext;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -61,12 +65,15 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityContextable;
+import org.nuiton.util.FileUtil;
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.datastore.RegionStorage;
import fr.ifremer.isisfish.entities.Equation;
import fr.ifremer.isisfish.entities.FisheryRegion;
+import fr.ifremer.isisfish.mexico.MexicoHelper;
import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
import fr.ifremer.isisfish.simulator.sensitivity.Domain;
import fr.ifremer.isisfish.simulator.sensitivity.Factor;
import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup;
@@ -91,8 +98,8 @@
import fr.ifremer.isisfish.ui.input.tree.FisheryTreeRenderer;
import fr.ifremer.isisfish.ui.simulator.RuleChooser;
import fr.ifremer.isisfish.ui.simulator.SimulAction;
+import fr.ifremer.isisfish.ui.widget.editor.MonthComponent;
import fr.ifremer.isisfish.ui.widget.editor.StepComponent;
-import fr.ifremer.isisfish.ui.widget.editor.MonthComponent;
/**
* Handler for sensitivity tab ui (fishery region factors).
@@ -1266,4 +1273,33 @@
factorWizardUI.getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree();
factorWizardUI.dispose();
}
+
+ /**
+ * Export factors list to xml mexico file.
+ *
+ * @since 4.1.1.2
+ */
+ public void exportFactorsToMexico(SensitivityTabUI view) {
+ File xmlFile = FileUtil.getFile(_("isisfish.sensitivity.mexico.exporttoxml.title"),
+ _("isisfish.sensitivity.mexico.exporttoxml.approve"), view,
+ new String[]{
+ ".*\\.xml",
+ _("isisfish.sensitivity.mexico.exporttoxml.filter")
+ });
+
+ if (xmlFile != null) {
+
+ // try to add ".xml" extension if no present
+ if (!FilenameUtils.isExtension(xmlFile.getAbsolutePath(), "xml")) {
+ xmlFile = new File(xmlFile.getAbsolutePath() + ".xml");
+ }
+
+ SimulAction simulAction = view.getContextValue(SimulAction.class);
+
+ DesignPlan designPlan = new DesignPlan();
+ designPlan.setFactorGroup(simulAction.getFactorGroup());
+ String xml = MexicoHelper.getDesignPlanAsXML(designPlan);
+ MexicoHelper.writeDesignPlanToFile(xmlFile, designPlan);
+ }
+ }
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx 2012-08-31 13:09:22 UTC (rev 3750)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx 2012-08-31 14:12:18 UTC (rev 3751)
@@ -108,13 +108,17 @@
<JButton icon="factors/dgroup.png" toolTipText="isisfish.sensitivity.newfactordgroup.tip"
onActionPerformed="getHandler().addNewFactorGroup(this, false)"/>
</cell>
- <cell anchor='west' weightx='1'>
+ <cell anchor='west'>
<JButton icon="factors/cgroup.png" toolTipText="isisfish.sensitivity.newfactorcgroup.tip"
onActionPerformed="getHandler().addNewFactorGroup(this, true)"/>
</cell>
+ <cell anchor='west' weightx='1'>
+ <JButton icon="script_go.png" toolTipText="isisfish.sensitivity.mexico.exporttoxml.tip"
+ onActionPerformed="getHandler().exportFactorsToMexico(this)"/>
+ </cell>
</row>
<row>
- <cell columns='2' fill="both" weightx='1.0' weighty='1.0'>
+ <cell columns='3' fill="both" weightx='1.0' weighty='1.0'>
<JScrollPane>
<FactorTree id="factorsTree" constructorParams='this'
rootVisible="true" selectionRow='0'
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-31 13:09:22 UTC (rev 3750)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-31 14:12:18 UTC (rev 3751)
@@ -866,6 +866,10 @@
isisfish.sensitivity.increment=Cardinality
isisfish.sensitivity.lastValue=Last value
isisfish.sensitivity.methodfactorsupported=The selected sensitivity method handles factors cardinalities
+isisfish.sensitivity.mexico.exporttoxml.approve=Export
+isisfish.sensitivity.mexico.exporttoxml.filter=Xml files
+isisfish.sensitivity.mexico.exporttoxml.tip=Export factors to mexico xml file
+isisfish.sensitivity.mexico.exporttoxml.title=Export factors to mexico xml file
isisfish.sensitivity.moveillegal=Can't move discrete factor to continuous group \!
isisfish.sensitivity.name=Factor name
isisfish.sensitivity.newfactorcgroup.tip=Add new continuous factor group
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-31 13:09:22 UTC (rev 3750)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-31 14:12:18 UTC (rev 3751)
@@ -866,6 +866,10 @@
isisfish.sensitivity.increment=Cardinalité
isisfish.sensitivity.lastValue=Dernière valeur
isisfish.sensitivity.methodfactorsupported=La méthode de sensibilité choisie gère les cardinalités des facteurs
+isisfish.sensitivity.mexico.exporttoxml.approve=Exporter
+isisfish.sensitivity.mexico.exporttoxml.filter=Fichier XML
+isisfish.sensitivity.mexico.exporttoxml.tip=Exporter les facteurs vers un fichier xml mexico
+isisfish.sensitivity.mexico.exporttoxml.title=Exporter les facteurs vers un fichier xml mexico
isisfish.sensitivity.moveillegal=Impossible d'ajouter un facteur discret dans un groupe continu \!
isisfish.sensitivity.name=Nom du facteur
isisfish.sensitivity.newfactorcgroup.tip=Ajouter un groupe de facteur continu
1
0
r3750 - in trunk: . src/main/java/fr/ifremer/isisfish/datastore
by bpoussin@users.forge.codelutin.com 31 Aug '12
by bpoussin@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: bpoussin
Date: 2012-08-31 15:09:22 +0200 (Fri, 31 Aug 2012)
New Revision: 3750
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3750
Log:
ajout de l'implantation d'un ResultStorage sur un RandomAccessFile
Added:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-30 14:46:24 UTC (rev 3749)
+++ trunk/pom.xml 2012-08-31 13:09:22 UTC (rev 3750)
@@ -62,7 +62,7 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Copied: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java (from rev 3749, trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 13:09:22 UTC (rev 3750)
@@ -0,0 +1,792 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.datastore;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.entities.ActiveRule;
+import fr.ifremer.isisfish.entities.ActiveRuleDAO;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationException;
+import fr.ifremer.isisfish.simulator.SimulationPlan;
+import fr.ifremer.isisfish.simulator.SimulationResultGetter;
+import fr.ifremer.isisfish.simulator.SimulationResultListener;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeStep;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.DoubleBigMappedVector;
+import org.nuiton.math.matrix.MatrixFactory;
+import org.nuiton.math.matrix.MatrixHelper;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.math.matrix.MatrixSemanticsDecorator;
+import org.nuiton.math.matrix.SemanticsDecorator;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.ArrayUtil;
+import org.nuiton.util.HashList;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Cette classe permet de conserver des résultats de simulation. Elle permet
+ * ensuite de les récupérer.
+ *
+ * Created: 31 aout 2012
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ResultMappedStorage implements SimulationResultListener,
+ SimulationResultGetter { // ResultStorage
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ResultMappedStorage.class);
+
+ static protected MatrixFactory matrixFactory = MatrixFactory.getInstance(DoubleBigMappedVector.class);
+
+ protected SimulationStorage simulation = null;
+ protected RandomAccessFile raf;
+ protected int offset;
+ protected Map<TimeStep, Map<String, ResultMapped>> stepNameResults =
+ new TreeMap<TimeStep, Map<String, ResultMapped>>();
+ protected Map<String, Map<TimeStep, ResultMapped>> nameStepResults =
+ new TreeMap<String, Map<TimeStep, ResultMapped>>();
+
+ /** result enabled */
+ transient protected Set<String> enabledResult = null;
+
+ /**
+ * Convertie une entite, month, timestep en string et inversement.
+ * Entity = "TopiaId:Entity.toString"
+ */
+ static protected class EntitySemanticsDecorator implements SemanticsDecorator {
+ static final private String SEP = ":";
+
+ protected TopiaContext tx;
+
+ public EntitySemanticsDecorator() {
+ }
+
+ public EntitySemanticsDecorator(TopiaContext tx) {
+ this.tx = tx;
+ }
+
+ public Object decorate(Object internalValue) {
+ Object result = internalValue;
+ if (internalValue instanceof String) {
+ if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int monthNumber = Integer.parseInt(val);
+ result = new Month(monthNumber);
+ } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int stepNumber = Integer.parseInt(val);
+ result = new TimeStep(stepNumber);
+ } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
+ if (tx == null) {
+ result = StringUtils.substringAfter((String)internalValue, SEP);
+ } else {
+ try {
+ String id = StringUtils.substringBefore((String)internalValue, SEP);
+ result = tx.findByTopiaId(id);
+ } catch (TopiaException eee) {
+ log.info("Fallback use string representation because"
+ + " i can't decorate (String->Entity): "
+ + internalValue, eee);
+ // si on arrive pas a convertir cette fois-ci, on
+ // renvoi internalValue pour que le undecorate est toutes les infos
+ // et donc que la prochaine fois on y arrive peut etre
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public Object undecorate(Object decoratedValue) {
+ String result;
+ if (decoratedValue instanceof Month) {
+ result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
+ } else if (decoratedValue instanceof TimeStep) {
+ result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
+ } else if (decoratedValue instanceof TopiaEntity) {
+ result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
+ } else {
+ result = String.valueOf(decoratedValue);
+ }
+ return result;
+ }
+
+ }
+
+ /**
+ * Represente un resultat
+ * Lors de la construction, si on ne passe que le RandomAccessFile et l'offset, on relie un resultat
+ * si on passe toutes les infos, on ecrit le resultat.
+ * Les deux operations doivent etre symetrique on lit et ecrit les meme informations
+ */
+ static protected class ResultMapped {
+ protected RandomAccessFile raf;
+ protected int offset;
+ protected int size;
+ protected TimeStep step;
+ protected String name;
+ protected MatrixND matrix;
+
+ /** read data from file */
+ public ResultMapped(RandomAccessFile raf, int offset) throws IOException {
+ this.raf = raf;
+ this.offset = offset;
+
+ int stepValue = raf.readInt();
+ step = new TimeStep(stepValue);
+
+ name = raf.readUTF();
+
+ int dimSize = raf.readInt();
+
+ String[] dimNames = new String[dimSize];
+ for (int i=0; i<dimSize; i++) {
+ dimNames[i] = raf.readUTF();
+ }
+
+ int[] dims = new int[dimSize];
+ for (int i=0; i<dimSize; i++) {
+ dims[i] = raf.readInt();
+ }
+
+ List[] sems = new List[dimSize];
+ for (int i=0; i<dimSize; i++) {
+ sems[i] = new ArrayList();
+ for (int j=0; j<dims[i]; j++) {
+ String s = raf.readUTF();
+ sems[i].add(s);
+ }
+ }
+
+
+ int size = (int) raf.getFilePointer();
+ int dataOffset = offset + size;
+
+ int dataSize = raf.readInt();
+ DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
+ this.matrix = matrixFactory.create(name, sems, dimNames, data);
+
+ size += dataSize * 8; /* un double est sur 8 bytes*/
+ this.size = size;
+ }
+
+ /** write date to file */
+ public ResultMapped(RandomAccessFile raf, int offset,
+ TimeStep step, String name, MatrixND matrix) throws IOException {
+ this.raf = raf;
+ this.offset = offset;
+ this.step = step;
+ this.name = name;
+
+ String[] dimNames = matrix.getDimensionNames();
+ int[] dims = matrix.getDim();
+ List[] sems = matrix.getSemantics();
+ int dataSize = MatrixHelper.getVectorSize(dims);
+
+ raf.write(step.getStep()); // ecriture du pas de temps
+ raf.writeUTF(name); // ecriture du nom du resultat
+ raf.write(dims.length); // ecriture de la taille du tableau de dimension et semantique
+
+ for (String s : dimNames) {
+ raf.writeUTF(s); // ecriture du nom de chaque dimensions
+ }
+ for (int d : dims) {
+ raf.write(d); // ecriture de chaque dimension
+ }
+
+ // conversion et enregistrement des semantiques
+ SemanticsDecorator deco = new EntitySemanticsDecorator();
+ for (int i=0; i<sems.length; i ++) {
+ List l = sems[i];
+ List undecorate = new ArrayList(l.size());
+ sems[i] = undecorate;
+ for (Object o : l) {
+ o = deco.undecorate(o);
+ raf.writeUTF(o.toString()); // ecriture de chaque dimension
+ }
+ }
+
+ raf.writeInt(dataSize);
+
+ // on prend la position apres l'ecriture de l'entete
+ int size = (int) raf.getFilePointer();
+
+ int dataOffset = offset + size;
+ // on cree la nouvelle matrice comme il faut (semantique non decore)
+ DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
+ this.matrix = MatrixFactory.getInstance().create(name, sems, dimNames, data);
+ // et on met les valeurs de l'ancienne dans la nouvelle
+ this.matrix.paste(matrix);
+
+ size += dataSize * 8; /* un double est sur 8 bytes*/
+ this.size = size;
+ }
+
+ /**
+ * retourne la taille en nombre de byte
+ * @return
+ */
+ public int size() {
+ return size;
+ }
+
+ public TimeStep getStep() {
+ return step;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public MatrixND getMatrix() {
+ return matrix;
+ }
+
+ public MatrixND getMatrix(TopiaContext tx) {
+ // on met la matrice dans un decorateur pour convertir automatiquement les semantiques
+ MatrixND result = new MatrixSemanticsDecorator(matrix, new EntitySemanticsDecorator(tx));
+ return result;
+ }
+
+ }
+
+ /**
+ * Les ResultStorage ne doivent pas etre instancier directement, mais
+ * recuperer a partir d'un
+ * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
+ *
+ * @param simulation storage to get result
+ */
+ public ResultMappedStorage(SimulationStorage simulation) throws IOException {
+ this.simulation = simulation;
+ File file = SimulationStorage.getResultFile(simulation.getDirectory());
+ raf = new RandomAccessFile(file, "rw");
+ // on lit les donnees deja presente
+ offset = 0;
+ while (offset < raf.length()) {
+ ResultMapped r = new ResultMapped(raf, offset);
+ storeResult(r);
+ offset += r.size();
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ raf.close();
+ }
+
+ /**
+ * Methode interne pour que les deux Map soit mise a jour en meme temps
+ * C'est la seul methode qui permet d'ajouter des noms de result dans les Map
+ * @param r
+ */
+ protected void storeResult(ResultMapped r) {
+ TimeStep step = r.getStep();
+ String name = r.getName();
+
+ getResult(step).put(name, r);
+ Map<TimeStep, ResultMapped> stepResult = nameStepResults.get(name);
+ if (stepResult == null) {
+ stepResult = new TreeMap<TimeStep, ResultMapped>();
+ nameStepResults.put(name, stepResult);
+ }
+ stepResult.put(step, r);
+ }
+
+ protected Map<String, ResultMapped> getResult(TimeStep step) {
+ Map<String, ResultMapped> result = stepNameResults.get(step);
+ if (result == null) {
+ result = new TreeMap<String, ResultMapped>();
+ stepNameResults.put(step, result);
+ }
+ return result;
+ }
+
+ protected ResultMapped getResult(TimeStep step, String name) {
+ ResultMapped result = getResult(step).get(name);
+ return result;
+ }
+
+ protected ResultMapped getResult(TimeStep step, String name, Population pop) {
+ name += " " + pop;
+ ResultMapped result = getResult(step, name);
+ return result;
+ }
+
+ protected Map<TimeStep, ResultMapped> getResult(String name, Population pop) {
+ name += " " + pop;
+ Map<TimeStep, ResultMapped> result = getResult(name);
+ return result;
+ }
+
+ protected Map<TimeStep, ResultMapped> getResult(String name) {
+ Map<TimeStep, ResultMapped> result = nameStepResults.get(name);
+ if (result == null) {
+ // on retourne une map vide, pour ne jamais retourne null
+ result = Collections.EMPTY_MAP;
+ }
+ return result;
+ }
+
+
+ public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), mat);
+ }
+
+ public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), pop, mat);
+ }
+
+ public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), mat);
+ }
+
+ public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), pop, mat);
+ }
+
+ public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, pop, mat);
+ }
+
+ public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, mat);
+ }
+
+ public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name + " " + pop, mat);
+ }
+ }
+
+ public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name, mat);
+ }
+ }
+
+ protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ // si la matrice n'a pas de semantique on refuse
+ for (int i = 0; i < mat.getDimCount(); i++) {
+ // la semantique n'est pas bonne des qu'il y a un null dedans
+ if (mat.getSemantic(i).contains(null)) {
+ throw new SimulationException(
+ "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
+ + i + " " + mat.getDimensionName(i));
+ }
+ }
+
+ try {
+ ResultMapped r = new ResultMapped(raf, offset, step, name, mat);
+ storeResult(r);
+ offset += r.size();
+ } catch (IOException eee) {
+ log.warn("Can't add result '" + name + "' at step " + step, eee);
+ }
+ }
+
+
+
+
+
+
+
+ /**
+ * Permet de savoir si lorsque l'on ajoutera ce resultat, il sera
+ * sauvé ou non.
+ *
+ * Check for result name returned by :
+ * <ul>
+ * <li>{@link Export#getNecessaryResult()}</li>
+ * <li>{@link SensitivityExport#getNecessaryResult()}</li>
+ * <li>{@link Rule#getNecessaryResult()}</li>
+ * <li>{@link SimulationPlan#getNecessaryResult()}</li>
+ * </ul>
+ *
+ * @param name result name
+ * @return {@code true} if result is enabled
+ */
+ public boolean isEnabled(String name) {
+ name = name.trim();
+ if (enabledResult == null) {
+ enabledResult = new HashSet<String>();
+
+ Collection<String> resultEnabled = simulation.getParameter()
+ .getResultEnabled();
+ enabledResult.addAll(resultEnabled);
+
+ // test on export
+ List<String> exportNames = simulation.getParameter().getExportNames();
+ if (exportNames != null) {
+ for (String exportName : exportNames) {
+ ExportStorage storage = ExportStorage.getExport(exportName);
+ try {
+ Export export = storage.getNewExportInstance();
+ for (String resultName : export.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ } catch (IsisFishException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("isisfish.error.instanciate.export",
+ exportName), eee);
+ }
+ }
+ }
+ }
+
+ // test on sensitivity export
+ List<SensitivityExport> sensitivityExports = simulation
+ .getParameter().getSensitivityExport();
+ if (sensitivityExports != null) {
+ for (SensitivityExport sensitivityExport : sensitivityExports) {
+ for (String resultName : sensitivityExport.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+
+ // test on rules
+ List<Rule> rules = simulation.getParameter().getRules();
+ if (rules != null) {
+ for (Rule rule : rules) {
+ for (String resultName : rule.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+
+ // test on plans
+ List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
+ if (plans != null) {
+ for (SimulationPlan plan : plans) {
+ for (String resultName : plan.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+ log.info("Enabled result: " + enabledResult);
+ }
+ boolean result = enabledResult.contains(name);
+ return result;
+ }
+
+
+ public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ ActiveRuleDAO ps = IsisFishDAOHelper.getActiveRuleDAO(tx);
+ ActiveRule result = ps.create();
+ result.setActiveRuleStep(step);
+ result.setName(RuleStorage.getName(rule));
+ result.setParam(RuleStorage.getParamAsString(rule));
+ ps.update(result);
+ if (mustClose) {
+ tx.commitTransaction();
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ throw new IsisFishException("Can't add result", eee);
+ }
+ }
+
+ /**
+ * Retourne la liste de tous les résultats. Si le résultat est categorisé
+ * par une population alors le nom de la population est automatiquement
+ * ajouté au nom du résultat.
+ */
+ public List<String> getResultName() {
+ List<String> result = new ArrayList<String>(nameStepResults.keySet());
+ return result;
+ }
+
+ /**
+ * Retourne la matrice stocke pour un pas de temps
+ * @param step le pas de temps que l'on souhaite
+ * @param pop la population pour lequelle on souhaite le resultat
+ * @param name le nom des resultats dont on veut la matrice
+ * @return La matrice demandée ou null si aucune matrice ne correspond a
+ * la demande.
+ */
+ public MatrixND getMatrix(TimeStep step, Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName, null);
+ }
+
+ public MatrixND getMatrix(TimeStep step, String name) {
+ return getMatrix(step, name, null);
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ *
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
+ ResultMapped r = getResult(step, name);
+ MatrixND mat = null;
+ if (r != null) {
+ mat = r.getMatrix(tx);
+ }
+ return mat;
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ * @param pop la population pour lequel on souhaite la matrice
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ public MatrixND getMatrix(Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, null);
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ *
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ public MatrixND getMatrix(String name) {
+ return getMatrix(name, null);
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ public MatrixND getMatrix(String name, TopiaContext tx) {
+ log.debug("Get result: " + name);
+
+ MatrixND resultMat = null;
+ Map<TimeStep, ResultMapped> results = getResult(name);
+ // recuperation des resultats qui nous interesse
+ if (!results.isEmpty()) {
+ // creation de la liste de date
+ TimeStep lastStep = getLastStep();
+ List<TimeStep> steps = new ArrayList<TimeStep>();
+ TimeStep step = new TimeStep(0);
+ steps.add(step);
+ while (step.before(lastStep)) {
+ step = step.next();
+ steps.add(step);
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("Steps list : " + steps);
+ }
+
+
+ MatrixND mat = results.values().iterator().next().getMatrix();
+
+ // recuperation des noms des dimensions
+ String[] dimNames = new String[1 + mat.getDimCount()];
+ dimNames[0] = _("isisfish.common.date");
+ for (int i = 1; i < dimNames.length; i++) {
+ dimNames[i] = mat.getDimensionName(i - 1);
+ }
+
+ // creation de la semantique pour la matrice resultat. +1 pour les dates
+ List[] sem = new List[1 + mat.getDimCount()];
+ sem[0] = steps;
+
+ for (int i = 1; i < sem.length; i++) {
+ sem[i] = new HashList();
+ }
+
+ for (ResultMapped result : results.values()) {
+ MatrixND mattmp = result.getMatrix();
+ if (log.isTraceEnabled()) {
+ log.trace("Ajout de la semantics: "
+ + Arrays.asList(mattmp.getSemantics()));
+ }
+
+ for (int s = 0; s < mattmp.getDimCount(); s++) {
+ sem[s + 1].addAll(mattmp.getSemantic(s));
+ }
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("La semantique final est: " + Arrays.asList(sem));
+ }
+
+ // creation de la matrice resultat
+ resultMat = matrixFactory.create(name, sem, dimNames);
+
+ // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
+ for (ResultMapped result : results.values()) {
+ TimeStep d = result.getStep();
+ mat = result.getMatrix();
+ // on met ce resultat dans la matrice result si besoin
+ if (mat != null) {
+ // on recupere dans la matrice resultat l'endroit on il faut
+ // mettre la matrice
+ MatrixND submat = resultMat.getSubMatrix(0, d, 1);
+ // on met les valeur de mat dans la sous matrice extraite
+ for (MatrixIterator mi = mat.iterator(); mi.next();) {
+ submat.setValue(
+ ArrayUtil.concat(new Object[] { d },
+ mi.getSemanticsCoordinates()), mi.getValue());
+ }
+ }
+ }
+ }
+ if (resultMat != null) {
+ // on decore la matrice resultat au dernier moment, tous les calcules
+ // ce font avec les strings
+ resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
+ }
+ return resultMat;
+ }
+
+ /**
+ * Get last simulation date.
+ *
+ * @return last simulation date
+ */
+ public TimeStep getLastStep() {
+ int monthNumber = simulation.getParameter().getNumberOfYear()
+ * Month.NUMBER_OF_MONTH;
+ TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(SimulationContext context, TimeStep step, String name,
+ MatrixND mat) throws IsisFishException {
+ doAddResult(step, name, mat);
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(step, name, context.getDB());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(String.format("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(name, context.getDB());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(String.format("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void afterSimulation(SimulationContext context) {
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void beforeSimulation(SimulationContext context) {
+ }
+
+ // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // rules.add(rule);
+ // }
+
+ // /**
+ // * Retourne pour une date données tous les RegleParam qui ont été activé
+ // * a la date demandé.
+ // * @return une list de {@link fr.ifremer.nodb.RegleParam}
+ // */
+ // public List getActivatedRule(ResultStorage self, Date date){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // return rules;
+ // }
+
+}
\ No newline at end of file
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-08-30 14:46:24 UTC (rev 3749)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-08-31 13:09:22 UTC (rev 3750)
@@ -74,6 +74,7 @@
public static final String CONTROL_FILENAME = "control";
public static final String PARAMETERS_FILENAME = "parameters.properties";
public static final String RESULT_XML_FILENAME = "isis-mexico-output.xml";
+ public static final String RESULT_FILENAME = "results.mapped";
public static final String RESULT_EXPORT_DIRECTORY = "resultExports";
public static final String DESIGN_PLAN_FILENAME = "isis-mexico-designplan.xml";
public static final String SENSITIVITY_RESULTS = "sensitivityresults";
@@ -183,7 +184,7 @@
/**
* Retourne le fichier de stockage des inforations de la simulation.
- *
+ *
* @param root le repertoire de stockage de la simulation
* @return information file
*/
@@ -195,7 +196,7 @@
/**
* Retourne le fichier de stockage des resultats sous format XML mexico
* de la simulation.
- *
+ *
* @param root le repertoire de stockage de la simulation
* @return mexico xml file
*/
@@ -205,6 +206,18 @@
}
/**
+ * Retourne le fichier de stockage des resultats
+ * de la simulation.
+ *
+ * @param root le repertoire de stockage de la simulation
+ * @return
+ */
+ public static File getResultFile(File root) {
+ File result = new File(root, RESULT_FILENAME);
+ return result;
+ }
+
+ /**
* Retourne le fichier de stockage des parametres de la simulation courante.
*
* @return parameter file
@@ -437,6 +450,8 @@
*/
public ResultStorage getResultStorage() {
if (resultStorage == null) {
+ // FIXME poussin 20120831 en fonction de la version de la base
+ // instancier un ResultStorage ou un ResultMappedStorage
resultStorage = new ResultStorage(this);
}
return resultStorage;
1
0
Author: tchemit
Date: 2012-08-30 16:46:24 +0200 (Thu, 30 Aug 2012)
New Revision: 3749
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3749
Log:
Update mavenpom4redmine to 3.3.7.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-30 14:07:12 UTC (rev 3748)
+++ trunk/pom.xml 2012-08-30 14:46:24 UTC (rev 3749)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.3.6</version>
+ <version>3.3.7</version>
</parent>
<groupId>fr.ifremer</groupId>
1
0
r3748 - in trunk/src: main/java/fr/ifremer/isisfish main/java/fr/ifremer/isisfish/simulator/launcher main/java/fr/ifremer/isisfish/ui main/java/fr/ifremer/isisfish/ui/config main/resources/i18n main/resources/templates/ssh test/java/fr/ifremer/isisfish/simulator/launcher
by echatellier@users.forge.codelutin.com 30 Aug '12
by echatellier@users.forge.codelutin.com 30 Aug '12
30 Aug '12
Author: echatellier
Date: 2012-08-30 16:07:12 +0200 (Thu, 30 Aug 2012)
New Revision: 3748
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3748
Log:
fixes #1442: Add option to control subprocess allocated memory
fixes #1443: Add option to control caparmor process allocated memory
fixes #1445: Add option to control subprocess max simultaneous process count
Modified:
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigAction.java
trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
trunk/src/main/resources/templates/ssh/qsub-script.ftl
trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -386,6 +386,36 @@
}
/**
+ * Retourne le nombre maximum de thread à utiliser en in process.
+ *
+ * @return number of thread to use
+ */
+ public int getSimulatorInMaxThreads() {
+ int result = getOptionAsInt(Option.SIMULATOR_IN_MAXTHREADS.key);
+ return result;
+ }
+
+ /**
+ * Retourne le nombre de sous processus maximum a creer.
+ *
+ * @return number of sub process to create
+ */
+ public int getSimulatorSubMaxProcess() {
+ int result = getOptionAsInt(Option.SIMULATOR_SUB_MAXPROCESS.key);
+ return result;
+ }
+
+ /**
+ * Retourne la quantité de ram (Xmx) a alloue au sous processus.
+ *
+ * @return memory amount to use for sub process
+ */
+ public String getSimulatorSubMaxMemory() {
+ String result = getOption(Option.SIMULATOR_SUB_MAXMEMORY.key);
+ return result;
+ }
+
+ /**
* Retourne l'url du serveur de simulation accessible via SSH.
*
* @return simulator server
@@ -601,6 +631,25 @@
}
/**
+ * Retourne la quantité de ram (Xmx) a alloue au processus sur caparmor.
+ *
+ * @return number of thread to use
+ */
+ public String getSimulatorSshMaxMemory() {
+ String result = getOption(Option.SIMULATOR_SSH_MAXMEMORY.key);
+ return result;
+ }
+
+ /**
+ * Set ssh simulation process memory to use
+ *
+ * @param memory memory
+ */
+ public void setSimulatorSshMaxMemory(String memory) {
+ setOption(Option.SIMULATOR_SSH_MAXMEMORY.key, memory);
+ }
+
+ /**
* Retourne la clé privée de l'utilisteur courant.
*
* @return private ssh key path
@@ -911,6 +960,14 @@
SIMULATOR_LAUNCHER2(SimulationService.SIMULATION_LAUNCHER + ".1", n_("isisfish.config.main.subSimulator.description"), SubProcessSimulationLauncher.class.getName()),
SIMULATOR_LAUNCHER_REMOTE(SimulationService.SIMULATION_LAUNCHER + ".2", n_("isisfish.config.main.remoteCaparmor.description"), SSHSimulatorLauncher.class.getName()),
+ /** Nombre maximum de thread de simulation in process. */
+ SIMULATOR_IN_MAXTHREADS("simulation.in.max.threads", n_("isisfish.config.main.simulation.in.max.threads.description"), "1"),
+
+ /** Nombre max de sous processus à lancer (-1 = pas de limite). */
+ SIMULATOR_SUB_MAXPROCESS("simulation.sub.max.process", n_("isisfish.config.main.simulation.sub.max.process.description"), "-1"),
+ /** Mémoire max (Xmx) allouée aux sous processus. */
+ SIMULATOR_SUB_MAXMEMORY("simulation.sub.max.memory", n_("isisfish.config.main.simulation.sub.max.memory.description"), "1024M"),
+
/** Serveur accessible par ssh : address */
SIMULATOR_SSH_SERVER("simulation.ssh.server", n_("isisfish.config.main.simulation.ssh.server.description"), "caparmor-sftp"),
/** Serveur accessible par ssh : login */
@@ -933,6 +990,8 @@
SIMULATOR_SSH_CONTROLCHECKINTERVAL("simulation.ssh.control.check.interval", n_("isisfish.config.main.simulation.ssh.control.check.interval.description"), "120"),
/** Serveur accessible par SSH : nombre de thread au maximum a utilise simultanement */
SIMULATOR_SSH_MAXTHREADS("simulation.ssh.max.threads", n_("isisfish.config.main.simulation.ssh.max.threads.description"), "1"),
+ /** Serveur accessible par SSH : mémoire (Xmx) allouée pour les process java sur caparmor */
+ SIMULATOR_SSH_MAXMEMORY("simulation.ssh.max.memory", n_("isisfish.config.main.simulation.ssh.max.memory.description"), "2000M"),
/** Application locale (for i18n init). */
LOCALE("locale", n_("isisfish.config.main.locale.description"), "fr_FR"),
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -171,7 +171,7 @@
* @see fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher#maxSimulationThread()
*/
public int maxSimulationThread() {
- return 1;
+ return IsisFish.config.getSimulatorInMaxThreads();
}
/*
@@ -181,7 +181,6 @@
public int getCheckProgressionInterval() {
// par defaut, pour les in process 5 secondes
-
int interval = 1;
return interval;
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -176,7 +176,7 @@
@Override
public int maxSimulationThread() {
- // met le serveur les lance quand il veut
+ // mais le serveur les lance quand il veut
int maxSimulationThread = IsisFish.config.getSimulatorSshMaxThreads();
if (maxSimulationThread <= 0) {
@@ -1104,6 +1104,7 @@
root.put("isishome", IsisFish.config.getSimulatorSshIsisHome());
root.put("isistemp", getRemoteTempDirectory());
root.put("javapath", IsisFish.config.getSimulatorSshJavaPath());
+ root.put("javamemory", IsisFish.config.getSimulatorSshMaxMemory());
root.put("simulationid", simuationId);
root.put("simulationzip", simulationZip);
root.put("simulationstandalonezip", standaloneZip);
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -43,6 +43,8 @@
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.FileUtil;
+import com.sun.tools.internal.jxc.gen.config.Config;
+
import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.SimulationControl;
@@ -110,8 +112,15 @@
@Override
public int maxSimulationThread() {
- // TODO rendre configurable le nombre de processeurs a utiliser
- int result = Runtime.getRuntime().availableProcessors();
+
+ int result = IsisFish.config.getSimulatorSubMaxProcess();
+
+ // s'il n'y a pas de configuration utilisateur particulière
+ // on utilise le nombre de processeur physique
+ if (result <= 0) {
+ result = Runtime.getRuntime().availableProcessors();
+ }
+
return result;
}
@@ -189,7 +198,7 @@
// common args
List<String> command = new ArrayList<String>();
command.add(java);
- command.add("-Xmx2048M");
+ command.add("-Xmx" + IsisFish.config.getSimulatorSubMaxMemory());
// jri args
String libraryPath = System.getProperty("java.library.path");
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -222,6 +222,12 @@
modelBuilder.addOption(IsisConfig.Option.SIMULATION_SHOW_ONLY_ERROR);
modelBuilder.addOption(IsisConfig.Option.SIMULATION_SCRIPT_AUTOCONFIG);
+ // category simulation
+ modelBuilder.addCategory(_("isisfish.config.category.simulation"), _("isisfish.config.category.simulation.description"));
+ modelBuilder.addOption(IsisConfig.Option.SIMULATOR_IN_MAXTHREADS);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATOR_SUB_MAXPROCESS);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATOR_SUB_MAXMEMORY);
+
// category database vcs
modelBuilder.addCategory(_("isisfish.config.category.officialvcs"), _("isisfish.config.category.officialvcs.description"));
modelBuilder.addOption(IsisConfig.Option.VCS_TYPE);
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigAction.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigAction.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigAction.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Chatellier Eric
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -79,6 +79,7 @@
protected String currentSSHPbsBinPath;
protected String currentSSHPbsQsubOptions;
protected String currentSSHMaxThreads;
+ protected String currentSSHMaxMemory;
protected String currentSSHControlInterval;
/**
@@ -109,6 +110,7 @@
configUI.getSshPbsQsubOptionsField().setText(IsisFish.config.getSimulatorSshPbsQsubOptions());
configUI.getSshControlIntervalField().setText(String.valueOf(IsisFish.config.getSimulatorSshControlCheckInterval()));
configUI.getSshMaxThreadsField().setText(String.valueOf(IsisFish.config.getSimulatorSshMaxThreads()));
+ configUI.getSshMaxMemoryField().setText(IsisFish.config.getSimulatorSshMaxMemory());
doCheck();
}
@@ -207,6 +209,9 @@
} else {
setColor(false, configUI.getSshMaxThreadsField());
}
+
+ // currentSSHMaxMemory
+ currentSSHMaxMemory = configUI.getSshMaxMemoryField().getText().trim();
// currentSSHControlInterval
currentSSHControlInterval = configUI.getSshControlIntervalField()
@@ -236,6 +241,7 @@
IsisFish.config.setSimulatorSshPbsQsubOptions(currentSSHPbsQsubOptions);
IsisFish.config.setSimulatorSshControlCheckInterval(Integer.parseInt(currentSSHControlInterval));
IsisFish.config.setSimulatorSshMaxThreads(Integer.parseInt(currentSSHMaxThreads));
+ IsisFish.config.setSimulatorSshMaxMemory(currentSSHMaxMemory);
IsisFish.config.saveForUser();
configUI.dispose();
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx 2012-08-30 14:07:12 UTC (rev 3748)
@@ -5,7 +5,7 @@
$Id$
$HeadURL$
%%
- Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric
+ Copyright (C) 2009 - 2012 Ifremer, CodeLutin, Chatellier Eric
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -157,6 +157,17 @@
</row>
<row fill='horizontal'>
<cell>
+ <JLabel id='sshMaxMemoryLabel' text='isisfish.config.main.simulation.ssh.max.memory'
+ toolTipText='isisfish.config.main.simulation.ssh.max.memory.description' />
+ </cell>
+ <cell>
+ <JTextField id='sshMaxMemoryField'
+ toolTipText='isisfish.config.main.simulation.ssh.max.memory.description'
+ onKeyReleased="getAction().doCheck()" />
+ </cell>
+ </row>
+ <row fill='horizontal'>
+ <cell>
<JLabel id='sshControlIntervalLabel' text='isisfish.config.main.simulation.ssh.control.check.interval'
toolTipText='isisfish.config.main.simulation.ssh.control.check.interval.description' />
</cell>
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-30 14:07:12 UTC (rev 3748)
@@ -145,6 +145,8 @@
isisfish.config.category.misc.description=Miscealenous
isisfish.config.category.officialvcs=Official VCS
isisfish.config.category.officialvcs.description=Official VCS repository
+isisfish.config.category.simulation=Simulations
+isisfish.config.category.simulation.description=Simulation execution configuration
isisfish.config.database.lockmode.description=Database lock mode
isisfish.config.main.compileDirectory.description=Script compilation directory
isisfish.config.main.configFileName.description=Configuration filename
@@ -166,6 +168,7 @@
isisfish.config.main.performvcsupdate.description=Perform vcs update
isisfish.config.main.remoteCaparmor.description=Remote simulator launcher name
isisfish.config.main.script.autoconfig.description=Display a dialog to force script configuration
+isisfish.config.main.simulation.in.max.threads.description=Max threads count in current process
isisfish.config.main.simulation.ssh.control.check.interval=Control check interval (seconds)
isisfish.config.main.simulation.ssh.control.check.interval.description=Control check interval (seconds)
isisfish.config.main.simulation.ssh.datapath=ISIS-Fish database
@@ -174,6 +177,8 @@
isisfish.config.main.simulation.ssh.isis.home.description=ISIS-Fish installation directory
isisfish.config.main.simulation.ssh.javapath=Java path
isisfish.config.main.simulation.ssh.javapath.description=Java location on remote server (full path or relative to $PATH, by default value is caparmor configuration)
+isisfish.config.main.simulation.ssh.max.memory=Ssh simulation Xmx allocated memory
+isisfish.config.main.simulation.ssh.max.memory.description=Ssh simulation Xmx allocated memory
isisfish.config.main.simulation.ssh.max.threads=SSH threads count
isisfish.config.main.simulation.ssh.max.threads.description=Number of simultaneous simulations to do through SSH. Might only be usefull for dependent analysis plans. Otherwise keep value at '1'.
isisfish.config.main.simulation.ssh.pbsbinpath=PBS executables directory
@@ -188,6 +193,8 @@
isisfish.config.main.simulation.ssh.userhome.description=User home directory
isisfish.config.main.simulation.ssh.username=SSH identifier
isisfish.config.main.simulation.ssh.username.description=SSH identifier
+isisfish.config.main.simulation.sub.max.memory.description=Sub process simulation Xmx allocated memory
+isisfish.config.main.simulation.sub.max.process.description=Max sub process count (using -1 value will use available processor count)
isisfish.config.main.simulationShowOnlyError.description=
isisfish.config.main.smtpServer.description=Smtp server address
isisfish.config.main.subSimulator.description=Sub process simulator launcher name
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-30 14:07:12 UTC (rev 3748)
@@ -145,6 +145,8 @@
isisfish.config.category.misc.description=Divers
isisfish.config.category.officialvcs=VCS Officiel
isisfish.config.category.officialvcs.description=Dépôt contenant les scripts officiels
+isisfish.config.category.simulation=Simulations
+isisfish.config.category.simulation.description=Configuration des simulations
isisfish.config.database.lockmode.description=Méthode de vérouillage à utiliser pour la base de données
isisfish.config.main.compileDirectory.description=le répertoire où sont compilés les scripts
isisfish.config.main.configFileName.description=le fichier de configuration à utiliser
@@ -166,6 +168,7 @@
isisfish.config.main.performvcsupdate.description=Met à jour le dépôt VCS
isisfish.config.main.remoteCaparmor.description=Nom du lanceur de simulation distante
isisfish.config.main.script.autoconfig.description=Affiche une fenêtre pour forcer la configuration des scripts
+isisfish.config.main.simulation.in.max.threads.description=Nombre de thread maximum dans le processus courant
isisfish.config.main.simulation.ssh.control.check.interval=Vérification de la progression (secondes)
isisfish.config.main.simulation.ssh.control.check.interval.description=Temps d'attente en secondes entre deux vérifications de progression
isisfish.config.main.simulation.ssh.datapath=Base de données
@@ -174,6 +177,8 @@
isisfish.config.main.simulation.ssh.isis.home.description=Emplacement d'installation d'ISIS-Fish sur le serveur
isisfish.config.main.simulation.ssh.javapath=Emplacement de java
isisfish.config.main.simulation.ssh.javapath.description=Emplacement de java sur le serveur (chemin total, ou relatif au $PATH, par défaut la valeur est celle de caparmor)
+isisfish.config.main.simulation.ssh.max.memory=Quantité de mémoire allouée
+isisfish.config.main.simulation.ssh.max.memory.description=Quantité de mémoire maximum allouée (Xmx)
isisfish.config.main.simulation.ssh.max.threads=Nombre de thread SSH
isisfish.config.main.simulation.ssh.max.threads.description=Nombre de simulation simultanée à faire en SSH. Attention, ne doit être utilisé que pour faire plusieurs plans de simulation dépendants en même temps, sinon laisser '1'.
isisfish.config.main.simulation.ssh.pbsbinpath=Emplacement des executables PBS
@@ -188,6 +193,8 @@
isisfish.config.main.simulation.ssh.userhome.description=Répertoire d'accueil de l'utilisateur
isisfish.config.main.simulation.ssh.username=Identifiant
isisfish.config.main.simulation.ssh.username.description=Identifiant SSH pour se connecter au serveur
+isisfish.config.main.simulation.sub.max.memory.description=Quantité de mémoire maximum allouée au sous processus
+isisfish.config.main.simulation.sub.max.process.description=Nombre maximum de sous processus (une valeur de -1 utilisera le nombre de processeur disponible)
isisfish.config.main.simulationShowOnlyError.description=pour indiquer si l'on doit conserver dans l'UI des simulations terminées uniquement celles avec erreur
isisfish.config.main.smtpServer.description=le nom du serveur smtp à utiliser pour envoyer les courriels
isisfish.config.main.subSimulator.description=Nom du simulateur en sous processus
Modified: trunk/src/main/resources/templates/ssh/qsub-script.ftl
===================================================================
--- trunk/src/main/resources/templates/ssh/qsub-script.ftl 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/main/resources/templates/ssh/qsub-script.ftl 2012-08-30 14:07:12 UTC (rev 3748)
@@ -29,7 +29,7 @@
setenv R_HOME /appli/R/2.15.0-gnu-4.3/lib64/R
setenv LD_LIBRARY_PATH ${r"${R_HOME}"}/lib
-<#assign commonCommand="${javapath} -Djava.library.path=jri64 -DR.type=jni -Xmx2000M -jar isis-fish*.jar" />
+<#assign commonCommand="${javapath} -Djava.library.path=jri64 -DR.type=jni -Xmx${javamemory} -jar isis-fish*.jar" />
<#assign commonOptions="--option launch.ui false --option perform.vcsupdate false --option perform.migration false --option perform.cron false" />
<#if qsubmutiplejob>
<#-- localsimulationid is short simulation id version -->
Modified: trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java
===================================================================
--- trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2012-08-30 13:50:52 UTC (rev 3747)
+++ trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2012-08-30 14:07:12 UTC (rev 3748)
@@ -329,4 +329,20 @@
Assert.assertTrue(content.contains("${R_HOME}/lib"));
}
+
+ /**
+ * Test que memoire définie dans la configuration est bien présente.
+ *
+ * @throws IOException
+ * @throws TemplateException
+ */
+ @Test
+ public void testFreemarkerTemplateMemory() throws IOException, TemplateException {
+ SSHSimulatorLauncher launcher = new SSHSimulatorLauncher();
+ String content = launcher.getSimulationScriptLaunchContent(
+ SSHSimulatorLauncher.QSUB_SCRIPT_TEMPLATE, "",
+ "", true, "", "", true);
+
+ Assert.assertTrue(content.contains("Xmx2000M"));
+ }
}
\ No newline at end of file
1
0
r3747 - trunk/src/main/java/fr/ifremer/isisfish/util
by echatellier@users.forge.codelutin.com 30 Aug '12
by echatellier@users.forge.codelutin.com 30 Aug '12
30 Aug '12
Author: echatellier
Date: 2012-08-30 15:50:52 +0200 (Thu, 30 Aug 2012)
New Revision: 3747
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3747
Log:
Wrong import
Modified:
trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java 2012-08-30 13:45:31 UTC (rev 3746)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java 2012-08-30 13:50:52 UTC (rev 3747)
@@ -35,7 +35,6 @@
import fr.ifremer.isisfish.entities.PopulationDAO;
import fr.ifremer.isisfish.entities.PopulationGroup;
import fr.ifremer.isisfish.entities.PopulationGroupDAO;
-import fr.ifremer.isisfish.entities.Result;
import fr.ifremer.isisfish.simulator.SimulationContext;
/**
1
0
r3746 - in trunk/src: main/java/fr/ifremer/isisfish/util test/java/fr/ifremer/isisfish/util
by echatellier@users.forge.codelutin.com 30 Aug '12
by echatellier@users.forge.codelutin.com 30 Aug '12
30 Aug '12
Author: echatellier
Date: 2012-08-30 15:45:31 +0200 (Thu, 30 Aug 2012)
New Revision: 3746
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3746
Log:
fixes #1444: Fix matrix import semantic mapper for PopulationGroup
Modified:
trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java
trunk/src/test/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapperTest.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java 2012-08-30 12:45:25 UTC (rev 3745)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapper.java 2012-08-30 13:45:31 UTC (rev 3746)
@@ -31,6 +31,11 @@
import org.nuiton.topia.persistence.TopiaEntity;
import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationDAO;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.PopulationGroupDAO;
+import fr.ifremer.isisfish.entities.Result;
import fr.ifremer.isisfish.simulator.SimulationContext;
/**
@@ -90,7 +95,30 @@
// In simulation context :
Object value = null;
try {
- if (TopiaEntity.class.isAssignableFrom(type)) {
+ // les populations groupes sont speciaux car ils n'ont pas de
+ // noms. Dans l'import il sont composé du nom de la population
+ // et du numero de groupe séparé par +.
+ if (PopulationGroup.class.isAssignableFrom(type)) {
+ int separatorIndex = valueId.indexOf('+');
+ if (separatorIndex >= 0) {
+ String popName = valueId.substring(0, separatorIndex);
+ int groupId = Integer.parseInt(valueId.substring(separatorIndex + 1));
+
+ TopiaContext context = SimulationContext.get().getDB();
+ PopulationDAO populationDao = IsisFishDAOHelper.getPopulationDAO(context);
+ PopulationGroupDAO populationGroupDAO = IsisFishDAOHelper.getPopulationGroupDAO(context);
+ Population population = populationDao.findByName(popName);
+ value = populationGroupDAO.findByProperties(
+ PopulationGroup.PROPERTY_POPULATION, population,
+ PopulationGroup.PROPERTY_ID, groupId);
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn("PopulationGroup identifiant doesn't contains '+' separator");
+ }
+ value = valueId;
+ }
+ }
+ else if (TopiaEntity.class.isAssignableFrom(type)) {
TopiaContext context = SimulationContext.get().getDB();
TopiaDAO dao = IsisFishDAOHelper.getDAO(context, type);
value = dao.findByProperty("name", valueId);
Modified: trunk/src/test/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapperTest.java
===================================================================
--- trunk/src/test/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapperTest.java 2012-08-30 12:45:25 UTC (rev 3745)
+++ trunk/src/test/java/fr/ifremer/isisfish/util/IsisMatrixSemanticMapperTest.java 2012-08-30 13:45:31 UTC (rev 3746)
@@ -45,6 +45,7 @@
import fr.ifremer.isisfish.AbstractIsisFishTest;
import fr.ifremer.isisfish.IsisFishDAOHelper;
import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.entities.Population;
import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.types.TimeStep;
@@ -149,4 +150,31 @@
Assert.assertEquals(2.0, m.getValue(0, 0, 0), 0.001);
Assert.assertEquals(1.0, m.getValue(0, 0, 1), 0.001);
}
+
+ /**
+ * Test la conversion des entités.
+ * @throws IOException
+ * @throws TopiaException
+ */
+ @Test
+ public void testImportPopulationGroup() throws IOException, TopiaException {
+ String data = "[1, 3, 1]\n" +
+ "Population:test population\n" +
+ "PopulationGroup:test population+2,test population+1,test population+0\n" +
+ "Zone:Zone test1\n" +
+ "0;2;0;42.0";
+
+ TopiaContext tx = SimulationContext.get().getDB();
+
+ Population pop = IsisFishDAOHelper.getPopulationDAO(tx).findByName("test population");
+ List[] sems = new List[] {
+ Collections.singletonList(pop),
+ Arrays.asList(pop.getPopulationGroup().get(0), pop.getPopulationGroup().get(1), pop.getPopulationGroup().get(2)),
+ Collections.singletonList(IsisFishDAOHelper.getZoneDAO(tx).findByName("Zone test1")),
+ };
+ MatrixND m = MatrixFactory.getInstance().create(sems);
+ m.importCSV(new StringReader(data), null);
+
+ Assert.assertEquals(42.0, m.getValue(0, 0, 0), 0.001);
+ }
}
1
0
r3745 - in trunk/src/main: java/fr/ifremer/isisfish java/fr/ifremer/isisfish/datastore java/fr/ifremer/isisfish/simulator java/fr/ifremer/isisfish/simulator/launcher resources/i18n
by echatellier@users.forge.codelutin.com 30 Aug '12
by echatellier@users.forge.codelutin.com 30 Aug '12
30 Aug '12
Author: echatellier
Date: 2012-08-30 14:45:25 +0200 (Thu, 30 Aug 2012)
New Revision: 3745
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3745
Log:
fixes #1435 : Memory leak is still present when reading result during export
Modified:
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationExportResultWrapper.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2012-08-30 12:45:25 UTC (rev 3745)
@@ -119,7 +119,7 @@
* migration de donnees demande automatiquement un changement de version
* d'application.
*/
- protected final static Version version = new Version(4, 1, 1, 0);
+ protected final static Version version = new Version(4, 1, 1, 1);
protected final static Version majorVersion = new Version(version.getNumber(0));
protected final static Version databaseVersion = new Version(
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-30 12:45:25 UTC (rev 3745)
@@ -37,11 +37,13 @@
import org.apache.commons.collections.map.ReferenceMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
import org.nuiton.math.matrix.MatrixFactory;
import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImpl;
import org.nuiton.util.ArrayUtil;
import org.nuiton.util.HashList;
@@ -357,6 +359,9 @@
}
// on fait une copie pour avoir reellement des resultats independant
+ // FIXME echatellier 20120829 : faire une copie optimiser
+ // suivant l'implementation du vector plutot qu'un parcourt
+ // via un iterateur de semantiques (plus couteux)
MatrixND newMat = mat.copy();
try {
ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
@@ -489,6 +494,11 @@
// donc mettre la matrice et la connexion dans une map
// la matrice dans une weak reference. Des que la matrice
// est liberer faire un close sur la transaction
+ } else {
+ // echatellier 20120829 : vidage du cache hibernate
+ // sinon on fait trop de lecture que la meme transaction
+ // et le cache hibernate se remplit sans se vider
+ tx.clearCache();
}
} catch (Exception eee) {
if (log.isWarnEnabled()) {
@@ -579,6 +589,11 @@
// donc mettre la matrice et la connexion dans une map
// la matrice dans une weak reference. Des que la matrice
// est liberer faire un close sur la transaction
+ } else {
+ // echatellier 20120829 : vidage du cache hibernate
+ // sinon on fait trop de lecture que la meme transaction
+ // et le cache hibernate se remplit sans se vider
+ tx.clearCache();
}
} catch (TopiaException eee) {
if (log.isWarnEnabled()) {
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationExportResultWrapper.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationExportResultWrapper.java 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationExportResultWrapper.java 2012-08-30 12:45:25 UTC (rev 3745)
@@ -25,6 +25,7 @@
package fr.ifremer.isisfish.simulator;
+import static org.nuiton.i18n.I18n._;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -66,9 +67,10 @@
SimulationStorage simulation = context.getSimulationStorage();
SimulationParameter parameters = simulation.getParameter();
File rootDirectory = simulation.getDirectory();
+ SimulationControl control = context.getSimulationControl();
// Ici on contantene les 2 listes d'exports
-
+
// first, make export instances based on export
// names
List<Export> allExports = new ArrayList<Export>();
@@ -95,6 +97,7 @@
// make exports
if (!allExports.isEmpty()) {
+ control.setText(_("isisfish.message.export.export"));
File exportDir = SimulationStorage
.getResultExportDirectory(rootDirectory);
exportDir.mkdirs();
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2012-08-30 12:45:25 UTC (rev 3745)
@@ -48,7 +48,6 @@
import org.nuiton.util.FileUtil;
import org.nuiton.util.ObjectUtil;
import org.nuiton.util.StringUtil;
-import org.nuiton.util.ZipUtil;
import fr.ifremer.isisfish.IsisConfig;
import fr.ifremer.isisfish.IsisFish;
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SubProcessSimulationLauncher.java 2012-08-30 12:45:25 UTC (rev 3745)
@@ -189,7 +189,7 @@
// common args
List<String> command = new ArrayList<String>();
command.add(java);
- command.add("-Xmx1024M");
+ command.add("-Xmx2048M");
// jri args
String libraryPath = System.getProperty("java.library.path");
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-30 12:45:25 UTC (rev 3745)
@@ -544,6 +544,7 @@
isisfish.message.directory.not.exists=
isisfish.message.evaluation.finished=evaluation finished
isisfish.message.export.done=export done
+isisfish.message.export.export=Exporting results
isisfish.message.file.already.exists=File %s already exists, do you want overwrite it ?
isisfish.message.file.overwrite=File exists, do you want overwrite it ?
isisfish.message.import=Import %1$s
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-27 19:41:06 UTC (rev 3744)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-30 12:45:25 UTC (rev 3745)
@@ -544,6 +544,7 @@
isisfish.message.directory.not.exists=
isisfish.message.evaluation.finished=évaluation terminée
isisfish.message.export.done=Export terminé
+isisfish.message.export.export=Export des résultats
isisfish.message.file.already.exists=Le fichier %s existe, voulez-vous l'écraser ?
isisfish.message.file.overwrite=Le fichier existe, voulez-vous l'écraser ?
isisfish.message.import=Importer %1$s
1
0