Isis-fish-commits
Threads by month
- ----- 2026 -----
- August
- July
- 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 Aug. 31, 2012
by bpoussin@users.forge.codelutin.com Aug. 31, 2012
Aug. 31, 2012
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 Aug. 31, 2012
by bpoussin@users.forge.codelutin.com Aug. 31, 2012
Aug. 31, 2012
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 Aug. 31, 2012
by echatellier@users.forge.codelutin.com Aug. 31, 2012
Aug. 31, 2012
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 Aug. 31, 2012
by echatellier@users.forge.codelutin.com Aug. 31, 2012
Aug. 31, 2012
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 Aug. 31, 2012
by bpoussin@users.forge.codelutin.com Aug. 31, 2012
Aug. 31, 2012
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 Aug. 30, 2012
by echatellier@users.forge.codelutin.com Aug. 30, 2012
Aug. 30, 2012
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 Aug. 30, 2012
by echatellier@users.forge.codelutin.com Aug. 30, 2012
Aug. 30, 2012
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 Aug. 30, 2012
by echatellier@users.forge.codelutin.com Aug. 30, 2012
Aug. 30, 2012
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 Aug. 30, 2012
by echatellier@users.forge.codelutin.com Aug. 30, 2012
Aug. 30, 2012
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
Author: maven-release
Date: 2012-08-27 21:41:06 +0200 (Mon, 27 Aug 2012)
New Revision: 3744
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3744
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-27 19:40:59 UTC (rev 3743)
+++ trunk/pom.xml 2012-08-27 19:41:06 UTC (rev 3744)
@@ -11,7 +11,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.1.1.0</version>
+ <version>4.1.1.1-SNAPSHOT</version>
<!-- POM Relationships : Inheritance : Dependencies -->
<dependencies>
@@ -730,9 +730,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.0</connection>
- <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.0</developerConnection>
- <url>http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.0</url>
+ <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</connection>
+ <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</developerConnection>
+ <url>http://svn.forge.codelutin.com/svn/isis-fish/trunk</url>
</scm>
<repositories>
1
0
Aug. 27, 2012
Author: maven-release
Date: 2012-08-27 21:40:59 +0200 (Mon, 27 Aug 2012)
New Revision: 3743
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3743
Log:
[maven-release-plugin] copy for tag isis-fish-4.1.1.0
Added:
tags/isis-fish-4.1.1.0/
Property changes on: tags/isis-fish-4.1.1.0
___________________________________________________________________
Added: svn:ignore
+ maven.log
target
velocity.log
.classpath
.project
isis-fish.ipr
isis-fish.iws
isis-fish.iml
.settings
bin
nbproject
Inputs_Langoustine
Added: svn:mergeinfo
+ /branches/4.1:3601-3670
1
0
Author: maven-release
Date: 2012-08-27 21:40:51 +0200 (Mon, 27 Aug 2012)
New Revision: 3742
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3742
Log:
[maven-release-plugin] prepare release isis-fish-4.1.1.0
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-27 19:35:53 UTC (rev 3741)
+++ trunk/pom.xml 2012-08-27 19:40:51 UTC (rev 3742)
@@ -11,7 +11,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.1.1.0-SNAPSHOT</version>
+ <version>4.1.1.0</version>
<!-- POM Relationships : Inheritance : Dependencies -->
<dependencies>
@@ -730,9 +730,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</connection>
- <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</developerConnection>
- <url>http://svn.forge.codelutin.com/svn/isis-fish/trunk</url>
+ <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.0</connection>
+ <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.0</developerConnection>
+ <url>http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.0</url>
</scm>
<repositories>
1
0
r3741 - trunk/src/main/java/fr/ifremer/isisfish/util
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 21:35:53 +0200 (Mon, 27 Aug 2012)
New Revision: 3741
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3741
Log:
Retrait du cache des converters (ya un truc qui ne fonctionne pas)
Modified:
trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java 2012-08-27 18:37:56 UTC (rev 3740)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java 2012-08-27 19:35:53 UTC (rev 3741)
@@ -52,7 +52,7 @@
*/
public class ConverterUtil {
- static protected Map<TopiaContext, ConvertUtilsBean> cache = new WeakHashMap<TopiaContext, ConvertUtilsBean>();
+ //static protected Map<TopiaContext, ConvertUtilsBean> cache = new WeakHashMap<TopiaContext, ConvertUtilsBean>();
static protected ConvertUtilsBean nullConverter = getConverterNoCache(null);
public static ConvertUtilsBean getConverter(TopiaContext context) {
@@ -60,10 +60,10 @@
if (context == null) {
result = nullConverter;
} else {
- result = cache.get(context);
- if (result == null) {
+ /*result = cache.get(context);
+ if (result == null) {*/
result = getConverterNoCache(context);
- }
+ //}
}
return result;
}
@@ -71,7 +71,7 @@
protected static ConvertUtilsBean getConverterNoCache(TopiaContext context) {
BeanUtilsBean bub = BeanUtilsBean.getInstance();
ConvertUtilsBean result = bub.getConvertUtils();
- cache.put(context, result);
+ //cache.put(context, result);
// mise en place de converter de string vers des objet ...
result.register(new TopiaEntityConverter(context), TopiaEntity.class);
1
0
Author: echatellier
Date: 2012-08-27 20:37:56 +0200 (Mon, 27 Aug 2012)
New Revision: 3740
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3740
Log:
Update to nuiton-matrix 2.3.1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-27 17:56:21 UTC (rev 3739)
+++ trunk/pom.xml 2012-08-27 18:37:56 UTC (rev 3740)
@@ -62,14 +62,14 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix-gui</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
<scope>compile</scope>
</dependency>
1
0
r3739 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 19:56:21 +0200 (Mon, 27 Aug 2012)
New Revision: 3739
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3739
Log:
Auto commit des resultats directement (au lieu d'en fin de pas de temps)
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-27 17:55:39 UTC (rev 3738)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-27 17:56:21 UTC (rev 3739)
@@ -369,6 +369,14 @@
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
1
0
r3738 - trunk/src/main/java/fr/ifremer/isisfish/simulator
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 19:55:39 +0200 (Mon, 27 Aug 2012)
New Revision: 3738
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3738
Log:
Ajout d'une method pour vider le cache ?\195?\160 la fin d'un pas de temps.
Modified:
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2012-08-27 17:51:40 UTC (rev 3737)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2012-08-27 17:55:39 UTC (rev 3738)
@@ -25,8 +25,6 @@
package fr.ifremer.isisfish.simulator;
-import fr.ifremer.isisfish.aspect.CacheAspect;
-import fr.ifremer.isisfish.aspect.TraceAspect;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -41,6 +39,7 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityUtils;
+import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.Cache;
import fr.ifremer.isisfish.util.Trace;
@@ -329,6 +328,17 @@
}
/**
+ * Clear isis fish cache for specified time step.
+ *
+ * @param step time step to remove data
+ * @since 4.1.1.0
+ * @throws TopiaException
+ */
+ public void clearCache(TimeStep step) throws TopiaException {
+ getCache().clear(step);
+ }
+
+ /**
* @return Returns the scriptDirectory.
*/
public File getScriptDirectory() {
1
0
Author: echatellier
Date: 2012-08-27 19:51:40 +0200 (Mon, 27 Aug 2012)
New Revision: 3737
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3737
Log:
Use topia 2.6.13
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-27 17:21:00 UTC (rev 3736)
+++ trunk/pom.xml 2012-08-27 17:51:40 UTC (rev 3737)
@@ -525,7 +525,7 @@
<!-- Dependencies version -->
<jaxxVersion>2.4.2</jaxxVersion>
<eugeneVersion>2.4.2</eugeneVersion>
- <topiaVersion>2.6.13-SNAPSHOT</topiaVersion>
+ <topiaVersion>2.6.13</topiaVersion>
<hibernateVersion>3.6.10.Final</hibernateVersion>
<nuitonUtilsVersion>2.4.7</nuitonUtilsVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
1
0
r3736 - in trunk/src/main/java/fr/ifremer/isisfish: aspect simulator simulator/launcher util
by bpoussin@users.forge.codelutin.com Aug. 27, 2012
by bpoussin@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: bpoussin
Date: 2012-08-27 19:21:00 +0200 (Mon, 27 Aug 2012)
New Revision: 3736
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3736
Log:
reecrire du cache et des traces pour qu'il n'y ait plus rien
de statiques, les informations sont toutes stockees dans
le SimualtionContext.
Il est possible de faire un getCache().clear() ou getCache().clear(TimeStep)
Trace et Cache sont vide lors du remove du SimualtionContext.
Added:
trunk/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java
trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java
trunk/src/main/java/fr/ifremer/isisfish/util/Cache.java
Removed:
trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java
trunk/src/main/java/fr/ifremer/isisfish/aspect/Trace.java
Modified:
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/util/Trace.java
Deleted: trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java 2012-08-27 15:20:25 UTC (rev 3735)
+++ trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -1,306 +0,0 @@
-/*
- * #%L
- * IsisFish
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software 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.aspect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.aspectwerkz.annotation.Around;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.annotation.Expression;
-import org.codehaus.aspectwerkz.definition.Pointcut;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
-import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
-import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-import fr.ifremer.isisfish.IsisFishRuntimeException;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.types.TimeStep;
-import fr.ifremer.isisfish.util.Nocache;
-
-/**
- * Cache aspect.
- *
- * Created: 25 août 06 22:42:47
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-@Aspect("perJVM")
-public class Cache {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(Cache.class);
-
- static private List<Cache> instances = new ArrayList<Cache>();
-
- protected long totalCall = 0;
- protected long cacheUsed = 0;
-
- protected Map cache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
-// protected Map cache = new AdaptaptativeCache(1000, 95);
-
- @Expression("execution(* scripts..*(..))")
- Pointcut scriptsMethod;
-
- public Cache() {
- instances.add(this);
- }
-
- /**
- * Return trace object from context.
- *
- * @return trace object from context
- */
- protected fr.ifremer.isisfish.util.Trace getTrace() {
- SimulationContext context = SimulationContext.get();
-
- fr.ifremer.isisfish.util.Trace result = (fr.ifremer.isisfish.util.Trace) context
- .getValue(fr.ifremer.isisfish.util.Trace.class.getName());
-
- if (result == null) {
- throw new IsisFishRuntimeException("No trace object found in context");
- }
-
- return result;
- }
-
-// @Before("scriptsMethod")
-// public void traceBeforeExecute (JoinPoint jp) {
-// System.out.println("before !!!");
-// }
-//
-// @AfterThrowing("scriptsMethod")
-// public void traceAfterThrowingExecute (JoinPoint jp) {
-// System.out.println("throwing !!!");
-// }
-//
-// @After("scriptsMethod")
-// public void traceAfterExecute (JoinPoint jp) {
-// System.out.println("After !!!");
-// }
-
-
- @Around("scriptsMethod")
- public Object call(final JoinPoint jp) throws Throwable {
- totalCall++;
-
- Object result = null;
- Method method = ((MethodSignature)jp.getSignature()).getMethod();
- if (method.getAnnotation(Nocache.class) != null ||
- method.getDeclaringClass().getAnnotation(Nocache.class) != null) {
- result = realCall(jp);
- } else {
- Object key = computeKey(jp);
- result = cache.get(key);
- if (result == null) {
-
- // computation increment (/ by 0)
- // FIXME need to be called, but fail with empty stack
- //Method method = ((MethodSignature)jp.getSignature()).getMethod();
- //getTrace().traceAfterComputation(method);
-
- result = realCall(jp);
- // addListenerFor(key); // pas necessaire car on a la date et pour une date donnée rien ne peut changer
- if (result != null) { // util pour les methodes retournant void, ne fonctionne pas si on met AND !execute(void *(..)) dans l'aspect. En fait fonction seulement si utilisé avec les traces :(
- cache.put(key, result);
- }
- } else {
- cacheUsed++;
- }
- }
-
- if (log.isTraceEnabled()) {
- log.trace(((MethodSignature)jp.getSignature()).getMethod()
- + " args " + Arrays.toString(((MethodRtti)jp.getRtti()).getParameterValues())
- + " result = " + result);
- }
- return result;
- }
-
- /**
- * On fait l'appel reel dans une autre methode pour pouvoir le savoir
- * dans les traces
- *
- * @param jp
- * @return ?
- * @throws Throwable
- */
- protected Object realCall(final JoinPoint jp) throws Throwable {
- Object result = jp.proceed();
- return result;
- }
-
- /**
- * Attention pour avoir une chaine en sortie on prend la reprensentation
- * toString des arguments. Mais en utilisant la methode toString implanté
- * dans Object.
- * <p>
- * Pour les objets de style Number ou String, il faut prendre le vrai
- * toString, pour que 2 soit bien egal a 2.
- *
- * @param jp
- * @return ?
- */
- protected Object computeKey(JoinPoint jp) {
- Method method = ((MethodSignature)jp.getSignature()).getMethod();
- Object[] args = ((MethodRtti)jp.getRtti()).getParameterValues();
-
- //String result = method.toString();
- String result = method.getDeclaringClass().getSimpleName() + "." +
- method.getName();
- for (Object o : args) {
- result += ";";
- if (o instanceof Number || o instanceof String) {
- result += o.toString();
- } else if (o instanceof TimeStep) {
- result += ((TimeStep)o).getStep();
- } else if (o instanceof TopiaEntity) {
- result += ((TopiaEntity)o).getTopiaId().replaceAll("fr.ifremer.isisfish.entities.", "");
- } else {
- result += ObjectUtils.identityToString(o);
- result = result.replaceAll("org.nuiton.math.matrix.", "");
- }
- }
-
- return result;
-
-// Method method = ((MethodSignature)jp.getSignature()).getMethod();
-// Object[] args = ((MethodRtti)jp.getRtti()).getParameterValues();
-//
-// Object[] keys = new Object[args.length + 1];
-// keys[0] = method;
-// System.arraycopy(args, 0, keys, 1, args.length);
-//
-// MultiKey result = new MultiKey(keys, false);
-//
-// return result;
- }
-// protected HashMapMultiKey.Key computeKey(JoinPoint jp) {
-// Method method = ((MethodSignature)jp.getSignature()).getMethod();
-// Object[] args = ((MethodRtti)jp.getRtti()).getParameterValues();
-//
-// HashMapMultiKey.Key result = new HashMapMultiKey.Key();
-// result.add(method);
-// for (Object arg : args) {
-// result.add(arg);
-// }
-//
-// return result;
-// }
-
-
- /**
- * @return Returns the cacheUsed.
- */
- static public long getCacheUsed() {
- long result = 0;
- for (Cache cache : instances) {
- result += cache.cacheUsed;
- }
- return result;
- }
-
- /**
- * @return Returns the totalCall.
- */
- static public long getTotalCall() {
- long result = 0;
- for (Cache cache : instances) {
- result += cache.totalCall;
- }
- return result;
- }
-
- /**
- * Affiche les statistiques
- *
- */
- static public String printStatistiqueAndClear() {
- StringBuffer result = new StringBuffer();
- for (Cache cache : instances) {
- result.append("--- Cache Statistiques ---\n");
- result.append("Total call: " + cache.totalCall + "\n");
- result.append("Cache used: " + cache.cacheUsed + "\n");
- result.append("Cache usage: " + (100*cache.cacheUsed/cache.totalCall) + "%" + "\n");
- result.append("--------------------\n");
- cache.cache.clear();
- }
- System.out.println(result.toString());
- instances.clear();
- return result.toString();
- }
-
-// /**
-// * Parcours les elements de la cle et pour ceux du type Entities se
-// * met listener pour pouvoir supprimer l'entre du cache lors de leur
-// * modification
-// *
-// * @param key
-// */
-// protected void addListenerFor(HashMapMultiKey.Key key) {
-// }
-
-
- class AdaptaptativeCache extends LinkedHashMap<String, Object> {
- protected int maxMemory = 95;
- /**
- *
- * @param capacity initial capacity
- * @param maxMemory maximum memory used (0-100)
- */
- public AdaptaptativeCache(int capacity, int maxMemory) {
- super(capacity, 0.75f, true);
- this.maxMemory = maxMemory;
- }
-
- /* (non-Javadoc)
- * @see java.util.LinkedHashMap#removeEldestEntry(java.util.Map.Entry)
- */
- @Override
- protected boolean removeEldestEntry(Entry<String, Object> eldest) {
- double free = 100.0 * Runtime.getRuntime().freeMemory() / Runtime.getRuntime().maxMemory() ;
- boolean result = 100 - free > maxMemory;
- return result;
- }
- }
-}
-
-
Copied: trunk/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java (from rev 3734, trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -0,0 +1,93 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software 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.aspect;
+
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.util.Cache;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.aspectwerkz.annotation.Around;
+import org.codehaus.aspectwerkz.annotation.Aspect;
+import org.codehaus.aspectwerkz.annotation.Expression;
+import org.codehaus.aspectwerkz.definition.Pointcut;
+import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
+import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
+import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
+
+/**
+ * CacheAspect aspect.
+ *
+ * Created: 25 août 06 22:42:47
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+@Aspect("perJVM")
+public class CacheAspect {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(CacheAspect.class);
+
+ @Expression("execution(* scripts..*(..))")
+ Pointcut scriptsMethod;
+
+ public CacheAspect() {
+ }
+
+ /**
+ * Return trace object from context.
+ *
+ * @return trace object from context
+ */
+ protected Cache getCache() {
+ SimulationContext context = SimulationContext.get();
+ Cache result = context.getCache();
+ return result;
+ }
+
+ @Around("scriptsMethod")
+ public Object call(final JoinPoint jp) throws Throwable {
+ Method method = ((MethodSignature)jp.getSignature()).getMethod();
+ Object[] args = ((MethodRtti)jp.getRtti()).getParameterValues();
+ Object result = getCache().get(method, args, jp);
+
+ if (log.isTraceEnabled()) {
+ log.trace(((MethodSignature)jp.getSignature()).getMethod()
+ + " args " + Arrays.toString(((MethodRtti)jp.getRtti()).getParameterValues())
+ + " result = " + result);
+ }
+ return result;
+ }
+
+}
+
+
Deleted: trunk/src/main/java/fr/ifremer/isisfish/aspect/Trace.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/aspect/Trace.java 2012-08-27 15:20:25 UTC (rev 3735)
+++ trunk/src/main/java/fr/ifremer/isisfish/aspect/Trace.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -1,127 +0,0 @@
-/*
- * #%L
- * IsisFish
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2006 - 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.aspect;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.aspectwerkz.annotation.After;
-import org.codehaus.aspectwerkz.annotation.AfterThrowing;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.annotation.Before;
-import org.codehaus.aspectwerkz.annotation.Expression;
-import org.codehaus.aspectwerkz.definition.Pointcut;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
-import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
-
-import fr.ifremer.isisfish.IsisFishRuntimeException;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-
-/**
- * Permet de tracer les appels aux methodes utilisateur ainsi que l'execution
- * a ces methodes. La difference entre les deux est lors de l'utilisation du
- * cache les appels seront superieur a l'execution car certaine valeur seront
- * reutilisé dans le cache
- *
- * Created: 25 août 06 22:19:21
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-@Aspect("perJVM")
-public class Trace {
-
- /** to use log facility, just put in your code: log.info("..."); */
- static private Log log = LogFactory.getLog(Trace.class);
-
- static private List<Trace> instances = new ArrayList<Trace>();
-
- @Expression("execution(* scripts..*(..))"
- + " || execution(* simulators..*(..))"
- + " || execution(* rules..*(..)) "
- + " || execution(* simulationplans..*(..)) "
- + " || execution(* formules..*(..))")
- Pointcut executeMethod;
-
- public Trace() {
- instances.add(this);
- }
-
- /**
- * Return trace object from context.
- *
- * @return trace object from context
- */
- protected fr.ifremer.isisfish.util.Trace getTrace() {
- SimulationContext context = SimulationContext.get();
-
- fr.ifremer.isisfish.util.Trace result = (fr.ifremer.isisfish.util.Trace) context
- .getValue(fr.ifremer.isisfish.util.Trace.class.getName());
-
- if (result == null) {
- throw new IsisFishRuntimeException("No trace object found in context");
- }
-
- return result;
- }
-
- @Before("executeMethod")
- public void traceBeforeExecute(JoinPoint jp) {
- getTrace().traceBefore();
- }
-
- @AfterThrowing(type = "java.lang.Exception", pointcut = "executeMethod")
- public void traceAfterThrowingExecute(JoinPoint jp) {
- // si une exeption est leve, il faut faire la meme chose
- traceAfterExecute(jp);
- }
-
- @After("executeMethod")
- public void traceAfterExecute(JoinPoint jp) {
- Method method = ((MethodSignature) jp.getSignature()).getMethod();
- getTrace().traceAfterCall(method);
- }
-
- /**
- * Affiche les statistiques
- *
- * @return statistics as string
- */
- public static String printStatistiqueAndClear() {
- StringBuffer result = new StringBuffer();
- for (Trace trace : instances) {
- result.append(trace.getTrace().printStatisticAndClear());
- }
- instances.clear();
- return result.toString();
- }
-}
Copied: trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java (from rev 3734, trunk/src/main/java/fr/ifremer/isisfish/aspect/Trace.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -0,0 +1,104 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2006 - 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.aspect;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.aspectwerkz.annotation.After;
+import org.codehaus.aspectwerkz.annotation.AfterThrowing;
+import org.codehaus.aspectwerkz.annotation.Aspect;
+import org.codehaus.aspectwerkz.annotation.Before;
+import org.codehaus.aspectwerkz.annotation.Expression;
+import org.codehaus.aspectwerkz.definition.Pointcut;
+import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
+import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
+
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.util.Trace;
+
+/**
+ * Permet de tracer les appels aux methodes utilisateur ainsi que l'execution
+ * a ces methodes. La difference entre les deux est lors de l'utilisation du
+ * cache les appels seront superieur a l'execution car certaine valeur seront
+ * reutilisé dans le cache
+ *
+ * Created: 25 août 06 22:19:21
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+@Aspect("perJVM")
+public class TraceAspect {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(TraceAspect.class);
+
+ @Expression("execution(* scripts..*(..))"
+ + " || execution(* simulators..*(..))"
+ + " || execution(* rules..*(..)) "
+ + " || execution(* simulationplans..*(..)) "
+ + " || execution(* formules..*(..))")
+ Pointcut executeMethod;
+
+ public TraceAspect() {
+ }
+
+ /**
+ * Return trace object from context.
+ *
+ * @return trace object from context
+ */
+ protected Trace getTrace() {
+ SimulationContext context = SimulationContext.get();
+ Trace result = context.getTrace();
+ return result;
+ }
+
+ @Before("executeMethod")
+ public void traceBeforeExecute(JoinPoint jp) {
+ getTrace().traceBefore();
+ }
+
+ @AfterThrowing(type = "java.lang.Exception", pointcut = "executeMethod")
+ public void traceAfterThrowingExecute(JoinPoint jp) {
+ // si une exeption est leve, il faut faire la meme chose
+ traceAfterExecute(jp);
+ }
+
+ @After("executeMethod")
+ public void traceAfterExecute(JoinPoint jp) {
+ Method method = ((MethodSignature) jp.getSignature()).getMethod();
+ getTrace().traceAfterCall(method);
+ }
+}
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2012-08-27 15:20:25 UTC (rev 3735)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -25,6 +25,8 @@
package fr.ifremer.isisfish.simulator;
+import fr.ifremer.isisfish.aspect.CacheAspect;
+import fr.ifremer.isisfish.aspect.TraceAspect;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -39,6 +41,8 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityUtils;
+import fr.ifremer.isisfish.util.Cache;
+import fr.ifremer.isisfish.util.Trace;
/**
* Keep all information on one simulation.
@@ -72,6 +76,10 @@
protected Set<SimulationListener> simulationListeners = new LinkedHashSet<SimulationListener>();
protected ClassLoader classLoader = null;
protected File scriptDirectory;
+ /** l'objet trace qui conserve les donnees statistiques des appels de methodes */
+ protected Trace trace;
+ /** cache used by aspect for this simulation */
+ protected Cache cache;
/** TopiaContext must be used by rule action to modify data */
protected TopiaContext db = null;
@@ -79,7 +87,7 @@
/** TopiaContext must be used to save result */
protected TopiaContext dbResult = null;
- /** Cache des variables d'entités. Topia id > map of attributes. */
+ /** CacheAspect des variables d'entités. Topia id > map of attributes. */
protected Map<TopiaEntity, SimulationVariable> variablesCache = new HashMap<TopiaEntity, SimulationVariable>();
/** Context value used in equation. */
@@ -107,6 +115,10 @@
*/
public static void remove() {
SimulationContext current = get();
+ current.getCache().clear();
+ current.cache = null;
+ current.getTrace().clear();
+ current.trace = null;
current.values.clear();
current.classLoader = null;
simulationContext.remove();
@@ -190,6 +202,19 @@
this.classLoader = classLoader;
}
+ public Trace getTrace() {
+ if (trace == null) {
+ trace = new Trace();
+ }
+ return trace;
+ }
+
+ public Cache getCache() {
+ if (cache == null) {
+ cache = new Cache();
+ }return cache;
+ }
+
/**
* Permet de recuperer une valeur prealablement stocker avec un setValue
* @param name le nom de la valeur souhaitée
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 15:20:25 UTC (rev 3735)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -54,9 +54,9 @@
import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.aspect.AspectClassLoader;
-import fr.ifremer.isisfish.aspect.Cache;
+import fr.ifremer.isisfish.aspect.CacheAspect;
import fr.ifremer.isisfish.aspect.RuleAspect;
-import fr.ifremer.isisfish.aspect.Trace;
+import fr.ifremer.isisfish.aspect.TraceAspect;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.datastore.SimulatorStorage;
import fr.ifremer.isisfish.simulator.SimulationContext;
@@ -354,20 +354,14 @@
// Activation de l'OAP demandée
//
if (parameters.getUseStatistic() || parameters.getUseOptimization()) {
-
- // il est necessaire de passer un object trace/cache
- // commun, donc on le met dans le context
- // pas moyen de le passer autrement plus simplement
- fr.ifremer.isisfish.util.Trace traceObject = new fr.ifremer.isisfish.util.Trace("");
- context.setValue(fr.ifremer.isisfish.util.Trace.class.getName(), traceObject);
-
+
if (parameters.getUseStatistic()) {
message(control, _("isisfish.message.setting.trace.aspects"));
- classLoader.deploy(Trace.class);
+ classLoader.deploy(TraceAspect.class);
}
if (parameters.getUseOptimization()) {
message(control, _("isisfish.message.setting.cache.aspects"));
- classLoader.deploy(Cache.class);
+ classLoader.deploy(CacheAspect.class);
}
}
@@ -472,11 +466,11 @@
(end - start) / 1000000, "s'.'S"));
SimulationParameter param = simulation.getParameter();
if (param.getUseStatistic()) {
- String trace = Trace.printStatistiqueAndClear();
+ String trace = context.getTrace().printStatisticAndClear();
simulation.getInformation().setStatistic(trace);
}
if (param.getUseOptimization()) {
- String cache = Cache.printStatistiqueAndClear();
+ String cache = context.getCache().printStatistiqueAndClear();
simulation.getInformation().setOptimizationUsage(cache);
}
@@ -487,7 +481,7 @@
}
FileUtil.deleteRecursively(simulationBuildDirectory);
- // context is used in Trace.printStatistiqueAndClear()
+ // context is used in TraceAspect.printStatistiqueAndClear()
SimulationContext.remove();
}
return result;
Copied: trunk/src/main/java/fr/ifremer/isisfish/util/Cache.java (from rev 3734, trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/Cache.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/Cache.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -0,0 +1,288 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software 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.util;
+
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.TimeStep;
+import java.lang.reflect.Method;
+import java.util.Map;
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * Cache utilise pour mettre les resultats de methode durant la simulation
+ * pour minimiser les appels
+ *
+ * Created: 25 août 06 22:42:47
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class Cache {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(Cache.class);
+
+ // la longueur du package pour minimiser la longueur des topiaId
+ static final private int entityPackageLenght = "fr.ifremer.isisfish.entities.".length();
+ // la valeur NULL a utilise a la place de null pour les timeStep
+ static final private Object NULL = new Object();
+
+// static private List<CacheAspect> instances = new ArrayList<CacheAspect>();
+
+ protected long totalCall = 0;
+ protected long cacheUsed = 0;
+
+ /**
+ * map<TimeStep, Map<Key, Value>>
+ * TimeStep peut etre null via l'objet NULL
+ * Key est la cle calcule par computeKey
+ * Value est la valeur du cache
+ *
+ * TimeStep est en WEAK pour que des que l'on passe au pas de temps suivant
+ * ils soit efface de la memoire si plus personne n'a de reference sur
+ * ce pas de temps. L'autre moyen est de force l'effacement via clear(TimeStep)
+ *
+ * Value est en SOFT reference pour que les valeurs soit effacee du cache
+ * lorsqu'il n'y a plus de place memoire
+ */
+ protected Map cache = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD);
+// protected Map cache = new AdaptaptativeCache(1000, 95);
+
+ public Cache() {
+ }
+
+ /**
+ * Return trace object from context.
+ *
+ * @return trace object from context
+ */
+ protected Trace getTrace() {
+ SimulationContext context = SimulationContext.get();
+ Trace result = context.getTrace();
+ return result;
+ }
+
+ /**
+ * Recupere pour un pas de temps donnes une valeur calcule pour une cle
+ * @param step le pas de temps pour lequel on souhaite ajouter (ou null)
+ * @param key la cle de storage
+ * @param defaultValue la valeur par defaut a retourner si elle n'est pas en cache
+ * si defaultValue est une JoinPoint alors un proceed est appele dessus et le
+ * resultat de l'appel est utiliser comme valeur par defaut
+ * @return la valeur dans le cache ou defaultValue
+ */
+ public Object get(Method method, Object[] args, Object defaultValue) throws Throwable {
+ totalCall++;
+
+ Object result = null;
+ if (method.getAnnotation(Nocache.class) != null ||
+ method.getDeclaringClass().getAnnotation(Nocache.class) != null) {
+ result = realCall(defaultValue);
+ } else {
+ // compute key and keep TimeStep objet
+ StringBuilder sbKey = new StringBuilder();
+ // le pas de temps trouve dans les arguments
+ TimeStep step = computeKey(sbKey, method, args);
+
+ Object key = sbKey.toString();
+ result = get(step, key);
+ if (result == null) {
+
+ // computation increment (/ by 0)
+ // FIXME need to be called, but fail with empty stack
+ //getTrace().traceAfterComputation(method);
+
+ result = realCall(defaultValue);
+ if (result != null) { // util pour les methodes retournant void, ne fonctionne pas si on met AND !execute(void *(..)) dans l'aspect. En fait fonction seulement si utilisé avec les traces :(
+ put(step, key, result);
+ }
+ } else {
+ cacheUsed++;
+ }
+ }
+ return result;
+ }
+
+ protected TimeStep computeKey(StringBuilder sbKey, Method method, Object[] args) {
+ TimeStep result = null;
+ sbKey.append(method.getDeclaringClass().getSimpleName());
+ sbKey.append(".");
+ sbKey.append(method.getName());
+ for (Object o : args) {
+ sbKey.append(";");
+ if (o == null) {
+ sbKey.append("null");
+ } else if (o instanceof Number || o instanceof String) {
+ sbKey.append(o.toString());
+ } else if (o instanceof TimeStep) {
+ result = (TimeStep)o;
+ sbKey.append(((TimeStep)o).getStep());
+ } else if (o instanceof TopiaEntity) {
+ sbKey.append( ((TopiaEntity)o).getTopiaId().substring(entityPackageLenght));
+ } else {
+ // on minimise en prenant que le nom de la classe (pas le package)
+ sbKey.append(o.getClass().getSimpleName());
+ sbKey.append('@');
+ // et en lui ajoutant son adresse memoire en Hexa
+ sbKey.append(Integer.toHexString(System.identityHashCode(o)));
+ }
+ }
+ return result;
+ }
+
+ protected Map getCacheTimeStep(TimeStep step) {
+ Object key = step;
+ if (step == null) {
+ key = NULL;
+ }
+ Map result = (Map)cache.get(key);
+ if (result == null) {
+ result = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
+ cache.put(key, result);
+ }
+ return result;
+ }
+
+ protected Object get(TimeStep step, Object key) {
+ Object result = null;
+ Map cacheTimeStep = getCacheTimeStep(step);
+ if (cacheTimeStep != null) {
+ result = cacheTimeStep.get(key);
+ }
+ return result;
+ }
+
+ protected void put(TimeStep step, Object key, Object value) {
+ getCacheTimeStep(step).put(key, value);
+ }
+
+ /**
+ * On fait l'appel reel dans une autre methode pour pouvoir le savoir
+ * dans les traces
+ *
+ * @param jp
+ * @return ?
+ * @throws Throwable
+ */
+ protected Object realCall(Object defaultValue) throws Throwable {
+ Object result = defaultValue;
+ if (defaultValue instanceof JoinPoint) {
+ result = ((JoinPoint)defaultValue).proceed();
+ }
+ return result;
+ }
+
+ /**
+ * remove all values in cache
+ */
+ public void clear() {
+ cache.clear();
+ }
+
+ /**
+ * remove all values in cache for the specied TimeStep
+ */
+ public void clear(TimeStep step) {
+ Object key = step;
+ if (key == null) {
+ key = NULL;
+ }
+ cache.remove(key);
+ }
+
+ /**
+ * @return Returns the cacheUsed.
+ */
+ public long getCacheUsed() {
+ long result = cacheUsed;
+ return result;
+ }
+
+ /**
+ * @return Returns the totalCall.
+ */
+ public long getTotalCall() {
+ long result = totalCall;
+ return result;
+ }
+
+ /**
+ * Affiche les statistiques
+ *
+ */
+ public String printStatistiqueAndClear() {
+ StringBuilder result = new StringBuilder();
+ result.append("--- Cache Statistiques ---\n");
+ result.append("Total call: ").append(totalCall).append("\n");
+ result.append("Cache used: ").append(cacheUsed).append("\n");
+ long percent = 0;
+ if (totalCall != 0) {
+ percent = 100*cacheUsed/totalCall;
+ }
+ result.append("Cache usage: ").append(percent).append("%\n");
+ result.append("--------------------\n");
+ cache.clear();
+
+ System.out.println(result.toString());
+ return result.toString();
+ }
+
+ // EN COURS D'ECRITURE MAIS JAMAIS FINI :(
+ // l'idee est de prendre la place memoire qu'il y a, mais s'il n'y en
+ // a plus on commence par enlever les objets les plus vieux
+// class AdaptaptativeCache extends LinkedHashMap<String, Object> {
+// protected int maxMemory = 95;
+// /**
+// *
+// * @param capacity initial capacity
+// * @param maxMemory maximum memory used (0-100)
+// */
+// public AdaptaptativeCache(int capacity, int maxMemory) {
+// super(capacity, 0.75f, true);
+// this.maxMemory = maxMemory;
+// }
+//
+// /* (non-Javadoc)
+// * @see java.util.LinkedHashMap#removeEldestEntry(java.util.Map.Entry)
+// */
+// @Override
+// protected boolean removeEldestEntry(Entry<String, Object> eldest) {
+// double free = 100.0 * Runtime.getRuntime().freeMemory() / Runtime.getRuntime().maxMemory() ;
+// boolean result = 100 - free > maxMemory;
+// return result;
+// }
+// }
+}
+
+
Modified: trunk/src/main/java/fr/ifremer/isisfish/util/Trace.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/Trace.java 2012-08-27 15:20:25 UTC (rev 3735)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/Trace.java 2012-08-27 17:21:00 UTC (rev 3736)
@@ -71,17 +71,13 @@
/** heure de depart de l'appel a la methode (avec le temps des autres methodes) */
final static private int STACK_TIME_START_NEST_METHOD = 2;
-
- protected String name = "";
-
/** array : [call's numbers, call do, min time, max time, total time, total time with child]*/
protected Map<String, long[]> statistics = new LinkedHashMap<String, long[]>();
/** array : [nest e call, start time, start time with child] */
protected Stack<long[]> callStack = new Stack<long[]>();
- public Trace(String name) {
- this.name = name;
+ public Trace() {
}
public long[] getStatistics(Object e) {
@@ -93,7 +89,14 @@
}
return result;
}
-
+
+ /**
+ * Clear current value statistics (all is reset)
+ */
+ public void clear() {
+ statistics.clear();
+ }
+
public void traceBefore () {
// ajout dans le stack
long current = System.nanoTime();
@@ -167,7 +170,7 @@
long call = 0;
long computation = 0;
StringBuffer result = new StringBuffer();
- result.append("--- " + name + " Statistics ---\n");
+ result.append("--- " + " Statistics ---\n");
for (String e : statistics.keySet()) {
long[] stat = getStatistics(e);
1
0
r3735 - in trunk: . src/main/java/fr/ifremer/isisfish/datastore src/main/java/fr/ifremer/isisfish/datastore/migration src/main/java/fr/ifremer/isisfish/simulator src/main/java/fr/ifremer/isisfish/ui/sensitivity src/main/java/fr/ifremer/isisfish/ui/widget/editor
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 17:20:25 +0200 (Mon, 27 Aug 2012)
New Revision: 3735
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3735
Log:
Update to topia 2.6.13
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/datastore/FormuleStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV33V40.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/MetierMonitor.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java
trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java
trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterTableCellEditor.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/pom.xml 2012-08-27 15:20:25 UTC (rev 3735)
@@ -525,7 +525,7 @@
<!-- Dependencies version -->
<jaxxVersion>2.4.2</jaxxVersion>
<eugeneVersion>2.4.2</eugeneVersion>
- <topiaVersion>2.6.9</topiaVersion>
+ <topiaVersion>2.6.13-SNAPSHOT</topiaVersion>
<hibernateVersion>3.6.10.Final</hibernateVersion>
<nuitonUtilsVersion>2.4.7</nuitonUtilsVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/FormuleStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/FormuleStorage.java 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/FormuleStorage.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -178,7 +178,7 @@
try {
@SuppressWarnings("unchecked")
- List<String> contextCategory = (List<String>) context.find(
+ List<String> contextCategory = (List<String>) context.findAll(
"SELECT DISTINCT category FROM Equation");
all.addAll(contextCategory);
} catch (TopiaException eee) {
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -168,7 +168,7 @@
mustClose = true;
}
- List<String> result = (List<String>) tx.find("Select " + Result.PROPERTY_RESULT_STEP + "||':'||name from fr.ifremer.isisfish.entities.Result");
+ List<String> result = (List<String>) tx.findAll("Select " + Result.PROPERTY_RESULT_STEP + "||':'||name from fr.ifremer.isisfish.entities.Result");
if (mustClose) {
tx.closeContext();
}
@@ -430,7 +430,7 @@
ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
result = (List<String>) resultPS.getContext()
- .find("Select distinct name from fr.ifremer.isisfish.entities.Result order by name");
+ .findAll("Select distinct name from fr.ifremer.isisfish.entities.Result order by name");
if (mustClose) {
tx.closeContext();
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV33V40.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV33V40.java 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV33V40.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -120,7 +120,7 @@
}
// build new equation for maturity group and reproduction rate
- List<Population> pops = tx.find("from " + Population.class.getName());
+ List<Population> pops = tx.findAll("from " + Population.class.getName());
for (Population pop : pops) {
String content = getReproductionRateContent(pop, reproductionResults);
((PopulationImpl)pop).setReproductionRateEquationContent(content);
@@ -129,7 +129,7 @@
// start equation migration
if (IsisFish.config.isLaunchUI()) {
- List<Equation> equations = tx.find("from " + Equation.class.getName());
+ List<Equation> equations = tx.findAll("from " + Equation.class.getName());
for (Equation equation : equations) {
// empty is empty and stay empty
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/MetierMonitor.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/MetierMonitor.java 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/MetierMonitor.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -269,7 +269,7 @@
TopiaContext tx = metier.getTopiaContext();
List<StrategyMonthInfo> res = null;
// FIXME, c faux car il ne faut prendre que les str selectionnée pour la simulation
- res = tx.find("select * from fr.ifremer.isisfish.entities.StrategyMonthInfo where strategyMonthInfo.month=?",
+ res = tx.findAll("select * from fr.ifremer.isisfish.entities.StrategyMonthInfo where strategyMonthInfo.month=?",
month, metier);
for(StrategyMonthInfo smi : res){
@@ -298,7 +298,7 @@
TopiaContext tx = metier.getTopiaContext();
List<SetOfVessels> res = null;
// FIXME, c faux car il ne faut prendre que les str selectionnée pour la simulation
- res = tx.find("select setOfVessels from fr.ifremer.isisfish.entities.EffortDescription where possibleMetiers=?",
+ res = tx.findAll("select setOfVessels from fr.ifremer.isisfish.entities.EffortDescription where possibleMetiers=?",
metier);
for(SetOfVessels sov : res){
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -75,7 +75,7 @@
Variable v = variablesCache.get(name);
if (v == null) {
TopiaContext topiaContext = simulationContext.getDB();
- List<Variable> vindb = topiaContext.find("FROM " + Variable.class.getName() +
+ List<Variable> vindb = topiaContext.findAll("FROM " + Variable.class.getName() +
" WHERE " + Variable.PROPERTY_ENTITY_ID + " = :id" +
" AND " + Variable.PROPERTY_NAME + " = :name",
"id", topiaEntity.getTopiaId(),
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-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -883,7 +883,7 @@
TopiaContext context = null;
try {
context = regionStorage.getStorage().beginTransaction();
- List list = context.find("from " + value.getClass().getName());
+ List list = context.findAll("from " + value.getClass().getName());
JComboBox c = new JComboBox(list.toArray());
c.setSelectedItem(value);
result = c;
@@ -1041,7 +1041,7 @@
TopiaContext context = null;
try {
context = regionStorage.getStorage().beginTransaction();
- List list = context.find("from " + type.getName());
+ List list = context.findAll("from " + type.getName());
JComboBox c = new JComboBox(list.toArray());
result = c;
} catch (TopiaException ex) {
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterTableCellEditor.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterTableCellEditor.java 2012-08-27 15:05:05 UTC (rev 3734)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterTableCellEditor.java 2012-08-27 15:20:25 UTC (rev 3735)
@@ -154,7 +154,7 @@
}
TopiaContext context = regionStorage.getStorage().beginTransaction();
if (context != null) {
- List list = context.find("from " + type.getName());
+ List list = context.findAll("from " + type.getName());
c = new JComboBox(list.toArray());
c.setSelectedItem(value);
editor = c;
1
0
r3734 - trunk/src/main/java/fr/ifremer/isisfish/aspect
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 17:05:05 +0200 (Mon, 27 Aug 2012)
New Revision: 3734
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3734
Log:
Improve cache key length
Modified:
trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java 2012-08-27 15:04:12 UTC (rev 3733)
+++ trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java 2012-08-27 15:05:05 UTC (rev 3734)
@@ -25,6 +25,7 @@
package fr.ifremer.isisfish.aspect;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -44,9 +45,11 @@
import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
+import org.nuiton.topia.persistence.TopiaEntity;
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.Nocache;
/**
@@ -180,13 +183,20 @@
Method method = ((MethodSignature)jp.getSignature()).getMethod();
Object[] args = ((MethodRtti)jp.getRtti()).getParameterValues();
- String result = method.toString();
+ //String result = method.toString();
+ String result = method.getDeclaringClass().getSimpleName() + "." +
+ method.getName();
for (Object o : args) {
result += ";";
if (o instanceof Number || o instanceof String) {
result += o.toString();
+ } else if (o instanceof TimeStep) {
+ result += ((TimeStep)o).getStep();
+ } else if (o instanceof TopiaEntity) {
+ result += ((TopiaEntity)o).getTopiaId().replaceAll("fr.ifremer.isisfish.entities.", "");
} else {
result += ObjectUtils.identityToString(o);
+ result = result.replaceAll("org.nuiton.math.matrix.", "");
}
}
1
0
r3733 - in trunk/src/main: java/fr/ifremer/isisfish/simulator java/fr/ifremer/isisfish/simulator/launcher java/fr/ifremer/isisfish/ui/sensitivity java/fr/ifremer/isisfish/ui/simulator resources/i18n
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 17:04:12 +0200 (Mon, 27 Aug 2012)
New Revision: 3733
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3733
Log:
fixes #1420: Add option to delete sensitivity analysis result
Modified:
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterCache.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterImpl.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/SimulationService.java
trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.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/simulator/SimulationParameter.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2012-08-27 15:04:12 UTC (rev 3733)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 - 2011 Ifremer, Code Lutin, Chatellier Eric
+ * Copyright (C) 2010 - 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
@@ -96,30 +96,30 @@
*
* @return Description property.
*/
- public abstract String getDescription();
+ public String getDescription();
/**
* Set simulation description.
*
* @param description the description to set.
*/
- public abstract void setDescription(String description);
+ public void setDescription(String description);
/**
* Load region corresponding to {@link #getRegionName()}.
*
* @return the region
*/
- public abstract RegionStorage getRegion();
+ public RegionStorage getRegion();
- public abstract MatrixND getNumberOf(Population pop);
+ public MatrixND getNumberOf(Population pop);
/**
* Get extra rules list.
*
* @return Returns the extraRules.
*/
- public abstract List<String> getExtraRules();
+ public List<String> getExtraRules();
/**
* Add extra rules.
@@ -129,19 +129,19 @@
*
* @param extraRules extra rules to add
*/
- public abstract void addExtraRules(String... extraRules);
+ public void addExtraRules(String... extraRules);
/**
* Get instantiated population list.
*
* @return Returns the populations.
*/
- public abstract List<Population> getPopulations();
+ public List<Population> getPopulations();
/**
* @param populations The populations to set.
*/
- public abstract void setPopulations(List<Population> populations);
+ public void setPopulations(List<Population> populations);
/**
* Get instantiated strategies list.
@@ -150,21 +150,21 @@
*
* @return Returns the strategies.
*/
- public abstract List<Strategy> getStrategies();
+ public List<Strategy> getStrategies();
/**
* Set strategies list.
*
* @param strategies strategies list to set
*/
- public abstract void setStrategies(List<Strategy> strategies);
+ public void setStrategies(List<Strategy> strategies);
/**
* Add new simulation plan.
*
* @param plan simulation plan to add
*/
- public abstract void addSimulationPlan(SimulationPlan plan);
+ public void addSimulationPlan(SimulationPlan plan);
/**
* Remove a plan.
@@ -172,7 +172,7 @@
* @param plan
* @return {@code true} if this list contained the specified element
*/
- public abstract boolean removeSimulationPlan(SimulationPlan plan);
+ public boolean removeSimulationPlan(SimulationPlan plan);
/**
* Get instantiated simulation plan list.
@@ -181,32 +181,32 @@
*
* @return the plans.
*/
- public abstract List<SimulationPlan> getSimulationPlans();
+ public List<SimulationPlan> getSimulationPlans();
/**
* Set plans list.
*
* @param plans plans to set
*/
- public abstract void setSimulationPlans(List<SimulationPlan> plans);
+ public void setSimulationPlans(List<SimulationPlan> plans);
/**
* Return {@code true} if simulation is composed of independent plan only.
*
* @return {@code true} if all {@link SimulationPlan} are {@link SimulationPlanIndependent}
*/
- public abstract boolean isIndependentPlan();
+ public boolean isIndependentPlan();
/**
* Clear plan list.
*/
- public abstract void clearPlans();
+ public void clearPlans();
/**
* Add new rule to rules list.
* @param rule rule to add
*/
- public abstract void addRule(Rule rule);
+ public void addRule(Rule rule);
/**
* Remove a rule.
@@ -214,26 +214,26 @@
* @param rule rule to remove
* @return {@code true} if this list contained the specified element
*/
- public abstract boolean removeRule(Rule rule);
+ public boolean removeRule(Rule rule);
/**
* Get parameters rules list.
*
* @return the rules
*/
- public abstract List<Rule> getRules();
+ public List<Rule> getRules();
/**
* Set simulation rules.
*
* @param rules rules to set
*/
- public abstract void setRules(List<Rule> rules);
+ public void setRules(List<Rule> rules);
/**
* Clear rule list.
*/
- public abstract void clearRules();
+ public void clearRules();
/**
* Return if optimization sould be used.
@@ -242,14 +242,14 @@
*
* @return use optimization
*/
- public abstract boolean getUseOptimization();
+ public boolean getUseOptimization();
/**
* Change use optimization parameter.
*
* @param useOptimization use optimization to set
*/
- public abstract void setUseOptimization(boolean useOptimization);
+ public void setUseOptimization(boolean useOptimization);
/**
* Return if statistic sould be used.
@@ -258,28 +258,28 @@
*
* @return use statistic
*/
- public abstract boolean getUseStatistic();
+ public boolean getUseStatistic();
/**
* Change use statistic property.
*
* @param useStatistic use statistic to set
*/
- public abstract void setUseStatistic(boolean useStatistic);
+ public void setUseStatistic(boolean useStatistic);
/**
* Get export names list.
*
* @return export names list
*/
- public abstract List<String> getExportNames();
+ public List<String> getExportNames();
/**
* Set export names list.
*
* @param exportNames export names list to set
*/
- public abstract void setExportNames(List<String> exportNames);
+ public void setExportNames(List<String> exportNames);
/**
* Get number of sensitivity simulation.
@@ -288,44 +288,59 @@
*
* @return the numberOfSensitivitySimulation
*/
- public abstract int getNumberOfSensitivitySimulation();
+ public int getNumberOfSensitivitySimulation();
/**
* Set number of sensitivity simulation.
*
* @param numberOfSensitivitySimulation number of sensitivity simulation to set
*/
- public abstract void setNumberOfSensitivitySimulation(
+ public void setNumberOfSensitivitySimulation(
int numberOfSensitivitySimulation);
/**
- * Get instantiated sensitivity calculator.
+ * Get instantiated sensitivity analysis.
*
* Default to : null.
*
* @return the sensitivityAnalysis
*/
- public abstract SensitivityAnalysis getSensitivityAnalysis();
+ public SensitivityAnalysis getSensitivityAnalysis();
/**
* @param sensitivityAnalysis the sensitivityAnalysis to set
*/
- public abstract void setSensitivityAnalysis(
- SensitivityAnalysis sensitivityAnalysis);
+ public void setSensitivityAnalysis(SensitivityAnalysis sensitivityAnalysis);
+
+ /**
+ * Get only keep first result policy.
+ *
+ * @return only keep first result policy
+ * @since 4.1.1.0
+ */
+ public boolean isSensitivityAnalysisOnlyKeepFirst();
/**
+ * Change only keep first result policy.
+ *
+ * @param onlyKeepFirst only keep first result policy
+ * @since 4.1.1.0
+ */
+ public void setSensitivityAnalysisOnlyKeepFirst(boolean onlyKeepFirst);
+
+ /**
* Return loaded sensitivity export.
*
* If exports are null or empty, try to load it from last ready parameters.
*
* @return the sensitivityExportNames
*/
- public abstract List<SensitivityExport> getSensitivityExport();
+ public List<SensitivityExport> getSensitivityExport();
/**
* @param sensitivityExport the sensitivityExportNames to set
*/
- public abstract void setSensitivityExport(
+ public void setSensitivityExport(
List<SensitivityExport> sensitivityExport);
/**
@@ -333,42 +348,42 @@
*
* @return use simulation plan.
*/
- public abstract boolean getUseSimulationPlan();
+ public boolean getUseSimulationPlan();
/**
* Set use simulation plans property.
*
* @param useSimulationPlan use simulation plan to set
*/
- public abstract void setUseSimulationPlan(boolean useSimulationPlan);
+ public void setUseSimulationPlan(boolean useSimulationPlan);
/**
* Get simulation number in simulation plan.
*
* @return simulation number in simulation plan
*/
- public abstract int getSimulationPlanNumber();
+ public int getSimulationPlanNumber();
/**
* Set simulation number in simulation plan.
*
* @param simulationPlanNumber simulation plan number to set
*/
- public abstract void setSimulationPlanNumber(int simulationPlanNumber);
+ public void setSimulationPlanNumber(int simulationPlanNumber);
/**
* Get number of year to run to simulate.
*
* @return number of year
*/
- public abstract int getNumberOfYear();
+ public int getNumberOfYear();
/**
* Set number of year to run to simulate.
*
* @param numberOfYear number of year to set
*/
- public abstract void setNumberOfYear(int numberOfYear);
+ public void setNumberOfYear(int numberOfYear);
/**
* Get use prescript.
@@ -377,70 +392,70 @@
*
* @return Returns the usePreScript.
*/
- public abstract boolean getUsePreScript();
+ public boolean getUsePreScript();
/**
* Set use prescript property
*
* @param usePreScript use preScript to set
*/
- public abstract void setUsePreScript(boolean usePreScript);
+ public void setUsePreScript(boolean usePreScript);
/**
* Get prescript content.
*
* @return preScript content
*/
- public abstract String getPreScript();
+ public String getPreScript();
/**
* Set pre script content.
*
* @param preScript prescript content
*/
- public abstract void setPreScript(String preScript);
+ public void setPreScript(String preScript);
/**
* Get region name.
*
* @return region name
*/
- public abstract String getRegionName();
+ public String getRegionName();
/**
* Set region name.
*
* @param regionName region name to set
*/
- public abstract void setRegionName(String regionName);
+ public void setRegionName(String regionName);
/**
* Set simulator name.
*
* @return simulator name.
*/
- public abstract String getSimulatorName();
+ public String getSimulatorName();
/**
* Set simulator name.
*
* @param simulatorName simulator name to set
*/
- public abstract void setSimulatorName(String simulatorName);
+ public void setSimulatorName(String simulatorName);
/**
* Get enabled result names list.
*
* @return enabled result names list
*/
- public abstract Collection<String> getResultEnabled();
+ public Collection<String> getResultEnabled();
/**
* Set enabled result names list.
*
* @param resultEnabled enabled result names list
*/
- public abstract void setResultEnabled(Collection<String> resultEnabled);
+ public void setResultEnabled(Collection<String> resultEnabled);
/**
* Get tag values.
@@ -449,14 +464,14 @@
*
* @return Returns the tagValue.
*/
- public abstract Map<String, String> getTagValue();
+ public Map<String, String> getTagValue();
/**
* Set tag values.
*
* @param tagValue tagValues to set.
*/
- public abstract void setTagValue(Map<String, String> tagValue);
+ public void setTagValue(Map<String, String> tagValue);
/**
* Get simulator log level.
@@ -465,14 +480,14 @@
*
* @return simualtor log level
*/
- public abstract String getSimulLogLevel();
+ public String getSimulLogLevel();
/**
* Set simulator log level.
*
* @param logLevel simulator log level
*/
- public abstract void setSimulLogLevel(String logLevel);
+ public void setSimulLogLevel(String logLevel);
/**
* Get script log level.
@@ -481,14 +496,14 @@
*
* @return script log level
*/
- public abstract String getScriptLogLevel();
+ public String getScriptLogLevel();
/**
* Set script log level.
*
* @param logLevel script log level
*/
- public abstract void setScriptLogLevel(String logLevel);
+ public void setScriptLogLevel(String logLevel);
/**
* Get librairies log level.
@@ -497,38 +512,38 @@
*
* @return librairies log level
*/
- public abstract String getLibLogLevel();
+ public String getLibLogLevel();
/**
* Set lib log level.
*
* @param logLevel
*/
- public abstract void setLibLogLevel(String logLevel);
+ public void setLibLogLevel(String logLevel);
- public abstract boolean isSimulErrorLevel();
+ public boolean isSimulErrorLevel();
- public abstract boolean isSimulWarnLevel();
+ public boolean isSimulWarnLevel();
- public abstract boolean isSimulInfoLevel();
+ public boolean isSimulInfoLevel();
- public abstract boolean isSimulDebugLevel();
+ public boolean isSimulDebugLevel();
- public abstract boolean isScriptErrorLevel();
+ public boolean isScriptErrorLevel();
- public abstract boolean isScriptWarnLevel();
+ public boolean isScriptWarnLevel();
- public abstract boolean isScriptInfoLevel();
+ public boolean isScriptInfoLevel();
- public abstract boolean isScriptDebugLevel();
+ public boolean isScriptDebugLevel();
- public abstract boolean isLibErrorLevel();
+ public boolean isLibErrorLevel();
- public abstract boolean isLibWarnLevel();
+ public boolean isLibWarnLevel();
- public abstract boolean isLibInfoLevel();
+ public boolean isLibInfoLevel();
- public abstract boolean isLibDebugLevel();
+ public boolean isLibDebugLevel();
/**
* Permet d'ajouter des parametres directement à partir de leur
@@ -551,7 +566,7 @@
*
* @return a copy of this instance
*/
- public abstract SimulationParameter copy();
+ public SimulationParameter copy();
/**
* Make a deep copy of current parameters.
@@ -561,14 +576,14 @@
*
* @return new parameters instance
*/
- public abstract SimulationParameter deepCopy();
+ public SimulationParameter deepCopy();
/**
* The toString() method call getters.
*
* So make instances of rules/export/plans...
*/
- public abstract String toString();
+ public String toString();
/**
* Permet de convertir l'objet SimulationParameter en un objet Properties
@@ -586,14 +601,14 @@
* @return L'objet Properties representant les parametres
* @see #fromProperties(Properties)
*/
- public abstract Properties toProperties();
+ public Properties toProperties();
/**
* Load properties from file.
*
* @param props property to read
*/
- public abstract void fromProperties(Properties props);
+ public void fromProperties(Properties props);
/**
* Reload parameters du to context change.
@@ -604,6 +619,6 @@
*
* @throws TopiaException
*/
- public abstract void reloadContextParameters() throws TopiaException;
+ public void reloadContextParameters() throws TopiaException;
}
\ No newline at end of file
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterCache.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterCache.java 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterCache.java 2012-08-27 15:04:12 UTC (rev 3733)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 Ifremer, Code Lutin, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2010 - 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
@@ -533,9 +533,21 @@
SimulationParameter param = getParam();
param.setSimulationPlanNumber(simulationPlanNumber);
store(param);
-
}
+ @Override
+ public boolean isSensitivityAnalysisOnlyKeepFirst() {
+ SimulationParameter param = getParam();
+ return param.isSensitivityAnalysisOnlyKeepFirst();
+ }
+
+ @Override
+ public void setSensitivityAnalysisOnlyKeepFirst(boolean onlyKeepFirst) {
+ SimulationParameter param = getParam();
+ param.setSensitivityAnalysisOnlyKeepFirst(onlyKeepFirst);
+ store(param);
+ }
+
/*
* @see fr.ifremer.isisfish.simulator.SimulationParameter#getNumberOfYear()
*/
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterImpl.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterImpl.java 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameterImpl.java 2012-08-27 15:04:12 UTC (rev 3733)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
+ * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -141,7 +141,7 @@
/** Utilisation du plan de simulation. */
protected Boolean useSimulationPlan;
- /**
+ /**
* Le numero de sequence de la liste des plans de simulation. Le premier
* élement du plan doit etre 0. Si la simulation ne fait pas partie d'un
* plan la valeur est -1. */
@@ -160,6 +160,14 @@
*/
protected Integer numberOfSensitivitySimulation;
+ /**
+ * Dans une analyze de sensibilite, conserver les résultats de toutes
+ * les simulations est inutile, seule les résultats de la premières
+ * sont nécéssaires. Les resultats peuvent être supprimés après les
+ * export de données.
+ */
+ protected Boolean sensitivityAnalysisOnlyKeepFirst;
+
/** Script utilisé pour les analyses de sensibilités. */
protected SensitivityAnalysis sensitivityAnalysis;
@@ -866,7 +874,7 @@
useSimulationPlan = Boolean.FALSE;
}
}
- return this.useSimulationPlan;
+ return useSimulationPlan;
}
/*
@@ -892,7 +900,7 @@
}
}
- return this.simulationPlanNumber.intValue();
+ return simulationPlanNumber.intValue();
}
/*
@@ -903,6 +911,25 @@
this.simulationPlanNumber = simulationPlanNumber;
}
+ @Override
+ public boolean isSensitivityAnalysisOnlyKeepFirst() {
+ if (sensitivityAnalysisOnlyKeepFirst == null) {
+
+ if (propertiesParameters != null) {
+ sensitivityAnalysisOnlyKeepFirst = Boolean.valueOf(propertiesParameters.getProperty("sensitivityAnalysisOnlyKeepFirst", "-1"));
+ } else {
+ sensitivityAnalysisOnlyKeepFirst = Boolean.FALSE;
+ }
+ }
+
+ return sensitivityAnalysisOnlyKeepFirst.booleanValue();
+ }
+
+ @Override
+ public void setSensitivityAnalysisOnlyKeepFirst(boolean onlyKeepFirst) {
+ sensitivityAnalysisOnlyKeepFirst = onlyKeepFirst;
+ }
+
/*
* @see fr.ifremer.isisfish.simulator.SimulationParameter#getNumberOfYear()
*/
@@ -1620,6 +1647,9 @@
}
}
+ // sensitivity params
+ result.setProperty("sensitivityAnalysisOnlyKeepFirst", String.valueOf(isSensitivityAnalysisOnlyKeepFirst()));
+
result.setProperty("usePreScript", String.valueOf(getUsePreScript()));
result.setProperty("preScript", getPreScript());
result.setProperty("useSimulationPlan", String.valueOf(getUseSimulationPlan()));
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 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2012-08-27 15:04:12 UTC (rev 3733)
@@ -48,6 +48,7 @@
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;
@@ -425,6 +426,12 @@
// quand date =progressMax
control.setProgress(control.getProgress() + 1);
+ // suppression des résultats si l'utilisateur a demande à ne conserver
+ // que les resultats de seulement la première simulation d'une AS
+ if (parameters.isSensitivityAnalysisOnlyKeepFirst() && !control.getId().endsWith("_0")) {
+ context.getDbResult().clear(true);
+ }
+
} catch (OutOfMemoryError eee) {
log.error(_("isisfish.error.during.simulation"), eee);
simulation.getInformation().setException(eee);
@@ -479,7 +486,7 @@
log.debug("Delete simulation build directory : " + simulationBuildDirectory.getAbsolutePath());
}
FileUtil.deleteRecursively(simulationBuildDirectory);
-
+
// context is used in Trace.printStatistiqueAndClear()
SimulationContext.remove();
}
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-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2012-08-27 15:04:12 UTC (rev 3733)
@@ -414,14 +414,7 @@
if (resultArchiveFile != null) {
- // FIXME big hacks here, only extract non first simulation
- // only for AS
- if (control.getId().startsWith("as_") && !control.getId().endsWith("_0")) {
- ZipUtil.uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory(), ".*/data/.*");
- }
- else {
- ZipUtil.uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory());
- }
+ ZipUtil.uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory());
if (log.isDebugEnabled()) {
log.debug("Simulation imported : " + resultArchiveFile.getAbsolutePath());
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2012-08-27 15:04:12 UTC (rev 3733)
@@ -223,7 +223,9 @@
}
/**
- * @return les SimulatorLauncher et leurs noms
+ * Retour les lanceurs ayant un executor.
+ *
+ * @return les SimulatorLauncher
*/
public List<SimulatorLauncher> getSimulationLaunchers() {
List<SimulatorLauncher> result = new ArrayList<SimulatorLauncher>(
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-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx 2012-08-27 15:04:12 UTC (rev 3733)
@@ -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
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2012-08-27 15:04:12 UTC (rev 3733)
@@ -135,19 +135,19 @@
});
}
}
-protected void setPreScript() {
+protected void initSimulationParams() {
if (!isSensitivity()){
+ // prescript
String preScript = simulAction.getSimulationParameter().getPreScript();
fieldUseSimulPreScripts.setSelected(preScript != null && !preScript.isEmpty());
getParentContainer(SimulUI.class).getPreScriptUI().getFieldSimulPreScript().setText(preScript);
- }
-}
-protected void setSimulationPlan() {
- if (!isSensitivity()){
+
+ // simulation plan
fieldSimulUseSimulationPlan.setSelected(simulAction.getSimulationParameter().getUseSimulationPlan());
getParentContainer(SimulUI.class).getSensUI().refresh();
}
}
+
protected void setSensitivityTabRegion() {
if (isSensitivity()) {
try {
@@ -167,24 +167,19 @@
}
}
}
-protected void setFactor() {
+protected void initSensitivityParams() {
if (isSensitivity()) {
+ getParentContainer(SensitivityUI.class).getSensitivityChooserUI().refreshSelectedSensitivityAnalysis();
getParentContainer(SensitivityUI.class).getSensitivityTabUI().setFactorModel();
- }
-}
-protected void setExportSens() {
- if (isSensitivity()) {
getParentContainer(SensitivityUI.class).getSensitivityChooserUI().setSensitivityExportListModel();
+ sensitivityOnlyKeepFirstResultCheckBox.setSelected(simulAction.getSimulationParameter().isSensitivityAnalysisOnlyKeepFirst());
}
}
-protected void setSensitivityAnalysis() {
- if (isSensitivity()){
- getParentContainer(SensitivityUI.class).getSensitivityChooserUI().refreshSelectedSensitivityAnalysis();
- }
-}
+
public void setSimulationParameter(SimulAction simulAction){
simulAction.setSimulationParameter(simulAction.getSimulationParameter());
}
+
protected void loadOldSimulation() {
final String selected = fieldSimulParamsSelect.getSelectedItem().toString();
// le premier item est " " pour ne pas avoir de selection par defaut
@@ -198,11 +193,8 @@
fieldSimulParamsRegion.setSelectedItem(getContextValue(SimulAction.class).getSimulationParameter().getRegionName());
// mise a jour des années
fieldSimulParamsNbAnnees.setText(String.valueOf(simulAction.getNumberOfYear()));
- setPreScript();
- setSimulationPlan();
- setExportSens();
- setSensitivityAnalysis();
- setFactor();
+ initSimulationParams();
+ initSensitivityParams();
// regles
ruleChooser.setRulesList(simulAction.getSimulationParameter().getRules());
@@ -502,14 +494,14 @@
<cell fill="horizontal" weightx="1.0">
<Table>
<row>
- <cell fill="horizontal" weightx="0.3">
+ <cell fill="horizontal" weightx="1">
<JCheckBox text="isisfish.params.usePreSimulationScript"
id="fieldUseSimulPreScripts"
selected='{simulAction.getSimulationParameter().getUsePreScript()}'
visible='{!isSensitivity()}'
onItemStateChanged='enablePreScript()' />
</cell>
- <cell fill="horizontal" weightx="0.3">
+ <cell fill="horizontal" weightx="1">
<JCheckBox text="isisfish.params.useSimulationPlan"
id="fieldSimulUseSimulationPlan"
selected='{simulAction.getSimulationParameter().getUseSimulationPlan()}'
@@ -517,6 +509,14 @@
onItemStateChanged='enableSimulationPlan()'
enabled="{getRegionStorage() != null}" />
</cell>
+ <cell fill="horizontal" weightx="1">
+ <JCheckBox text="isisfish.params.sensitivityOnlyKeepFirstResult"
+ id="sensitivityOnlyKeepFirstResultCheckBox"
+ selected='{simulAction.getSimulationParameter().isSensitivityAnalysisOnlyKeepFirst()}'
+ visible='{isSensitivity()}'
+ onItemStateChanged='simulAction.getSimulationParameter().setSensitivityAnalysisOnlyKeepFirst(sensitivityOnlyKeepFirstResultCheckBox.isSelected())'
+ enabled="{getRegionStorage() != null}" />
+ </cell>
</row>
</Table>
</cell>
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2012-08-27 15:04:12 UTC (rev 3733)
@@ -628,6 +628,7 @@
isisfish.params.rules.availables=Available rules
isisfish.params.rules.selected=Selected rules
isisfish.params.sensitivityName=Sensitivity name
+isisfish.params.sensitivityOnlyKeepFirstResult=Only keep results for first simulation
isisfish.params.simulationLauncher=Simulation launcher
isisfish.params.simulationName=Simulation name
isisfish.params.stategiesAndPopulations=Strategies and populations
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-27 12:11:46 UTC (rev 3732)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2012-08-27 15:04:12 UTC (rev 3733)
@@ -628,6 +628,7 @@
isisfish.params.rules.availables=Règles disponibles
isisfish.params.rules.selected=Règles sélectionnées
isisfish.params.sensitivityName=Nom de l'analyse de sensibilité
+isisfish.params.sensitivityOnlyKeepFirstResult=Ne conserver les résultats que pour la première simulation.
isisfish.params.simulationLauncher=Lanceur de simulation
isisfish.params.simulationName=Nom de la simulation
isisfish.params.stategiesAndPopulations=Stratégies et populations
1
0
r3732 - in trunk: . src/main/java/fr/ifremer/isisfish
by echatellier@users.forge.codelutin.com Aug. 27, 2012
by echatellier@users.forge.codelutin.com Aug. 27, 2012
Aug. 27, 2012
Author: echatellier
Date: 2012-08-27 14:11:46 +0200 (Mon, 27 Aug 2012)
New Revision: 3732
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3732
Log:
Update next isis version.
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-25 06:38:45 UTC (rev 3731)
+++ trunk/pom.xml 2012-08-27 12:11:46 UTC (rev 3732)
@@ -11,7 +11,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.1.0.4-SNAPSHOT</version>
+ <version>4.1.1.0-SNAPSHOT</version>
<!-- POM Relationships : Inheritance : Dependencies -->
<dependencies>
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2012-08-25 06:38:45 UTC (rev 3731)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2012-08-27 12:11:46 UTC (rev 3732)
@@ -119,7 +119,7 @@
* migration de donnees demande automatiquement un changement de version
* d'application.
*/
- protected final static Version version = new Version(4, 1, 0, 3);
+ protected final static Version version = new Version(4, 1, 1, 0);
protected final static Version majorVersion = new Version(version.getNumber(0));
protected final static Version databaseVersion = new Version(
1
0
r3731 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com Aug. 25, 2012
by echatellier@users.forge.codelutin.com Aug. 25, 2012
Aug. 25, 2012
Author: echatellier
Date: 2012-08-25 08:38:45 +0200 (Sat, 25 Aug 2012)
New Revision: 3731
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3731
Log:
Fix code style
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java 2012-08-25 06:38:26 UTC (rev 3730)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java 2012-08-25 06:38:45 UTC (rev 3731)
@@ -48,9 +48,9 @@
* by : $Author$
*/
public class SimulatorStorage extends JavaSourceStorage {
-
+
public static final String SIMULATOR_PATH = "simulators";
-
+
/** Template freemarker pour les scripts. */
public static final String SIMULATOR_TEMPLATE = "templates/script/simulator.ftl";
1
0
Author: echatellier
Date: 2012-08-25 08:38:26 +0200 (Sat, 25 Aug 2012)
New Revision: 3730
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3730
Log:
Use performances improvements in nuiton matrix.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-24 12:57:23 UTC (rev 3729)
+++ trunk/pom.xml 2012-08-25 06:38:26 UTC (rev 3730)
@@ -62,14 +62,14 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix</artifactId>
- <version>2.3</version>
+ <version>2.3.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix-gui</artifactId>
- <version>2.3</version>
+ <version>2.3.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
1
0