Isis-fish-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
August 2008
- 4 participants
- 45 discussions
r1294 - in branches/isis-fish-3.1.4/src: java/fr/ifremer/isisfish java/fr/ifremer/isisfish/datastore/migration java/fr/ifremer/isisfish/entities java/fr/ifremer/isisfish/equation java/fr/ifremer/isisfish/simulator java/fr/ifremer/isisfish/ui/simulator xmi
by bpoussin@users.labs.libre-entreprise.org 12 Aug '08
by bpoussin@users.labs.libre-entreprise.org 12 Aug '08
12 Aug '08
Author: bpoussin
Date: 2008-08-12 15:23:29 +0000 (Tue, 12 Aug 2008)
New Revision: 1294
Added:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/SoVTechnicalEfficiencyEquation.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/StrategyInactivityEquation.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java
Removed:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java
Modified:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/SetOfVesselsImpl.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyImpl.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java
branches/isis-fish-3.1.4/src/xmi/isis-fish.zargo
Log:
- Implantation dans le modele des nouvelles equations
- passage de version en 3.2.0
- ajout du code pour upgrader les tables (alter table)
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -42,10 +42,9 @@
*/
public class IsisConfig extends IsisAbstractConfigMain {
- protected final static VersionNumber version = new VersionNumber(3, 1, 4);
+ protected final static VersionNumber version = new VersionNumber(3, 2, 0);
protected final static VersionNumber databaseVersion = new VersionNumber(
- 0);
-// FIXME a remettre apres les tests de simu version.getNumber(0), version.getNumber(1));
+ version.getNumber(0), version.getNumber(1));
public static VersionNumber getVersionNumber() {
return version;
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -19,6 +19,8 @@
package fr.ifremer.isisfish.datastore.migration;
import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
import javax.swing.JOptionPane;
import org.apache.commons.logging.Log;
@@ -99,19 +101,20 @@
return MigrationChoice.NO_MIGRATION; // force false during test // result;
}
- private void migrateTo3_2(Connection conn) {
+ private void migrateTo3_2(Connection conn) throws SQLException {
log.info("Migrate to version 3.2");
//alteration du schema
// nouvelles equations dans les tables
-
- // creation de valeur par defaut pour les equations
-
-
- // recuperation des valeurs de ???
-
- // creation de l'equation avec ces valeurs
-
- // sauvegarde de l'equation
+
+ String [] sqls = new String[]{
+ "alter table SETOFVESSELS add column TECHNICALEFFICIENCYEQUATION VARCHAR(255);",
+ "alter table STRATEGY add column INACTIVITYEQUATIONUSED BIT default false;",
+ "alter table STRATEGY add column INACTIVITYEQUATION VARCHAR(255);",
+ };
+ for (String sql : sqls) {
+ PreparedStatement sta = conn.prepareStatement(sql);
+ sta.executeUpdate();
+ }
}
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/SetOfVesselsImpl.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/SetOfVesselsImpl.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/SetOfVesselsImpl.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -1,10 +1,19 @@
package fr.ifremer.isisfish.entities;
+import static org.codelutin.i18n.I18n._;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
import java.io.Serializable;
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.datastore.RegionStorage;
import fr.ifremer.isisfish.datastore.StorageException;
+import fr.ifremer.isisfish.equation.Language;
+import fr.ifremer.isisfish.equation.SoVTechnicalEfficiencyEquation;
+import fr.ifremer.isisfish.types.Date;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaException;
/**
* Implantation des operations pour l'entité SetOfVessels.
@@ -13,6 +22,11 @@
private static final long serialVersionUID = 1L;
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory.getLog(SetOfVesselsImpl.class);
+
public FisheryRegion getFisheryRegion() {
try {
FisheryRegion result = RegionStorage.getFisheryRegion(getTopiaContext());
@@ -22,6 +36,68 @@
}
}
+ /**
+ * override to change name of equation
+ * @see fr.ifremer.isisfish.entities.SetOfVesselsAbstract#setName(java.lang.String)
+ */
+ @Override
+ public void setName(String value) {
+ super.setName(value);
+ Equation eq = getTechnicalEfficiencyEquation();
+ if (eq != null) {
+ eq.setName(getName());
+ }
+ }
+
+ /**
+ * Compute or return inactivity days
+ * @param length length of group
+ * @param group group
+ * @return age in month
+ */
+ @Override
+ public double getTechnicalEfficiency(Date date, Metier metier) {
+ double result = 0;
+
+ try {
+ Gear gear = metier.getGear();
+ Equation eq = getTechnicalEfficiencyEquation();
+ if (eq != null) {
+ result = eq.evaluate("date", date, "metier", metier, "gear", gear);
+ }
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Error in technical efficiency equation");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ }
+ return result;
+ }
+
+ public void setEquationTechnicalEfficiency(String content) {
+ try {
+ Equation eq = getTechnicalEfficiencyEquation();
+
+ if (eq == null) {
+ EquationDAO dao = IsisFishDAOHelper.getEquationDAO(getTopiaContext());
+ // create Growth equation
+ eq = dao.create();
+ eq.setCategory("Inactivity");
+ eq.setJavaInterface(SoVTechnicalEfficiencyEquation.class);
+ eq.setLanguage(Language.JAVA);
+ setTechnicalEfficiencyEquation(eq);
+ }
+
+ eq.setName(getName());
+ eq.setContent(content);
+ eq.update();
+ } catch (TopiaException eee) {
+ throw new IsisFishRuntimeException(_("isisfish.change.equation"), eee);
+ }
+ }
+
/* (non-Javadoc)
* @see fr.ifremer.isisfish.entities.FisheryRegionAbstract#toString()
*/
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyImpl.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyImpl.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyImpl.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -14,6 +14,8 @@
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.datastore.RegionStorage;
import fr.ifremer.isisfish.datastore.StorageException;
+import fr.ifremer.isisfish.equation.Language;
+import fr.ifremer.isisfish.equation.StrategyInactivityEquation;
import fr.ifremer.isisfish.types.Month;
/**
@@ -34,6 +36,19 @@
throw new IsisFishRuntimeException(eee);
}
}
+
+ /**
+ * override to change name of equation
+ * @see fr.ifremer.isisfish.entities.StrategyAbstract#setName(java.lang.String)
+ */
+ @Override
+ public void setName(String value) {
+ super.setName(value);
+ Equation eq = getInactivityEquation();
+ if (eq != null) {
+ eq.setName(getName());
+ }
+ }
/* (non-Javadoc)
* @see fr.ifremer.isisfish.entities.StrategyAbstract#getStrategyMonthInfo()
@@ -88,6 +103,55 @@
return result;
}
+ /**
+ * Compute or return inactivity days
+ * @param length length of group
+ * @param group group
+ * @return age in month
+ */
+ public double getInactivityDays(Month month) {
+ double result = 0;
+
+ StrategyMonthInfo info = getStrategyMonthInfo(month);
+ if (!getInactivityEquationUsed()) {
+ result = info.getMinInactivityDays();
+ } else {
+ try {
+ Equation eq = getInactivityEquation();
+ result = eq.evaluate("month", month, "info", info);
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Error in inactivityDays equation");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ }
+ }
+ return result;
+ }
+ public void setEquationInactivity(String content) {
+ try {
+ Equation eq = getInactivityEquation();
+
+ if (eq == null) {
+ EquationDAO dao = IsisFishDAOHelper.getEquationDAO(getTopiaContext());
+ // create Growth equation
+ eq = dao.create();
+ eq.setCategory("Inactivity");
+ eq.setJavaInterface(StrategyInactivityEquation.class);
+ eq.setLanguage(Language.JAVA);
+ setInactivityEquation(eq);
+ }
+
+ eq.setName(getName());
+ eq.setContent(content);
+ eq.update();
+ } catch (TopiaException eee) {
+ throw new IsisFishRuntimeException(_("isisfish.change.equation"), eee);
+ }
+ }
+
/* (non-Javadoc)
* @see fr.ifremer.isisfish.entities.StrategyAbstract#toString()
*/
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -152,7 +152,10 @@
public void computeNumberOfTrips() {
TripType tripType = getTripType();
- int inactivity = getMinInactivityDays();
+ // remplace un simple getMinInactivityDays(), pour pouvoir utiliser une
+ // equation si besoin (tout est pret, il ne manque que l'interface
+ // graphique pour saisir l'equation dans strategie
+ double inactivity = getStrategy().getInactivityDays(getMonth());
if(tripType != null && tripType.getTripDuration() != null && inactivity >= 0){
int nbDayMonth = getMonth().getNumbersOfDays();
double result = (int)((nbDayMonth - inactivity) / tripType.getTripDuration().getDay());
Added: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/SoVTechnicalEfficiencyEquation.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/SoVTechnicalEfficiencyEquation.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/SoVTechnicalEfficiencyEquation.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+package fr.ifremer.isisfish.equation;
+
+import fr.ifremer.isisfish.entities.Gear;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.util.Args;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface SoVTechnicalEfficiencyEquation {
+
+ /**
+ * @param context
+ * @param metier le metier pour lequel on demande le calcul
+ * @param gear l'engin utilise par le metier
+ * @return
+ */
+ @Args({"context", "metier", "gear"})
+ public double compute(SimulationContext context, Metier metier, Gear gear) throws Exception;
+
+}
Added: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/StrategyInactivityEquation.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/StrategyInactivityEquation.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/equation/StrategyInactivityEquation.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+package fr.ifremer.isisfish.equation;
+
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.util.Args;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface StrategyInactivityEquation {
+
+ /**
+ *
+ * @param context
+ * @param month le mois courant de simulation
+ * @param info l'objet associe a la strategie pour le mois courant
+ * @return
+ */
+ @Args({"context", "month", "info"})
+ public double compute(SimulationContext context, Month month, StrategyMonthInfo info) throws Exception;
+
+}
Deleted: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -1,372 +0,0 @@
-/* *##%
- * Copyright (C) 2006
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-/* *
- * PopulationMonitor.java
- *
- * Created: 21 août 2006 15:41:18
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package fr.ifremer.isisfish.simulator;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.collections.MapIterator;
-import org.apache.commons.collections.keyvalue.MultiKey;
-import org.apache.commons.collections.map.MultiKeyMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.math.matrix.MatrixFactory;
-import org.codelutin.math.matrix.MatrixIterator;
-import org.codelutin.math.matrix.MatrixND;
-
-import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.entities.PopulationGroup;
-import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
-import fr.ifremer.isisfish.entities.Species;
-import fr.ifremer.isisfish.entities.Zone;
-import fr.ifremer.isisfish.types.Date;
-import fr.ifremer.isisfish.types.Month;
-
-
-/**
- * Classe permettant le suivi des populations de la simulation.
- *
- * FIXME: certain calcul sont les memes que ceux implanter dans les scripts
- * a cause du groupe des juveniles qui n'est pas un vrai groupe de population.
- * Il serait bon que ce groupe deviennent un vrai groupe et que ce code specifique
- * puisse etre supprimer.
- *
- *
- * @author poussin
- */
-public class PopulationMonitor {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(PopulationMonitor.class);
-
- /** current number of fish by Pop */
- protected Map<Population, MatrixND> Ns = new HashMap<Population, MatrixND>();
- /** reproduction key: <date, pop> value:<MatrixND> */
- protected MultiKeyMap reproductions = new MultiKeyMap();
- /** discard key: <date, pop> value:<MatrixND> */
- protected MultiKeyMap discards = new MultiKeyMap();
- /** catch per population, only last catch is remaining */
- protected Map<Population, MatrixND> catchs = new HashMap<Population, MatrixND>();
- /** catch per population, only last catch is remaining */
- protected Map<Population, MatrixND> holdCatchs = new HashMap<Population, MatrixND>();
- protected double totalHoldCatch = 0;
-
- /**
- * Return all population actualy in PopulationMonitor
- * @return new list of Population
- */
- public List<Population> getPopulations() {
- ArrayList<Population> result = new ArrayList<Population>(Ns.keySet());
- return result;
- }
-
- /**
- * Return current biomass for species
- * @param species
- * @return
- */
- public double getBiomass(Species species) {
- double result = 0;
-
- for (Population pop : species.getPopulation()) {
- result += getBiomass(pop);
- }
-
- return result;
- }
-
- /**
- * Return current biomass for population
- * @param pop
- * @return
- */
- public double getBiomass(Population pop) {
- double result = 0;
-
- MatrixND n = getN(pop);
- if (n != null) {
- n = n.sumOverDim(1);
- for (MatrixIterator i=n.iterator(); i.next();){
- Object [] coord = i.getSemanticsCoordinates();
- PopulationGroup group = (PopulationGroup)coord[0];
- result += i.getValue() * group.getMeanWeight();
- }
- }
-
- return result;
- }
-
- /**
- * Return current numbers for population
- * @param pop
- * @return
- */
- public MatrixND getN(Population pop) {
- MatrixND result = Ns.get(pop);
-
- if (result != null) {
- // change semantics with list from argument to ensure that
- // semantics don't used too old context
- result.setSemantics(0, pop.getPopulationGroup());
- result.setSemantics(1, pop.getPopulationZone());
- }
-
- return result;
- }
-
- public void setN(Population pop, MatrixND mat) {
- Ns.put(pop, mat);
- }
-
- /**
- * @return Returns the reproduction.
- */
- public MatrixND getReproduction(Date date, Population pop) {
- return (MatrixND)this.reproductions.get(date, pop);
- }
-
- /**
- * @param reproduction The reproduction to set.
- */
- public void setReproduction(Date date, Population pop, MatrixND repro) {
- this.reproductions.put(date, pop, repro);
- }
-
- /**
- * Applique de la mortalite naturelle aux poissons qui sont pas encore
- * dans les classes de populations. (Reproduction)
- * @param pop
- */
- public void applyReproductionMortality(Population pop) {
- for (MapIterator i=reproductions.mapIterator(); i.hasNext();) {
- i.next();
- MultiKey key = (MultiKey)i.getKey();
- if (pop.equals(key.getKey(1))) {
- MatrixND reproduction = (MatrixND)i.getValue();
- if (log.isTraceEnabled()) {
- log.trace("Matrix repro before mortality: " + reproduction);
- }
- for(MatrixIterator mi=reproduction.iterator(); mi.next();){
- Object[] sems = mi.getSemanticsCoordinates();
- Zone z = (Zone)sems[0];
- double coeff = pop.getNaturalDeathBirth(z);
- if (log.isTraceEnabled()) {
- log.trace("NaturalDeath zone " + z + "=" + coeff);
- }
- mi.setValue(mi.getValue() * Math.exp(-coeff/Month.NUMBER_OF_MONTH));
- }
- if (log.isTraceEnabled()) {
- log.trace("Matrix repro after mortality: " + reproduction);
- }
- }
- }
- }
-
- /**
- * @todo les reproductions qui sont trop veille pour encore servir
- * doivent être supprimées. c-a-d date < currentDate - etalement - gap between repro recru
- * Une autre facon de faire est de supprimer les repro == 0 car normalement
- * toute la repro doit etre utilisé au bout d'un certain temps
- *
- * @param date
- * @param pop
- * @return
- */
- public MatrixND getRecruitment(Date date, Population pop) {
- MatrixND matEtalement = pop.getRecruitmentDistribution();
- int etalement = matEtalement.getDim(0);
-
- MatrixND result = MatrixFactory.getInstance().create(
- new List[]{pop.getPopulationGroup(), pop.getPopulationZone()});
-
- // pour chaque
- for(int e=0; e<etalement; e++){
- // recuperation de la reproduction stucture en zone repro
- Date d = new Date(date.getDate() - e -
- pop.getMonthGapBetweenReproRecrutement());
- MatrixND repro = (MatrixND)reproductions.get(d, pop);
-
- if(repro != null){ // si une repro existe pour le mois
-
- // on fait la correspondance entre les zones repro et
- // recrutement
-
- PopulationGroup classe;
- int indiceClasse = 0;
- // si on a change d'annee le recrutement ne se fait pas en
- // classe 0 mais en classe 1, si on a change 2 fois d'annee
- // le recrutement se fait en age 2, etc.
- classe = pop.getPopulationGroup().get(indiceClasse);
-
- List<Zone> zoneRepros = pop.getReproductionZone();
-
- // on multiplie la repro par le coeff de recrutement
- double coeff = matEtalement.getValue(e);
-
- MatrixND matRepro = repro.copy();
- matRepro = matRepro.mults(coeff);
-
- matRepro.setSemantics(0, zoneRepros);
-
- MatrixND mapping = pop.getMappingZoneReproZoneRecru();
- for(Zone zoneRepro : zoneRepros){
- MatrixND submapping = mapping.getSubMatrix(0, new Object[]{zoneRepro});
- for (MatrixIterator i=submapping.iterator(); i.hasNext();) {
- i.next();
- Object[] sem = i.getSemanticsCoordinates();
- Zone zoneRecru = (Zone)sem[1];
- double c = i.getValue();
- result.setValue(classe, zoneRecru, c*matRepro.getValue(zoneRepro)
- +result.getValue(classe, zoneRecru));
- }
- }
- }
- }
-
- if(pop.getSpecies().getAgeGroupType()){
- // conversion et retour de la matrice en vecteur
- MatrixND N = pop.N2DToN1D(result);
- // on applique les migrations et le changement d'age sur le resultat
- // on suppose que la reproduction est toujours dans une seul saison
- Date dateRepro = new Date(date.getDate() -
- pop.getMonthGapBetweenReproRecrutement());
-
- // recherche les saisons des differents mois entre les deux dates
- List<PopulationSeasonInfo> infos = pop.getPopulationSeasonInfo();
- List<PopulationSeasonInfo> usedSeasons = new ArrayList<PopulationSeasonInfo>();
-
- while (date.after(dateRepro)) {
- dateRepro = dateRepro.next();
- Month month = dateRepro.getMonth();
- for (PopulationSeasonInfo info : infos) {
- if (month.equals(info.getFirstMonth())) {
- usedSeasons.add(info);
- dateRepro = new Date(dateRepro.getDate() + info.getMonths().size() - 1); // -1 because, for have next()
- break;
- }
- }
- }
-
- for(PopulationSeasonInfo info : usedSeasons){
- Month month = info.getFirstMonth();
- MatrixND CA = info.getGroupChangeMatrix(month);
- MatrixND MI = info.getMigrationMatrix(month, result);
- MatrixND tmp0 = N.mult(CA);
- MatrixND tmp2 = tmp0.mult(MI);
- N = tmp2;
- }
- result = pop.split2D(N);
- }
- return result;
- }
-
- /**
- * @param catchPerStrategyMet
- */
- public void holdCatch(Population pop, MatrixND catchPerStrategyMet) {
- catchs.put(pop, catchPerStrategyMet);
-
- MatrixND holdCatch = holdCatchs.get(pop);
- if (holdCatch == null) {
- holdCatch = MatrixFactory.getInstance().create(catchPerStrategyMet);
- holdCatchs.put(pop, holdCatch);
- } else {
- holdCatch.add(catchPerStrategyMet);
- }
-
- // compute total
- for(MatrixIterator i=catchPerStrategyMet.iterator(); i.next();){
- this.totalHoldCatch += i.getValue();
- }
-
- }
-
- /**
- * @param pop
- * @return
- */
- public MatrixND getCatch(Population pop) {
- MatrixND result = catchs.get(pop);
- return result;
- }
-
- /**
- * @param pop
- * @return
- */
- public MatrixND getHoldCatch(Population pop) {
- MatrixND result = holdCatchs.get(pop);
- return result;
- }
-
- /**
- * @param pop
- * @return
- */
- public double getTotalHoldCatch(Population pop) {
- double result = totalHoldCatch;
- return result;
- }
-
- /**
- * raz capture cumulée de toutes les pops
- */
- public void clearCatch() {
- catchs.clear();
- holdCatchs.clear();
- totalHoldCatch = 0;
- }
-
- /**
- * @param date
- * @param pop
- * @return
- */
- public MatrixND getDiscard(Date date, Population pop) {
- MatrixND result = (MatrixND)discards.get(date, pop);
- return result;
- }
-
- public void addDiscard(Date date, Population pop, MatrixND discard) {
- MatrixND tmp = (MatrixND)discards.get(date, pop);
- if (tmp == null) {
- tmp = discard.copy();
- discards.put(date, pop, tmp);
- } else {
- tmp.add(discard);
- }
- }
-}
-
-
Copied: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java (from rev 1292, branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java)
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -0,0 +1,399 @@
+/* *##%
+ * Copyright (C) 2006
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * PopulationMonitor.java
+ *
+ * Created: 21 août 2006 15:41:18
+ *
+ * @author poussin
+ * @version $Revision: 428 $
+ *
+ * Last update: $Date: 2007-10-15 14:56:13 +0200 (lun, 15 oct 2007) $
+ * by : $Author: bpoussin $
+ */
+
+package fr.ifremer.isisfish.simulator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
+
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import java.util.Collections;
+
+
+/**
+ * Classe permettant le suivi des populations de la simulation.
+ * <p>
+ * Cette classe est normalement multi-thread safe
+ * <p>
+ * FIXME: certain calcul sont les memes que ceux implanter dans les scripts
+ * a cause du groupe des juveniles qui n'est pas un vrai groupe de population.
+ * Il serait bon que ce groupe deviennent un vrai groupe et que ce code specifique
+ * puisse etre supprimer.
+ *
+ *
+ * @author poussin
+ */
+public class PopulationMonitor {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(PopulationMonitor.class);
+
+ /** La liste des pops monitorer par cette instance */
+ protected List<Population> pops = null;
+ /** current number of fish by Pop */
+ protected Map<Population, MatrixND> Ns = new HashMap<Population, MatrixND>();
+ /** reproduction key: <date, pop> value:<MatrixND> */
+ protected Map<Population, Map<Date, MatrixND>> reproductions = new HashMap<Population, Map<Date, MatrixND>>();
+ /** discard key: <date, pop> value:<MatrixND> */
+ protected Map<Population, Map<Date, MatrixND>> discards = new HashMap<Population, Map<Date, MatrixND>>();
+ /** catch per population, only last catch is remaining */
+ protected Map<Population, MatrixND> catchs = new HashMap<Population, MatrixND>();
+ /** catch per population, only last catch is remaining */
+ protected Map<Population, MatrixND> holdCatchs = new HashMap<Population, MatrixND>();
+ protected double totalHoldCatch = 0;
+
+ /**
+ * Initialise le monitor pour l'ensemble de pop passe en parametre.
+ * Normalement cet init est fait dans le thread principale de la simulation
+ * et il n'y a pas de besoin de le synchroniser.
+ *
+ * Cet init permet d'avoir ensuite le maxime de variable en lecture, et donc
+ * de permettre le multithreading de facon legere (pas de synchronise) et
+ * sur (pas de concurent modification exception)
+ *
+ * @param pops
+ */
+ public void init(List<Population> pops) {
+ this.pops = Collections.unmodifiableList(new ArrayList<Population>(pops));
+ for (Population pop : this.pops) {
+ reproductions.put(pop, new HashMap<Date, MatrixND>());
+ discards.put(pop, new HashMap<Date, MatrixND>());
+ }
+ }
+
+ /**
+ * Return all population actualy in PopulationMonitor
+ * @return new list of Population
+ */
+ public List<Population> getPopulations() {
+ return pops;
+ }
+
+ /**
+ * Return current biomass for species
+ * @param species
+ * @return
+ */
+ public double getBiomass(Species species) {
+ double result = 0;
+
+ for (Population pop : species.getPopulation()) {
+ result += getBiomass(pop);
+ }
+
+ return result;
+ }
+
+ /**
+ * Return current biomass for population
+ * @param pop
+ * @return
+ */
+ public double getBiomass(Population pop) {
+ double result = 0;
+
+ MatrixND n = getN(pop);
+ if (n != null) {
+ n = n.sumOverDim(1);
+ for (MatrixIterator i=n.iterator(); i.next();){
+ Object [] coord = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)coord[0];
+ result += i.getValue() * group.getMeanWeight();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Return current numbers for population
+ * @param pop
+ * @return
+ */
+ public MatrixND getN(Population pop) {
+ MatrixND result = Ns.get(pop);
+
+ if (result != null) {
+ // change semantics with list from argument to ensure that
+ // semantics don't used too old context
+ result.setSemantics(0, pop.getPopulationGroup());
+ result.setSemantics(1, pop.getPopulationZone());
+ }
+
+ return result;
+ }
+
+ public void setN(Population pop, MatrixND mat) {
+ Ns.put(pop, mat);
+ }
+
+ /**
+ * @return Returns the reproduction.
+ */
+ public MatrixND getReproduction(Date date, Population pop) {
+ return this.reproductions.get(pop).get(date);
+ }
+
+ /**
+ * @param reproduction The reproduction to set.
+ */
+ public void setReproduction(Date date, Population pop, MatrixND repro) {
+ reproductions.get(pop).put(date, repro);
+ }
+
+ /**
+ * Applique de la mortalite naturelle aux poissons qui sont pas encore
+ * dans les classes de populations. (Reproduction)
+ * @param pop
+ */
+ public void applyReproductionMortality(Population pop) {
+ for (MatrixND reproduction : reproductions.get(pop).values()) {
+ if (log.isTraceEnabled()) {
+ log.trace("Matrix repro before mortality: " + reproduction);
+ }
+
+ for (MatrixIterator mi = reproduction.iterator(); mi.next();) {
+ Object[] sems = mi.getSemanticsCoordinates();
+ Zone z = (Zone) sems[0];
+ double coeff = pop.getNaturalDeathBirth(z);
+ if (log.isTraceEnabled()) {
+ log.trace("NaturalDeath zone " + z + "=" + coeff);
+ }
+ mi.setValue(mi.getValue() * Math.exp(-coeff / Month.NUMBER_OF_MONTH));
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("Matrix repro after mortality: " + reproduction);
+ }
+ }
+ }
+
+ /**
+ * @todo les reproductions qui sont trop veille pour encore servir
+ * doivent être supprimées. c-a-d date < currentDate - etalement - gap between repro recru
+ * Une autre facon de faire est de supprimer les repro == 0 car normalement
+ * toute la repro doit etre utilisé au bout d'un certain temps
+ *
+ * @param date
+ * @param pop
+ * @return
+ */
+ public MatrixND getRecruitment(Date date, Population pop) {
+ MatrixND matEtalement = pop.getRecruitmentDistribution();
+ int etalement = matEtalement.getDim(0);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ new List[]{pop.getPopulationGroup(), pop.getPopulationZone()});
+
+ // pour chaque
+ for(int e=0; e<etalement; e++){
+ // recuperation de la reproduction stucture en zone repro
+ Date d = new Date(date.getDate() - e -
+ pop.getMonthGapBetweenReproRecrutement());
+ MatrixND repro = (MatrixND)reproductions.get(pop).get(d);
+
+ if(repro != null){ // si une repro existe pour le mois
+
+ // on fait la correspondance entre les zones repro et
+ // recrutement
+
+ PopulationGroup classe;
+ int indiceClasse = 0;
+ // si on a change d'annee le recrutement ne se fait pas en
+ // classe 0 mais en classe 1, si on a change 2 fois d'annee
+ // le recrutement se fait en age 2, etc.
+ classe = pop.getPopulationGroup().get(indiceClasse);
+
+ List<Zone> zoneRepros = pop.getReproductionZone();
+
+ // on multiplie la repro par le coeff de recrutement
+ double coeff = matEtalement.getValue(e);
+
+ MatrixND matRepro = repro.copy();
+ matRepro = matRepro.mults(coeff);
+
+ matRepro.setSemantics(0, zoneRepros);
+
+ MatrixND mapping = pop.getMappingZoneReproZoneRecru();
+ for(Zone zoneRepro : zoneRepros){
+ MatrixND submapping = mapping.getSubMatrix(0, new Object[]{zoneRepro});
+ for (MatrixIterator i=submapping.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sem = i.getSemanticsCoordinates();
+ Zone zoneRecru = (Zone)sem[1];
+ double c = i.getValue();
+ result.setValue(classe, zoneRecru, c*matRepro.getValue(zoneRepro)
+ +result.getValue(classe, zoneRecru));
+ }
+ }
+ }
+ }
+
+ if(pop.getSpecies().getAgeGroupType()){
+ // conversion et retour de la matrice en vecteur
+ MatrixND N = pop.N2DToN1D(result);
+ // on applique les migrations et le changement d'age sur le resultat
+ // on suppose que la reproduction est toujours dans une seul saison
+ Date dateRepro = new Date(date.getDate() -
+ pop.getMonthGapBetweenReproRecrutement());
+
+ // recherche les saisons des differents mois entre les deux dates
+ List<PopulationSeasonInfo> infos = pop.getPopulationSeasonInfo();
+ List<PopulationSeasonInfo> usedSeasons = new ArrayList<PopulationSeasonInfo>();
+
+ while (date.after(dateRepro)) {
+ dateRepro = dateRepro.next();
+ Month month = dateRepro.getMonth();
+ for (PopulationSeasonInfo info : infos) {
+ if (month.equals(info.getFirstMonth())) {
+ usedSeasons.add(info);
+ dateRepro = new Date(dateRepro.getDate() + info.getMonths().size() - 1); // -1 because, for have next()
+ break;
+ }
+ }
+ }
+
+ for(PopulationSeasonInfo info : usedSeasons){
+ Month month = info.getFirstMonth();
+ MatrixND CA = info.getGroupChangeMatrix(month);
+ MatrixND MI = info.getMigrationMatrix(month, result);
+ MatrixND tmp0 = N.mult(CA);
+ MatrixND tmp2 = tmp0.mult(MI);
+ N = tmp2;
+ }
+ result = pop.split2D(N);
+ }
+ return result;
+ }
+
+ /**
+ * @param catchPerStrategyMet
+ */
+ public void holdCatch(Population pop, MatrixND catchPerStrategyMet) {
+ catchs.put(pop, catchPerStrategyMet);
+
+ MatrixND holdCatch = holdCatchs.get(pop);
+ if (holdCatch == null) {
+ holdCatch = MatrixFactory.getInstance().create(catchPerStrategyMet);
+ holdCatchs.put(pop, holdCatch);
+ } else {
+ holdCatch.add(catchPerStrategyMet);
+ }
+
+ // compute total
+ for(MatrixIterator i=catchPerStrategyMet.iterator(); i.next();){
+ this.totalHoldCatch += i.getValue();
+ }
+
+ }
+
+ /**
+ * @param pop
+ * @return
+ */
+ public MatrixND getCatch(Population pop) {
+ MatrixND result = catchs.get(pop);
+ return result;
+ }
+
+ /**
+ * @param pop
+ * @return
+ */
+ public MatrixND getHoldCatch(Population pop) {
+ MatrixND result = holdCatchs.get(pop);
+ return result;
+ }
+
+ /**
+ * @param pop
+ * @return
+ */
+ public double getTotalHoldCatch(Population pop) {
+ double result = totalHoldCatch;
+ return result;
+ }
+
+ /**
+ * raz capture cumulée de toutes les pops
+ */
+ public void clearCatch() {
+ catchs.clear();
+ holdCatchs.clear();
+ totalHoldCatch = 0;
+ }
+
+ /**
+ * @param date
+ * @param pop
+ * @return
+ */
+ public MatrixND getDiscard(Date date, Population pop) {
+ MatrixND result = discards.get(pop).get(date);
+ return result;
+ }
+
+ /**
+ * FIXME: discards n'est jamais vider, on le conserve pour toutes les annees
+ * il serait bon de faire un peu le menage de temps en temps.
+ *
+ * @param date
+ * @param pop
+ * @param discard
+ */
+ public void addDiscard(Date date, Population pop, MatrixND discard) {
+ Map<Date, MatrixND> oneDiscard = discards.get(pop);
+ synchronized(oneDiscard) {
+ MatrixND tmp = oneDiscard.get(date);
+ if (tmp == null) {
+ tmp = discard.copy();
+ discards.get(pop).put(date, tmp);
+ } else {
+ tmp.add(discard);
+ }
+ }
+ }
+}
+
+
Deleted: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -1,399 +0,0 @@
-/* *##%
- * Copyright (C) 2006
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-/* *
- * PopulationMonitor.java
- *
- * Created: 21 août 2006 15:41:18
- *
- * @author poussin
- * @version $Revision: 428 $
- *
- * Last update: $Date: 2007-10-15 14:56:13 +0200 (lun, 15 oct 2007) $
- * by : $Author: bpoussin $
- */
-
-package fr.ifremer.isisfish.simulator;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.math.matrix.MatrixFactory;
-import org.codelutin.math.matrix.MatrixIterator;
-import org.codelutin.math.matrix.MatrixND;
-
-import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.entities.PopulationGroup;
-import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
-import fr.ifremer.isisfish.entities.Species;
-import fr.ifremer.isisfish.entities.Zone;
-import fr.ifremer.isisfish.types.Date;
-import fr.ifremer.isisfish.types.Month;
-import java.util.Collections;
-
-
-/**
- * Classe permettant le suivi des populations de la simulation.
- * <p>
- * Cette classe est normalement multi-thread safe
- * <p>
- * FIXME: certain calcul sont les memes que ceux implanter dans les scripts
- * a cause du groupe des juveniles qui n'est pas un vrai groupe de population.
- * Il serait bon que ce groupe deviennent un vrai groupe et que ce code specifique
- * puisse etre supprimer.
- *
- *
- * @author poussin
- */
-public class PopulationMonitorMultiThread {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(PopulationMonitorMultiThread.class);
-
- /** La liste des pops monitorer par cette instance */
- protected List<Population> pops = null;
- /** current number of fish by Pop */
- protected Map<Population, MatrixND> Ns = new HashMap<Population, MatrixND>();
- /** reproduction key: <date, pop> value:<MatrixND> */
- protected Map<Population, Map<Date, MatrixND>> reproductions = new HashMap<Population, Map<Date, MatrixND>>();
- /** discard key: <date, pop> value:<MatrixND> */
- protected Map<Population, Map<Date, MatrixND>> discards = new HashMap<Population, Map<Date, MatrixND>>();
- /** catch per population, only last catch is remaining */
- protected Map<Population, MatrixND> catchs = new HashMap<Population, MatrixND>();
- /** catch per population, only last catch is remaining */
- protected Map<Population, MatrixND> holdCatchs = new HashMap<Population, MatrixND>();
- protected double totalHoldCatch = 0;
-
- /**
- * Initialise le monitor pour l'ensemble de pop passe en parametre.
- * Normalement cet init est fait dans le thread principale de la simulation
- * et il n'y a pas de besoin de le synchroniser.
- *
- * Cet init permet d'avoir ensuite le maxime de variable en lecture, et donc
- * de permettre le multithreading de facon legere (pas de synchronise) et
- * sur (pas de concurent modification exception)
- *
- * @param pops
- */
- public void init(List<Population> pops) {
- this.pops = Collections.unmodifiableList(new ArrayList<Population>(pops));
- for (Population pop : this.pops) {
- reproductions.put(pop, new HashMap<Date, MatrixND>());
- discards.put(pop, new HashMap<Date, MatrixND>());
- }
- }
-
- /**
- * Return all population actualy in PopulationMonitor
- * @return new list of Population
- */
- public List<Population> getPopulations() {
- return pops;
- }
-
- /**
- * Return current biomass for species
- * @param species
- * @return
- */
- public double getBiomass(Species species) {
- double result = 0;
-
- for (Population pop : species.getPopulation()) {
- result += getBiomass(pop);
- }
-
- return result;
- }
-
- /**
- * Return current biomass for population
- * @param pop
- * @return
- */
- public double getBiomass(Population pop) {
- double result = 0;
-
- MatrixND n = getN(pop);
- if (n != null) {
- n = n.sumOverDim(1);
- for (MatrixIterator i=n.iterator(); i.next();){
- Object [] coord = i.getSemanticsCoordinates();
- PopulationGroup group = (PopulationGroup)coord[0];
- result += i.getValue() * group.getMeanWeight();
- }
- }
-
- return result;
- }
-
- /**
- * Return current numbers for population
- * @param pop
- * @return
- */
- public MatrixND getN(Population pop) {
- MatrixND result = Ns.get(pop);
-
- if (result != null) {
- // change semantics with list from argument to ensure that
- // semantics don't used too old context
- result.setSemantics(0, pop.getPopulationGroup());
- result.setSemantics(1, pop.getPopulationZone());
- }
-
- return result;
- }
-
- public void setN(Population pop, MatrixND mat) {
- Ns.put(pop, mat);
- }
-
- /**
- * @return Returns the reproduction.
- */
- public MatrixND getReproduction(Date date, Population pop) {
- return this.reproductions.get(pop).get(date);
- }
-
- /**
- * @param reproduction The reproduction to set.
- */
- public void setReproduction(Date date, Population pop, MatrixND repro) {
- reproductions.get(pop).put(date, repro);
- }
-
- /**
- * Applique de la mortalite naturelle aux poissons qui sont pas encore
- * dans les classes de populations. (Reproduction)
- * @param pop
- */
- public void applyReproductionMortality(Population pop) {
- for (MatrixND reproduction : reproductions.get(pop).values()) {
- if (log.isTraceEnabled()) {
- log.trace("Matrix repro before mortality: " + reproduction);
- }
-
- for (MatrixIterator mi = reproduction.iterator(); mi.next();) {
- Object[] sems = mi.getSemanticsCoordinates();
- Zone z = (Zone) sems[0];
- double coeff = pop.getNaturalDeathBirth(z);
- if (log.isTraceEnabled()) {
- log.trace("NaturalDeath zone " + z + "=" + coeff);
- }
- mi.setValue(mi.getValue() * Math.exp(-coeff / Month.NUMBER_OF_MONTH));
- }
- if (log.isTraceEnabled()) {
- log.trace("Matrix repro after mortality: " + reproduction);
- }
- }
- }
-
- /**
- * @todo les reproductions qui sont trop veille pour encore servir
- * doivent être supprimées. c-a-d date < currentDate - etalement - gap between repro recru
- * Une autre facon de faire est de supprimer les repro == 0 car normalement
- * toute la repro doit etre utilisé au bout d'un certain temps
- *
- * @param date
- * @param pop
- * @return
- */
- public MatrixND getRecruitment(Date date, Population pop) {
- MatrixND matEtalement = pop.getRecruitmentDistribution();
- int etalement = matEtalement.getDim(0);
-
- MatrixND result = MatrixFactory.getInstance().create(
- new List[]{pop.getPopulationGroup(), pop.getPopulationZone()});
-
- // pour chaque
- for(int e=0; e<etalement; e++){
- // recuperation de la reproduction stucture en zone repro
- Date d = new Date(date.getDate() - e -
- pop.getMonthGapBetweenReproRecrutement());
- MatrixND repro = (MatrixND)reproductions.get(pop).get(d);
-
- if(repro != null){ // si une repro existe pour le mois
-
- // on fait la correspondance entre les zones repro et
- // recrutement
-
- PopulationGroup classe;
- int indiceClasse = 0;
- // si on a change d'annee le recrutement ne se fait pas en
- // classe 0 mais en classe 1, si on a change 2 fois d'annee
- // le recrutement se fait en age 2, etc.
- classe = pop.getPopulationGroup().get(indiceClasse);
-
- List<Zone> zoneRepros = pop.getReproductionZone();
-
- // on multiplie la repro par le coeff de recrutement
- double coeff = matEtalement.getValue(e);
-
- MatrixND matRepro = repro.copy();
- matRepro = matRepro.mults(coeff);
-
- matRepro.setSemantics(0, zoneRepros);
-
- MatrixND mapping = pop.getMappingZoneReproZoneRecru();
- for(Zone zoneRepro : zoneRepros){
- MatrixND submapping = mapping.getSubMatrix(0, new Object[]{zoneRepro});
- for (MatrixIterator i=submapping.iterator(); i.hasNext();) {
- i.next();
- Object[] sem = i.getSemanticsCoordinates();
- Zone zoneRecru = (Zone)sem[1];
- double c = i.getValue();
- result.setValue(classe, zoneRecru, c*matRepro.getValue(zoneRepro)
- +result.getValue(classe, zoneRecru));
- }
- }
- }
- }
-
- if(pop.getSpecies().getAgeGroupType()){
- // conversion et retour de la matrice en vecteur
- MatrixND N = pop.N2DToN1D(result);
- // on applique les migrations et le changement d'age sur le resultat
- // on suppose que la reproduction est toujours dans une seul saison
- Date dateRepro = new Date(date.getDate() -
- pop.getMonthGapBetweenReproRecrutement());
-
- // recherche les saisons des differents mois entre les deux dates
- List<PopulationSeasonInfo> infos = pop.getPopulationSeasonInfo();
- List<PopulationSeasonInfo> usedSeasons = new ArrayList<PopulationSeasonInfo>();
-
- while (date.after(dateRepro)) {
- dateRepro = dateRepro.next();
- Month month = dateRepro.getMonth();
- for (PopulationSeasonInfo info : infos) {
- if (month.equals(info.getFirstMonth())) {
- usedSeasons.add(info);
- dateRepro = new Date(dateRepro.getDate() + info.getMonths().size() - 1); // -1 because, for have next()
- break;
- }
- }
- }
-
- for(PopulationSeasonInfo info : usedSeasons){
- Month month = info.getFirstMonth();
- MatrixND CA = info.getGroupChangeMatrix(month);
- MatrixND MI = info.getMigrationMatrix(month, result);
- MatrixND tmp0 = N.mult(CA);
- MatrixND tmp2 = tmp0.mult(MI);
- N = tmp2;
- }
- result = pop.split2D(N);
- }
- return result;
- }
-
- /**
- * @param catchPerStrategyMet
- */
- public void holdCatch(Population pop, MatrixND catchPerStrategyMet) {
- catchs.put(pop, catchPerStrategyMet);
-
- MatrixND holdCatch = holdCatchs.get(pop);
- if (holdCatch == null) {
- holdCatch = MatrixFactory.getInstance().create(catchPerStrategyMet);
- holdCatchs.put(pop, holdCatch);
- } else {
- holdCatch.add(catchPerStrategyMet);
- }
-
- // compute total
- for(MatrixIterator i=catchPerStrategyMet.iterator(); i.next();){
- this.totalHoldCatch += i.getValue();
- }
-
- }
-
- /**
- * @param pop
- * @return
- */
- public MatrixND getCatch(Population pop) {
- MatrixND result = catchs.get(pop);
- return result;
- }
-
- /**
- * @param pop
- * @return
- */
- public MatrixND getHoldCatch(Population pop) {
- MatrixND result = holdCatchs.get(pop);
- return result;
- }
-
- /**
- * @param pop
- * @return
- */
- public double getTotalHoldCatch(Population pop) {
- double result = totalHoldCatch;
- return result;
- }
-
- /**
- * raz capture cumulée de toutes les pops
- */
- public void clearCatch() {
- catchs.clear();
- holdCatchs.clear();
- totalHoldCatch = 0;
- }
-
- /**
- * @param date
- * @param pop
- * @return
- */
- public MatrixND getDiscard(Date date, Population pop) {
- MatrixND result = discards.get(pop).get(date);
- return result;
- }
-
- /**
- * FIXME: discards n'est jamais vider, on le conserve pour toutes les annees
- * il serait bon de faire un peu le menage de temps en temps.
- *
- * @param date
- * @param pop
- * @param discard
- */
- public void addDiscard(Date date, Population pop, MatrixND discard) {
- Map<Date, MatrixND> oneDiscard = discards.get(pop);
- synchronized(oneDiscard) {
- MatrixND tmp = oneDiscard.get(date);
- if (tmp == null) {
- tmp = discard.copy();
- discards.get(pop).put(date, tmp);
- } else {
- tmp.add(discard);
- }
- }
- }
-}
-
-
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -67,7 +67,7 @@
static protected SimulationManager instance = null;
-// protected boolean autoLaunch = false;
+ protected boolean autoLaunch = false;
protected ListenerSet<SimulationQueueListener> listeners = new ListenerSet<SimulationQueueListener>();
protected PropertyChangeSupport propertyListeners = new PropertyChangeSupport(this);
@@ -122,12 +122,12 @@
}
-// /**
-// * @return Returns the autoLaunch.
-// */
-// public boolean isAutoLaunch() {
-// return this.autoLaunch;
-// }
+ /**
+ * @return Returns the autoLaunch.
+ */
+ public boolean isAutoLaunch() {
+ return this.autoLaunch;
+ }
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyListeners.addPropertyChangeListener(listener);
@@ -145,15 +145,32 @@
propertyListeners.removePropertyChangeListener(propertyName, listener);
}
-// /**
-// * @param autoLaunch The autoLaunch to set.
-// */
-// public void setAutoLaunch(boolean autoLaunch) {
-// boolean oldValue = this.autoLaunch;
-// this.autoLaunch = autoLaunch;
-// propertyListeners.firePropertyChange("autoLaunch", oldValue, autoLaunch);
-// }
+ /**
+ * @param autoLaunch The autoLaunch to set.
+ */
+ public void setAutoLaunch(boolean autoLaunch) {
+ synchronized (this) {
+ boolean oldValue = this.autoLaunch;
+ this.autoLaunch = autoLaunch;
+ if (this.autoLaunch) {
+ this.notifyAll();
+ }
+ propertyListeners.firePropertyChange("autoLaunch", oldValue, autoLaunch);
+ }
+ }
+ public void waitAutoLaunch() {
+ synchronized(this) {
+ while (!isAutoLaunch()) {
+ try {
+ this.wait();
+ } catch (InterruptedException eee) {
+ log.warn("Error during wait autoLaunch flag", eee);
+ }
+ }
+ }
+ }
+
/**
* Cree l'objet de gestion de la simulation en interne et le place dans la
* bonne queue de simulation (local/remote). Appel le
@@ -632,6 +649,7 @@
}
public void run() {
+ simulationManager.waitAutoLaunch();
// l'item est independant, on ajoute toutes ces simulations en plus
// mais pas dans la map pour qu'il n'y ait bien que l'initiale
// plus celles en cours d'affichees
@@ -671,6 +689,7 @@
}
public void run() {
+ simulationManager.waitAutoLaunch();
try {
// si l'simItem exist encore (que l'utilisateur ne la pas retire)
while (simulationManager.exists(simItem.getPlanIdOrId()) &&
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java 2008-08-12 15:23:26 UTC (rev 1293)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java 2008-08-12 15:23:29 UTC (rev 1294)
@@ -115,10 +115,8 @@
* <code>false</code> otherwise
*/
public static boolean isSimulStartButtonEnabled(JTable table) {
- return false;
- // L'auto launche a disparu maintenant
-// return !SimulationManager.getInstance().isAutoLaunch() &&
-// (table.getRowCount() > 0);
+ return !SimulationManager.getInstance().isAutoLaunch() &&
+ (table.getRowCount() > 0);
}
/**
Modified: branches/isis-fish-3.1.4/src/xmi/isis-fish.zargo
===================================================================
(Binary files differ)
1
0
r1293 - branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities
by bpoussin@users.labs.libre-entreprise.org 12 Aug '08
by bpoussin@users.labs.libre-entreprise.org 12 Aug '08
12 Aug '08
Author: bpoussin
Date: 2008-08-12 15:23:26 +0000 (Tue, 12 Aug 2008)
New Revision: 1293
Removed:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/entities/migration/
Log:
- Implantation dans le modele des nouvelles equations
- passage de version en 3.2.0
- ajout du code pour upgrader les tables (alter table)
1
0
r1292 - in branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish: . datastore logging simulator versionning
by bpoussin@users.labs.libre-entreprise.org 11 Aug '08
by bpoussin@users.labs.libre-entreprise.org 11 Aug '08
11 Aug '08
Author: bpoussin
Date: 2008-08-11 14:36:27 +0000 (Mon, 11 Aug 2008)
New Revision: 1292
Added:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/versionning/DummyVCSHandler.java
Modified:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisContext.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisFish.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java
Log:
debut de debbugage de la refonte du lanceur de simulation.
- SimulationLogUtil ne semble pas multi-thread support (plusieurs simulation simultanement)
- ajout d'un DummyVCSHandler si le reseau est unreacheable
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -44,16 +44,22 @@
protected final static VersionNumber version = new VersionNumber(3, 1, 4);
protected final static VersionNumber databaseVersion = new VersionNumber(
- version.getNumber(0), version.getNumber(1));
+ 0);
+// FIXME a remettre apres les tests de simu version.getNumber(0), version.getNumber(1));
+ public static VersionNumber getVersionNumber() {
+ return version;
+ }
+
static public String getVERSION() {
- String result = getVersion().toString();
+ String result = version.toString();
return result;
}
- static public VersionNumber getVersion() {
- return version;
- }
+// @Override
+// public VersionNumber getVersion() {
+// return version;
+// }
public static VersionNumber getDatabaseVersion() {
return databaseVersion;
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisContext.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisContext.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisContext.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -21,6 +21,7 @@
import fr.ifremer.isisfish.commandline.IsisAbstractContext;
import fr.ifremer.isisfish.commandline.IsisOptionParser;
import fr.ifremer.isisfish.datastore.IsisH2Config;
+import fr.ifremer.isisfish.versionning.DummyVCSHandler;
import fr.ifremer.isisfish.versionning.IsisVcsConfig;
import org.codelutin.i18n.I18n;
import org.codelutin.option.OptionKey;
@@ -209,6 +210,10 @@
}
public VCSHandler getVCSHanler() {
+ if (handler == null) {
+ // handler not initializer, we used dummy handler
+ handler = new DummyVCSHandler();
+ }
return handler;
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisFish.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisFish.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisFish.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -105,7 +105,7 @@
StringBuilder builder = new StringBuilder();
builder.append(java.text.SimpleDateFormat.getInstance().format(new java.util.Date()));
builder.append(" Java version: ").append(System.getProperty("java.runtime.version"));
- builder.append(" Isis-fish version: ").append(IsisConfig.VERSION_PROPERTY_KEY.getDefaultValue().toString());
+ builder.append(" Isis-fish version: ").append(IsisConfig.getVERSION());
log.info(builder.toString());
log.debug(_("isisfish.launch.debugMode"));
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -75,7 +75,7 @@
* @param directory le repertoire ou devrait se trouver la classe. Ce
* répertoire doit etre un sous répertoire de rootSrc
* @param name le nom de la classe
- * @param suffix TODO
+ * @param suffix l'extension des fichiers
*/
protected CodeSourceStorage(File rootSrc, File directory, String name, String suffix) {
// if name end with suffix we don't add suffix to filename
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -42,6 +42,7 @@
import org.apache.commons.logging.LogFactory;
import java.io.File;
+import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -260,10 +261,15 @@
static public List<String> getStorageNames(File directory) {
List<String> result = new ArrayList<String>();
- if (directory.exists()) {
- Collections.addAll(result, directory.list(getVCSHanler().getVersionnableFilenameFilter()));
+ try {
+ if (directory.exists()) {
+ FilenameFilter filter = getVCSHanler().getVersionnableFilenameFilter();
+ String[] list = directory.list(filter);
+ Collections.addAll(result, list);
+ }
+ } catch (Exception eee) {
+ log.error("Can't get list file for " + directory, eee);
}
-
Collections.sort(result);
return result;
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -39,6 +39,10 @@
import java.util.Map;
/**
+ * FIXME poussin, a priori cette classe ne supporte pas plusieurs simulation
+ * en meme temps, ce qui est le cas si on a plusieurs processeurs de dispo :(
+ *
+ *
* Usefull class for dealing with hot configuration of log4J. this is temporary
* we must find a way to abstract this layer.
* <p/>
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -55,6 +55,13 @@
/**
+ * Classe permettant le suivi des populations de la simulation.
+ *
+ * FIXME: certain calcul sont les memes que ceux implanter dans les scripts
+ * a cause du groupe des juveniles qui n'est pas un vrai groupe de population.
+ * Il serait bon que ce groupe deviennent un vrai groupe et que ce code specifique
+ * puisse etre supprimer.
+ *
*
* @author poussin
*/
Added: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/PopulationMonitorMultiThread.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -0,0 +1,399 @@
+/* *##%
+ * Copyright (C) 2006
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * PopulationMonitor.java
+ *
+ * Created: 21 août 2006 15:41:18
+ *
+ * @author poussin
+ * @version $Revision: 428 $
+ *
+ * Last update: $Date: 2007-10-15 14:56:13 +0200 (lun, 15 oct 2007) $
+ * by : $Author: bpoussin $
+ */
+
+package fr.ifremer.isisfish.simulator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
+
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import java.util.Collections;
+
+
+/**
+ * Classe permettant le suivi des populations de la simulation.
+ * <p>
+ * Cette classe est normalement multi-thread safe
+ * <p>
+ * FIXME: certain calcul sont les memes que ceux implanter dans les scripts
+ * a cause du groupe des juveniles qui n'est pas un vrai groupe de population.
+ * Il serait bon que ce groupe deviennent un vrai groupe et que ce code specifique
+ * puisse etre supprimer.
+ *
+ *
+ * @author poussin
+ */
+public class PopulationMonitorMultiThread {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(PopulationMonitorMultiThread.class);
+
+ /** La liste des pops monitorer par cette instance */
+ protected List<Population> pops = null;
+ /** current number of fish by Pop */
+ protected Map<Population, MatrixND> Ns = new HashMap<Population, MatrixND>();
+ /** reproduction key: <date, pop> value:<MatrixND> */
+ protected Map<Population, Map<Date, MatrixND>> reproductions = new HashMap<Population, Map<Date, MatrixND>>();
+ /** discard key: <date, pop> value:<MatrixND> */
+ protected Map<Population, Map<Date, MatrixND>> discards = new HashMap<Population, Map<Date, MatrixND>>();
+ /** catch per population, only last catch is remaining */
+ protected Map<Population, MatrixND> catchs = new HashMap<Population, MatrixND>();
+ /** catch per population, only last catch is remaining */
+ protected Map<Population, MatrixND> holdCatchs = new HashMap<Population, MatrixND>();
+ protected double totalHoldCatch = 0;
+
+ /**
+ * Initialise le monitor pour l'ensemble de pop passe en parametre.
+ * Normalement cet init est fait dans le thread principale de la simulation
+ * et il n'y a pas de besoin de le synchroniser.
+ *
+ * Cet init permet d'avoir ensuite le maxime de variable en lecture, et donc
+ * de permettre le multithreading de facon legere (pas de synchronise) et
+ * sur (pas de concurent modification exception)
+ *
+ * @param pops
+ */
+ public void init(List<Population> pops) {
+ this.pops = Collections.unmodifiableList(new ArrayList<Population>(pops));
+ for (Population pop : this.pops) {
+ reproductions.put(pop, new HashMap<Date, MatrixND>());
+ discards.put(pop, new HashMap<Date, MatrixND>());
+ }
+ }
+
+ /**
+ * Return all population actualy in PopulationMonitor
+ * @return new list of Population
+ */
+ public List<Population> getPopulations() {
+ return pops;
+ }
+
+ /**
+ * Return current biomass for species
+ * @param species
+ * @return
+ */
+ public double getBiomass(Species species) {
+ double result = 0;
+
+ for (Population pop : species.getPopulation()) {
+ result += getBiomass(pop);
+ }
+
+ return result;
+ }
+
+ /**
+ * Return current biomass for population
+ * @param pop
+ * @return
+ */
+ public double getBiomass(Population pop) {
+ double result = 0;
+
+ MatrixND n = getN(pop);
+ if (n != null) {
+ n = n.sumOverDim(1);
+ for (MatrixIterator i=n.iterator(); i.next();){
+ Object [] coord = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)coord[0];
+ result += i.getValue() * group.getMeanWeight();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Return current numbers for population
+ * @param pop
+ * @return
+ */
+ public MatrixND getN(Population pop) {
+ MatrixND result = Ns.get(pop);
+
+ if (result != null) {
+ // change semantics with list from argument to ensure that
+ // semantics don't used too old context
+ result.setSemantics(0, pop.getPopulationGroup());
+ result.setSemantics(1, pop.getPopulationZone());
+ }
+
+ return result;
+ }
+
+ public void setN(Population pop, MatrixND mat) {
+ Ns.put(pop, mat);
+ }
+
+ /**
+ * @return Returns the reproduction.
+ */
+ public MatrixND getReproduction(Date date, Population pop) {
+ return this.reproductions.get(pop).get(date);
+ }
+
+ /**
+ * @param reproduction The reproduction to set.
+ */
+ public void setReproduction(Date date, Population pop, MatrixND repro) {
+ reproductions.get(pop).put(date, repro);
+ }
+
+ /**
+ * Applique de la mortalite naturelle aux poissons qui sont pas encore
+ * dans les classes de populations. (Reproduction)
+ * @param pop
+ */
+ public void applyReproductionMortality(Population pop) {
+ for (MatrixND reproduction : reproductions.get(pop).values()) {
+ if (log.isTraceEnabled()) {
+ log.trace("Matrix repro before mortality: " + reproduction);
+ }
+
+ for (MatrixIterator mi = reproduction.iterator(); mi.next();) {
+ Object[] sems = mi.getSemanticsCoordinates();
+ Zone z = (Zone) sems[0];
+ double coeff = pop.getNaturalDeathBirth(z);
+ if (log.isTraceEnabled()) {
+ log.trace("NaturalDeath zone " + z + "=" + coeff);
+ }
+ mi.setValue(mi.getValue() * Math.exp(-coeff / Month.NUMBER_OF_MONTH));
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("Matrix repro after mortality: " + reproduction);
+ }
+ }
+ }
+
+ /**
+ * @todo les reproductions qui sont trop veille pour encore servir
+ * doivent être supprimées. c-a-d date < currentDate - etalement - gap between repro recru
+ * Une autre facon de faire est de supprimer les repro == 0 car normalement
+ * toute la repro doit etre utilisé au bout d'un certain temps
+ *
+ * @param date
+ * @param pop
+ * @return
+ */
+ public MatrixND getRecruitment(Date date, Population pop) {
+ MatrixND matEtalement = pop.getRecruitmentDistribution();
+ int etalement = matEtalement.getDim(0);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ new List[]{pop.getPopulationGroup(), pop.getPopulationZone()});
+
+ // pour chaque
+ for(int e=0; e<etalement; e++){
+ // recuperation de la reproduction stucture en zone repro
+ Date d = new Date(date.getDate() - e -
+ pop.getMonthGapBetweenReproRecrutement());
+ MatrixND repro = (MatrixND)reproductions.get(pop).get(d);
+
+ if(repro != null){ // si une repro existe pour le mois
+
+ // on fait la correspondance entre les zones repro et
+ // recrutement
+
+ PopulationGroup classe;
+ int indiceClasse = 0;
+ // si on a change d'annee le recrutement ne se fait pas en
+ // classe 0 mais en classe 1, si on a change 2 fois d'annee
+ // le recrutement se fait en age 2, etc.
+ classe = pop.getPopulationGroup().get(indiceClasse);
+
+ List<Zone> zoneRepros = pop.getReproductionZone();
+
+ // on multiplie la repro par le coeff de recrutement
+ double coeff = matEtalement.getValue(e);
+
+ MatrixND matRepro = repro.copy();
+ matRepro = matRepro.mults(coeff);
+
+ matRepro.setSemantics(0, zoneRepros);
+
+ MatrixND mapping = pop.getMappingZoneReproZoneRecru();
+ for(Zone zoneRepro : zoneRepros){
+ MatrixND submapping = mapping.getSubMatrix(0, new Object[]{zoneRepro});
+ for (MatrixIterator i=submapping.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sem = i.getSemanticsCoordinates();
+ Zone zoneRecru = (Zone)sem[1];
+ double c = i.getValue();
+ result.setValue(classe, zoneRecru, c*matRepro.getValue(zoneRepro)
+ +result.getValue(classe, zoneRecru));
+ }
+ }
+ }
+ }
+
+ if(pop.getSpecies().getAgeGroupType()){
+ // conversion et retour de la matrice en vecteur
+ MatrixND N = pop.N2DToN1D(result);
+ // on applique les migrations et le changement d'age sur le resultat
+ // on suppose que la reproduction est toujours dans une seul saison
+ Date dateRepro = new Date(date.getDate() -
+ pop.getMonthGapBetweenReproRecrutement());
+
+ // recherche les saisons des differents mois entre les deux dates
+ List<PopulationSeasonInfo> infos = pop.getPopulationSeasonInfo();
+ List<PopulationSeasonInfo> usedSeasons = new ArrayList<PopulationSeasonInfo>();
+
+ while (date.after(dateRepro)) {
+ dateRepro = dateRepro.next();
+ Month month = dateRepro.getMonth();
+ for (PopulationSeasonInfo info : infos) {
+ if (month.equals(info.getFirstMonth())) {
+ usedSeasons.add(info);
+ dateRepro = new Date(dateRepro.getDate() + info.getMonths().size() - 1); // -1 because, for have next()
+ break;
+ }
+ }
+ }
+
+ for(PopulationSeasonInfo info : usedSeasons){
+ Month month = info.getFirstMonth();
+ MatrixND CA = info.getGroupChangeMatrix(month);
+ MatrixND MI = info.getMigrationMatrix(month, result);
+ MatrixND tmp0 = N.mult(CA);
+ MatrixND tmp2 = tmp0.mult(MI);
+ N = tmp2;
+ }
+ result = pop.split2D(N);
+ }
+ return result;
+ }
+
+ /**
+ * @param catchPerStrategyMet
+ */
+ public void holdCatch(Population pop, MatrixND catchPerStrategyMet) {
+ catchs.put(pop, catchPerStrategyMet);
+
+ MatrixND holdCatch = holdCatchs.get(pop);
+ if (holdCatch == null) {
+ holdCatch = MatrixFactory.getInstance().create(catchPerStrategyMet);
+ holdCatchs.put(pop, holdCatch);
+ } else {
+ holdCatch.add(catchPerStrategyMet);
+ }
+
+ // compute total
+ for(MatrixIterator i=catchPerStrategyMet.iterator(); i.next();){
+ this.totalHoldCatch += i.getValue();
+ }
+
+ }
+
+ /**
+ * @param pop
+ * @return
+ */
+ public MatrixND getCatch(Population pop) {
+ MatrixND result = catchs.get(pop);
+ return result;
+ }
+
+ /**
+ * @param pop
+ * @return
+ */
+ public MatrixND getHoldCatch(Population pop) {
+ MatrixND result = holdCatchs.get(pop);
+ return result;
+ }
+
+ /**
+ * @param pop
+ * @return
+ */
+ public double getTotalHoldCatch(Population pop) {
+ double result = totalHoldCatch;
+ return result;
+ }
+
+ /**
+ * raz capture cumulée de toutes les pops
+ */
+ public void clearCatch() {
+ catchs.clear();
+ holdCatchs.clear();
+ totalHoldCatch = 0;
+ }
+
+ /**
+ * @param date
+ * @param pop
+ * @return
+ */
+ public MatrixND getDiscard(Date date, Population pop) {
+ MatrixND result = discards.get(pop).get(date);
+ return result;
+ }
+
+ /**
+ * FIXME: discards n'est jamais vider, on le conserve pour toutes les annees
+ * il serait bon de faire un peu le menage de temps en temps.
+ *
+ * @param date
+ * @param pop
+ * @param discard
+ */
+ public void addDiscard(Date date, Population pop, MatrixND discard) {
+ Map<Date, MatrixND> oneDiscard = discards.get(pop);
+ synchronized(oneDiscard) {
+ MatrixND tmp = oneDiscard.get(date);
+ if (tmp == null) {
+ tmp = discard.copy();
+ discards.get(pop).put(date, tmp);
+ } else {
+ tmp.add(discard);
+ }
+ }
+ }
+}
+
+
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -30,6 +30,8 @@
package fr.ifremer.isisfish.simulator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import static org.codelutin.i18n.I18n._;
import java.io.File;
@@ -291,22 +293,20 @@
*/
static public void simulate(String simulId, SimulationParameter param,
boolean inQueue) throws SimulationException {
- // Ajout automatiquement de la date+heure a la fin de l'identifiant
- // comme demandé par Steph 20070227
- simulId += " " + dateFormat.format(new java.util.Date());
+ try {
+ simulId += " " + dateFormat.format(new java.util.Date());
- if (simulId == null ||
- "".equals(simulId) ||
- SimulationStorage.localyExists(simulId) ||
- SimulationManager.getInstance().exists(simulId)) {
- log.error("Can't start simulation, bad id: " + simulId);
- throw new SimulationException(_("isisfish.error.start" +
- " simulation, bad id: {0}", "" + simulId));
+ if (simulId == null || "".equals(simulId) || SimulationStorage.localyExists(simulId) || SimulationManager.getInstance().exists(simulId)) {
+ log.error("Can't start simulation, bad id: " + simulId);
+ throw new SimulationException(_("isisfish.error.start" + " simulation, bad id: {0}", "" + simulId));
+ }
+ SimulationParameter p = param.copy();
+ p.setInQueue(inQueue);
+
+ SimulationManager.getInstance().addSimulation(simulId, p);
+ } catch (Exception eee) {
+ throw new SimulationException("Can't add simulation", eee);
}
- SimulationParameter p = param.copy();
- p.setInQueue(inQueue);
-
- SimulationManager.getInstance().addSimulation(simulId, p);
}
static public SimulationStorage simulate(SimulationControl control, SimulationStorage simulation) throws Exception {
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -36,9 +36,11 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.types.Date;
import java.beans.PropertyChangeEvent;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18nf._;
import org.codelutin.util.FileUtil;
import org.codelutin.util.ListenerSet;
@@ -46,16 +48,11 @@
import java.beans.PropertyChangeSupport;
import java.io.File;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.PriorityBlockingQueue;
/**
@@ -118,7 +115,8 @@
// TODO passer ces valeurs en valeur configurable
int cpus = Runtime.getRuntime().availableProcessors();
int MAX_REMOTE_SIMULATION = 1;
-
+ log.info(_("Launch Simulation executor with %s cpu(s) for local, and %s" +
+ " process for remote", cpus, MAX_REMOTE_SIMULATION));
localExecutor = Executors.newFixedThreadPool(cpus);
remoteExecutor = Executors.newFixedThreadPool(MAX_REMOTE_SIMULATION);
}
@@ -173,26 +171,26 @@
log.debug(_("isisfish.message.add.queue.remote", id));
}
+
+
// on construit le bon type de SimulationItem pour le job
SimulationItem item = null;
if (param.getUseAnalysePlan()) {
if (!param.isIndependentPlan()) {
item = new SimulationItemPlan(id, param);
+ executor.submit(new SimulationJob(this, item));
} else {
+ // on met dans la queue local le process de generation de toutes
+ // les simus
item = new SimulationItemPlanIndependent(id, param);
- // l'item est independant, on ajoute toutes ces simulations en plus
- // mais pas dans la map pour qu'il n'y ait bien que l'initiale
- // plus celles en cours d'affichees
- while(item.hasNext()) {
- executor.submit(new SimulationJob(this, item.next()));
- }
+ localExecutor.submit(
+ new PrepareIndependentSimulationJob(this, executor, item));
}
} else {
item = new SimulationItem(id, param);
+ executor.submit(new SimulationJob(this, item));
}
fireAddEvent(id, item); // must be before thread notification because thread look in map
-
- executor.submit(new SimulationJob(this, item));
}
/**
@@ -619,10 +617,40 @@
//
// }
+ class PrepareIndependentSimulationJob implements Runnable {
+
+ protected SimulationManager simulationManager;
+ protected ExecutorService executor;
+ protected SimulationItem item;
+
+ public PrepareIndependentSimulationJob(SimulationManager simulationManager,
+ ExecutorService executor,
+ SimulationItem item) {
+ this.simulationManager = simulationManager;
+ this.executor = executor;
+ this.item = item;
+ }
+
+ public void run() {
+ // l'item est independant, on ajoute toutes ces simulations en plus
+ // mais pas dans la map pour qu'il n'y ait bien que l'initiale
+ // plus celles en cours d'affichees
+ while (item.hasNext()) {
+ try {
+ executor.submit(new SimulationJob(simulationManager, item.next()));
+ } catch (Exception eee) {
+ log.error("Can't add simulation: " + item, eee);
+ }
+ }
+
+ }
+
+ }
+
/**
* Utilise pour les simulations sans plan d'analyse ou des plans independant
*/
- static class SimulationJob implements Runnable {
+ class SimulationJob implements Runnable {
protected SimulationManager simulationManager;
protected SimulationItem simItem;
@@ -739,6 +767,7 @@
* Une simulation a faire sans plan d'experience
*/
public class SimulationItem {
+
protected String id;
protected SimulationParameter param;
protected SimulationItemPlan planItem = null;
@@ -877,7 +906,8 @@
/**
* Une simulation a faire qui contient un plan d'experience dependant
*/
- public class SimulationItemPlan extends SimulationItem implements PropertyChangeListener {
+ public class SimulationItemPlan extends SimulationItem
+ implements PropertyChangeListener {
// FIXME a mettre en config MAX_SIMULATION_PLAN
// nombre maximal de simulation de plan par simulation
// (pour eviter les plans qui ne retroune jamais faux
@@ -971,12 +1001,26 @@
}
public void propertyChange(PropertyChangeEvent evt) {
+ // Attention il faut bien que toutes les simultions soit
+ // genere (ou qu'il en reste au moins une en cours
+ // sinon, la condition est tout de suite vrai et la simulation
+ // s'arrete. Ce qui est normalement le cas ici, car on utilise
+ // le meme executor pour genere les simultions que pour les faire
+ // et les generes est mis en premier dans l'executor, mais si
+ // on est multi cpu, et que le temps de simulation est inferieur
+ // au temps de generation des simulations, on pourrai finir par
+ // avoir un probleme.
+
if (Boolean.FALSE.equals(evt.getNewValue())) {
simulationFinished++;
control.setProgress(simulationFinished);
control.setText(simulationFinished + " / " + simulationNumber);
if (simulationFinished >= simulationNumber) {
+ log.info("All simulations have been executed: " + simulationFinished);
control.stopSimulation();
+ String id = control.getId();
+ SimulationManager.this.fireStopEvent(id);
+ SimulationManager.this.fireRemoveEvent(id);
}
}
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java 2008-08-07 19:38:45 UTC (rev 1291)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -73,7 +73,11 @@
int row = getRowCount();
fireTableRowsInserted(row, row);
SimulationControl control = getSimulationControl(e.getId());
- control.addPropertyChangeListener(this);
+ if (control != null) {
+ control.addPropertyChangeListener(this);
+ } else {
+ log.warn("Simulation without controler: " + e.getId());
+ }
}
/* (non-Javadoc)
Added: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/versionning/DummyVCSHandler.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/versionning/DummyVCSHandler.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/versionning/DummyVCSHandler.java 2008-08-11 14:36:27 UTC (rev 1292)
@@ -0,0 +1,209 @@
+/* *##%
+ * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *##%*/
+
+package fr.ifremer.isisfish.versionning;
+
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.vcs.VCSConfig;
+import org.codelutin.vcs.VCSException;
+import org.codelutin.vcs.VCSHandler;
+import org.codelutin.vcs.VCSState;
+
+/**
+ * Class utilisee lorsqu'aucun handler n'a ete initialise
+ *
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class DummyVCSHandler implements VCSHandler {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(DummyVCSHandler.class);
+
+ protected final FilenameFilter versionnableFilenameFilter;
+ protected final FileFilter versionnableFileFilter;
+
+ public DummyVCSHandler() {
+ this.versionnableFilenameFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return !".svn".equals(name) && !"CVS".equals(name);
+ }
+ };
+ this.versionnableFileFilter = new FileFilter() {
+ public boolean accept(File dir) {
+ return !".svn".equals(dir.getName()) && !"CVS".equals(dir.getName());
+ }
+ };
+}
+
+
+
+ public File getLocalDatabasePath() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void initWorkingCopy() throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void reinitWorkingCopy() throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void deleteWorkingCopy() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getRemoteUrl() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public VCSConfig getConfig() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public FilenameFilter getVersionnableFilenameFilter() {
+ return versionnableFilenameFilter;
+ }
+
+ public FileFilter getVersionnableFileFilter() {
+ return versionnableFileFilter;
+ }
+
+ public String getConfLocalDirname() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getConfLocalEntriesFilename() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public VCSState getState(File fileState, Collection tmp) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isOnRemote(File file) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isUpToDate(File file) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isVersionnableFile(File file) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void makeRemoteDir(String commitMessage, String... dirNames) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void deleteRemoteDir(String commitMessage, String... dirNames) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public long add(List<File> files, String msg) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void delete(List<File> files, String msg) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void revert(List<File> files) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public long commit(List<File> files, String msg) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void update(File file, Object revision) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void update(File file) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void checkout(File destDir, String module, boolean recurse) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void checkoutFile(File destDir, String module) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<String> getRemoteStorageNames(File directory) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<String> getLocalStorageNames(File directory) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getRevision(File f) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List getLog(Object startRevision, Object endRevision, File file) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getFileContent(File file, Object revision) throws VCSException, IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getChangeLog(File file) throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getDiff(File file) throws VCSException, IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getDiff(File file, Object againstRevision) throws VCSException, IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void testConnection() throws VCSException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+}
1
0
r1291 - in branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish: . commandline/actions datastore datastore/migration simulator ui/simulator
by bpoussin@users.labs.libre-entreprise.org 07 Aug '08
by bpoussin@users.labs.libre-entreprise.org 07 Aug '08
07 Aug '08
Author: bpoussin
Date: 2008-08-07 19:38:45 +0000 (Thu, 07 Aug 2008)
New Revision: 1291
Added:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AnalysePlanIndependent.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointExternalProcessThread.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointRemoteThread.java
Removed:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointThread.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModelOld.java
Modified:
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/commandline/actions/IsisOptionActionSimulate.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/IsisH2Config.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationInformation.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AbstractSimulationQueueModel.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationControl.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationDoneQueueModel.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationParameter.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java
branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java
Log:
refonte complete du SimulationManager, on utilise maintenant 2 executors, un local (batch ou non) et l'autre distant.
Les executors utlisent un nombre de thread predefinit au maximun (default: cpu number)
Ajout du mode batch pour lancer les simulations dans un sous process systeme
Ajout du support de la migration de base, tout est pret pour ecrire les changements necessaires entre version
pas encore test tout ca, mais commiter c jamais mauvais pour ne rien perdre
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.codelutin.util.VersionNumber;
/**
* L'implantation concrete de la configuration principale d'Isis
@@ -41,16 +42,23 @@
*/
public class IsisConfig extends IsisAbstractConfigMain {
- /** la version (ne peut pas être final car la configuration doit être chargée) */
- static private String VERSION;
-
+ protected final static VersionNumber version = new VersionNumber(3, 1, 4);
+ protected final static VersionNumber databaseVersion = new VersionNumber(
+ version.getNumber(0), version.getNumber(1));
+
static public String getVERSION() {
- if (VERSION == null) {
- VERSION = IsisContext.get().getMainConfig().getVersion().toString();
- }
- return VERSION;
+ String result = getVersion().toString();
+ return result;
}
+
+ static public VersionNumber getVersion() {
+ return version;
+ }
+ public static VersionNumber getDatabaseVersion() {
+ return databaseVersion;
+ }
+
/** le copyright (ne peut pas être final car la configuration doit être chargée) */
static private String COPYRIGHT_TEXT;
@@ -591,8 +599,6 @@
@Override
protected void loadFromSource() throws IOException {
super.loadFromSource();
- // alwyas used the java program version, should even never stored...
- setVersion(VERSION_PROPERTY_KEY.getDefaultValue());
// we do not deal with inter-config properties
clearUnsafeData();
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/commandline/actions/IsisOptionActionSimulate.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/commandline/actions/IsisOptionActionSimulate.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/commandline/actions/IsisOptionActionSimulate.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -16,6 +16,7 @@
import fr.ifremer.isisfish.datastore.RegionStorage;
import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.SimulationControl;
import fr.ifremer.isisfish.simulator.SimulationHelper;
import fr.ifremer.isisfish.simulator.SimulationParameter;
@@ -37,16 +38,22 @@
@Override
public void run() throws Exception {
- Thread.currentThread().dumpStack();
- String simulId = getSimulationId();
- File parameters = getSimulationParameter();
- File region = this.getRegion();
- File simulation = getSimulation();
+ String simulId = getSimulationId();
+ File parameters = getSimulationParameter();
+ File region = this.getRegion();
+ File simulation = getSimulation();
- if (parameters != null && simulation == null) {
+ if (parameters == null && region == null && simulation == null) {
+ // juste l'id, donc la simulation exist deja en local et ne demande
+ // qu'a etre executee
+ log.info(getOption().getUsedAlias() + ", id:" + simulId);
+ simulationWithId(simulId);
+ } else if (parameters != null && simulation == null) {
+ // Si on a des parametre, on a peut etre aussi une region
log.info(getOption().getUsedAlias() + ", id:" + simulId + ", parameters:" + parameters);
simulateWithParams(simulId, parameters, region);
} else {
+ // si on a une simulation, on a peut-etre des paramtres
log.info(getOption().getUsedAlias() + ", id:" + simulId + ", zip:" + simulation);
simulateWithSimulation(simulId, simulation, parameters);
}
@@ -101,11 +108,22 @@
if (params != null) {
sim.setParameter(params);
}
+
+ SimulationControl control = new SimulationControl(simulId);
+
// lancement de la simulation
- SimulationHelper.simulate(null, sim);
+ SimulationHelper.simulate(control, sim);
- sim.getStorage().closeContext();
+ sim.closeStorage();
+ }
+
+ public static void simulationWithId(String simulId) throws Exception {
+ SimulationStorage sim = SimulationStorage.getSimulation(simulId);
+ SimulationControl control = new SimulationControl(simulId);
+ // lancement de la simulation
+ SimulationHelper.simulate(control, sim);
+
+ sim.closeStorage();
}
-
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/IsisH2Config.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/IsisH2Config.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/IsisH2Config.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -18,6 +18,7 @@
* ##% */
package fr.ifremer.isisfish.datastore;
+import fr.ifremer.isisfish.IsisConfig;
import fr.ifremer.isisfish.commandline.configs.IsisAbstractConfigH2;
import fr.ifremer.isisfish.IsisContext;
import fr.ifremer.isisfish.IsisFishRuntimeException;
@@ -148,7 +149,7 @@
// migrate database
if (conf.isUpdateschemaDatabase()) {
// migration configuration
- config.put(TopiaMigrationServiceImpl.MIGRATION_APPLICATION_VERSION, conf.getMigrationApplicationVersion());
+ config.put(TopiaMigrationServiceImpl.MIGRATION_APPLICATION_VERSION, IsisConfig.getDatabaseVersion().toString());
config.put(TopiaMigrationServiceImpl.MIGRATION_PREVIOUS_MAPPING_DIRECTORY, conf.getMigrationPreviousMappingDirectory());
config.put(TopiaMigrationServiceImpl.MIGRATION_MODEL_NAMES, conf.getMigrationModelNames());
config.put(TopiaMigrationServiceImpl.MIGRATION_CALLBACKHANDLERS, conf.getMigrationCallBackhandlers());
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationInformation.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationInformation.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationInformation.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -275,6 +275,10 @@
setInfo(SIMULATION_EXCEPTION, v);
}
+ public boolean hasError() {
+ boolean result = getException() != null && getException().length() > 0;
+ return result;
+ }
public String getInfomation() {
String result = info.getProperty(OTHER_INFO);
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -57,6 +57,7 @@
import fr.ifremer.isisfish.entities.FisheryRegion;
import fr.ifremer.isisfish.entities.FisheryRegionDAO;
import fr.ifremer.isisfish.logging.SimulationLoggerUtil;
+import fr.ifremer.isisfish.simulator.SimulationControl;
import fr.ifremer.isisfish.simulator.SimulationParameter;
import org.codelutin.vcs.VCSException;
@@ -99,6 +100,50 @@
//return new File(getDirectory(), IsisConfig.SIMULATION_PARAMETERS);
}
+ protected transient File simulationControlFile = null;
+ protected File getSimulationControlFile() {
+ if (simulationControlFile == null) {
+ simulationControlFile = new File(getDirectory(), "control");
+ }
+ return simulationControlFile;
+ }
+
+ public void saveControl(SimulationControl control) {
+ try {
+ Properties prop = control.getProperties();
+ File file = getSimulationControlFile();
+ FileOutputStream out = new FileOutputStream(file);
+ prop.store(out, "Control");
+ out.close();
+ } catch (Exception eee) {
+ // juste un log, car la sauvegarde d'un control ne doit jamais echouer
+ // car simplement utilise pour indique l'etat de simulation
+ log.warn("Can't save control", eee);
+ }
+ }
+
+ /**
+ * Reli le fichier contenant les infos de SimulationControl, en excluant
+ * certain champs
+ * @param control
+ * @param exclude
+ */
+ public void readControl(SimulationControl control, String ... exclude) {
+ try {
+ Properties prop = new Properties();
+ File file = getSimulationControlFile();
+ FileInputStream in = new FileInputStream(file);
+ prop.load(in);
+ in.close();
+ for (String e : exclude) {
+ prop.remove(e);
+ }
+ control.updateFromProperties(prop);
+ } catch (Exception eee) {
+ log.warn("Can't read control", eee);
+ }
+ }
+
public void setParameter(SimulationParameter parameter) {
this.parameter = parameter;
if (parameter != null) {
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -18,12 +18,17 @@
package fr.ifremer.isisfish.datastore.migration;
+import java.sql.Connection;
import javax.swing.JOptionPane;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.migration.DatabaseManager;
import org.codelutin.topia.migration.callback.MigrationCallbackHandler;
+import org.codelutin.topia.migration.callback.MigrationCallbackHandler.MigrationChoice;
+import org.codelutin.util.VersionNumberUtil;
-
/**
* MigrationCallbackHandler
*
@@ -35,11 +40,15 @@
*/
public class SwingMigrationCallbackHandler implements MigrationCallbackHandler {
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(SwingMigrationCallbackHandler.class);
+
/* (non-Javadoc)
* @see org.codelutin.topia.migration.callback.MigrationCallbackHandler#doMigration(java.lang.String, java.lang.String)
*/
@Override
- public boolean doMigration(String dbVersion, String applicationVersion) {
+ public MigrationChoice doMigration(DatabaseManager dbManager,
+ String dbVersion, String applicationVersion) {
int answer = JOptionPane
.showConfirmDialog(
@@ -52,9 +61,57 @@
JOptionPane.QUESTION_MESSAGE
);
- boolean result = ( answer == JOptionPane.YES_OPTION );
+ MigrationChoice result = ( answer == JOptionPane.YES_OPTION ) ? MigrationChoice.MIGRATION : MigrationChoice.NO_MIGRATION;
+ if (result == MigrationChoice.MIGRATION) {
+ // migration manuel sans l'aide de topia-service
+ // tant que c pas fait on dit non
+ result = MigrationChoice.NO_MIGRATION;
+ // ouverture d'une connexion direct JDBC sur la base
+ try {
+ Connection conn = dbManager.getConnection();
+ try {
+ conn.setAutoCommit(false);
+ if (VersionNumberUtil.smallerThan(dbVersion, "3.2")) {
+ // on fait une migration vers 3.2
+ migrateTo3_2(conn);
+ }
+
+ // do same thing for other version
+
+ // commit des modifs
+ conn.commit();
+ // la migration a reussi, on dit que c fait
+ result = MigrationChoice.CUSTOM_MIGRATION;
+ } catch (Exception eee) {
+ // en cas d'erreur
+ log.error("Migration impossible de la base", eee);
+ // rollback du travail en cours
+ conn.rollback();
+ } finally {
+ // close database connexion
+ conn.close();
+ }
+ } catch (Exception eee) {
+ log.error("Error lors de la tentative de migration", eee);
+ }
+ }
- return result;
+ return MigrationChoice.NO_MIGRATION; // force false during test // result;
}
+ private void migrateTo3_2(Connection conn) {
+ log.info("Migrate to version 3.2");
+ //alteration du schema
+ // nouvelles equations dans les tables
+
+ // creation de valeur par defaut pour les equations
+
+
+ // recuperation des valeurs de ???
+
+ // creation de l'equation avec ces valeurs
+
+ // sauvegarde de l'equation
+ }
+
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AbstractSimulationQueueModel.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AbstractSimulationQueueModel.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AbstractSimulationQueueModel.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -15,6 +15,7 @@
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -29,13 +30,14 @@
*
* @author chemit
*/
-public abstract class AbstractSimulationQueueModel extends JComponent implements TableModel, SimulationQueueListener, PropertyChangeListener {
+public abstract class AbstractSimulationQueueModel extends JComponent
+ implements TableModel, SimulationQueueListener, PropertyChangeListener {
/** @return list of ids of simulations contained in this model */
protected abstract List<String> getSimulationIds();
/** @return map of QueueItems (indexed by id) */
- protected abstract Map<String, SimulationManager.QueueItem> getQueueItemsAsMap();
+ protected abstract Map<String, SimulationManager.SimulationItem> getQueueItemsAsMap();
/** to use log facility, just put in your code: log.info("..."); */
protected static LutinLog log = LutinLogFactory.getLutinLog(AbstractSimulationQueueModel.class);
@@ -50,7 +52,14 @@
protected String[] header = new String[]{_("isisfish.queue.id"), _("isisfish.queue.plan"), _("isisfish.queue.name"), _("isisfish.queue.local"), _("isisfish.queue.status"), _("isisfish.queue.progression")};
/** columns types */
- protected Class[] columnClass = new Class[]{String.class, String.class, Boolean.class, Boolean.class, String.class, JProgressBar.class};
+ protected Class[] columnClass = new Class[]{
+ String.class, // id
+ String.class, // analyse plan number
+ Boolean.class, // in queue
+ String.class, // local, remote, batch
+ String.class, // text
+ JProgressBar.class // progress
+ };
/** progress bar (one for each row) */
protected Map<String, JProgressBar> progress = new HashMap<String, JProgressBar>();
@@ -116,7 +125,7 @@
* @param id id of the QueueItem to find
* @return the queueItem found via his id
*/
- protected SimulationManager.QueueItem getItem(String id) {
+ protected SimulationManager.SimulationItem getItem(String id) {
return getQueueItemsAsMap().get(id);
}
@@ -124,7 +133,7 @@
* @param rowIndex rowIndex of the QueueItem to find
* @return the queueItem found via his rowIndex
*/
- protected SimulationManager.QueueItem getItem(int rowIndex) {
+ protected SimulationManager.SimulationItem getItem(int rowIndex) {
String id = getSimulationId(rowIndex);
return id == null ? null : getQueueItemsAsMap().get(id);
}
@@ -134,24 +143,16 @@
* @return the SimulationControl of the given simulation
*/
protected SimulationControl getSimulationControl(String id) {
- SimulationControl result = null;
- SimulationManager.QueueItem item = getItem(id);
- if (item != null) {
- result = item.control;
- } else {
+ SimulationControl result = queue.getControl(id);
+ if (result == null) {
log.user(_("isisfish.error.invalid.simulation.id", id, getSimulationIds()));
}
return result;
}
public SimulationControl getSimulationControl(int rowIndex) {
- SimulationControl result = null;
- SimulationManager.QueueItem item = getItem(rowIndex);
- if (item != null) {
- result = item.control;
- } else {
- log.user(_("isisfish.error.invalid.simulation.index", rowIndex));
- }
+ String id = getSimulationId(rowIndex);
+ SimulationControl result = getSimulationControl(id);
return result;
}
/**
@@ -160,7 +161,7 @@
*/
protected SimulationParameter getSimulationParameter(String id) {
SimulationParameter result = null;
- SimulationManager.QueueItem item = getItem(id);
+ SimulationManager.SimulationItem item = getItem(id);
if (item != null) {
result = item.param;
} else {
@@ -189,6 +190,24 @@
}
/////////////////////////////////////////////
+ // SimulationQueueListener implementation
+ /////////////////////////////////////////////
+
+ /* (non-Javadoc)
+ * @see SimulationQueueListener#simulationStart(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
+ */
+ public void simulationStart(SimulationQueueEvent e) {
+ // nothing to do
+ }
+
+ /* (non-Javadoc)
+ * @see SimulationQueueListener#simulationStop(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
+ */
+ public void simulationStop(SimulationQueueEvent e) {
+ // nothing to do
+ }
+
+ /////////////////////////////////////////////
// TableModel implementation
/////////////////////////////////////////////
@@ -260,7 +279,15 @@
result = param.getInQueue();
break;
case 3:
- result = param.getLocal();
+ if (param.getLocal()) {
+ if (param.isSubProcess()) {
+ result = "batch";
+ } else {
+ result = "local";
+ }
+ } else {
+ result = "remote";
+ }
break;
case 4:
if (control != null) {
Added: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AnalysePlanIndependent.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AnalysePlanIndependent.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/AnalysePlanIndependent.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -0,0 +1,46 @@
+/* *##%
+ * Copyright (C) 2007
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * AnalysePlan.java
+ *
+ * Created: 1 mars 07 20:27:28
+ *
+ * @author poussin
+ * @version $Revision: 336 $
+ *
+ * Last update: $Date: 2007-03-09 15:10:40 +0100 (ven, 09 mar 2007) $
+ * by : $Author: bpoussin $
+ */
+
+package fr.ifremer.isisfish.simulator;
+
+/**
+ * Use for Analyse plan that don't need previous simulation to do next
+ * simulation. When Simulation use this plan type, Isis can do more than one
+ * simulation in same time.
+ *
+ * author poussin
+ */
+public interface AnalysePlanIndependent extends AnalysePlan {
+
+
+}
+
+
Added: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointExternalProcessThread.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointExternalProcessThread.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointExternalProcessThread.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -0,0 +1,89 @@
+/**
+* SimulationCheckpointThread.java
+*
+* Created: Wed Aug 28 2002
+*
+* @author <poussin at codelutin.com>
+* Copyright Code Lutin
+* @version $Revision: 1187 $
+*
+* Mise a jour: $Date: 2008-03-19 01:26:10 +0100 (mer, 19 mar 2008) $
+* par : $Author: tchemit $
+*/
+
+package fr.ifremer.isisfish.simulator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.xmlrpc.XmlRpcClient;
+
+import fr.ifremer.isisfish.IsisConfig;
+import fr.ifremer.isisfish.IsisContext;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * This thread is responsable to synchronized SimulationControl used localy with
+ * remote simulation control for remote simulation.
+ *
+ * This thread dead when {@link SimulationControl#isRunning()} is false
+ *
+ * @author poussin
+ */
+public class SimulationCheckpointExternalProcessThread extends Thread { // SimulationCheckpointThread
+
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory
+ .getLog(SimulationCheckpointExternalProcessThread.class);
+
+ protected SimulationControl control = null;
+ protected SimulationStorage simulation = null;
+ protected Process process = null;
+ // on l'appel plutot out que in, car c le output du process lance
+ protected InputStream out = null;
+
+ public SimulationCheckpointExternalProcessThread(SimulationControl control,
+ SimulationStorage simulation, Process process) {
+ this.control = control;
+ this.simulation = simulation;
+ this.process = process;
+ out = process.getInputStream();
+
+ }
+
+ public void run(){
+ int sleepTime = 2000;
+ int error = 0;
+ while(true){
+ try{
+ out.skip(out.available());
+ Thread.sleep(sleepTime);
+ // on ne lit pas le stop, car le stop ne peut-etre appeler
+ // que par l'utilisateur qui est de ce cote de la machine
+ simulation.readControl(control, "stop");
+
+ if (control.isStopSimulationRequest()) {
+ // FIXME, un destroy du process est peut-etre un peu violent ?
+ process.destroy();
+ // passe artificiellement le control a fini
+ control.stopSimulation();
+ }
+ if (!control.isRunning()) {
+ return;
+ }
+ } catch (Exception eee) {
+ log.debug("Can't update control for " + control.getId(), eee);
+ }
+ }
+
+ }
+
+} // SimulationCheckpointThread
Copied: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointRemoteThread.java (from rev 1289, branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointThread.java)
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointRemoteThread.java (rev 0)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointRemoteThread.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -0,0 +1,92 @@
+/**
+* SimulationCheckpointRemoteThread.java
+*
+* Created: Wed Aug 28 2002
+*
+* @author <poussin at codelutin.com>
+* Copyright Code Lutin
+* @version $Revision$
+*
+* Mise a jour: $Date$
+* par : $Author$
+*/
+
+package fr.ifremer.isisfish.simulator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.xmlrpc.XmlRpcClient;
+
+import fr.ifremer.isisfish.IsisConfig;
+import fr.ifremer.isisfish.IsisContext;
+
+/**
+ * This thread is responsable to synchronized SimulationControl used localy with
+ * remote simulation control for remote simulation.
+ *
+ * This thread dead when {@link SimulationControl#isRunning()} is false
+ *
+ * @author poussin
+ */
+public class SimulationCheckpointRemoteThread extends Thread { // SimulationCheckpointRemoteThread
+
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory
+ .getLog(SimulationCheckpointRemoteThread.class);
+
+ protected SimulationControl control = null;
+ int badId = 0;
+
+ public SimulationCheckpointRemoteThread(SimulationControl control) {
+ this.control = control;
+ }
+
+ public void run(){
+ int sleepTime = 2000;
+ while(true){
+ try{
+ Thread.sleep(sleepTime);
+
+ updateControl(control);
+ // on remet de le temps normal, vu que la connexion a reussi
+ sleepTime = 2000;
+
+ if (!control.isRunning()) {
+ return;
+ }
+
+ } catch (Exception eee) {
+ // on supporte 10 erreurs puis ensuite on quitte le thread.
+ if ( badId++ > 10){
+ log.error("Error !!! ", eee);
+ break;
+ }else{
+ // on a echouer sur une tentative, on allonge un
+ // peu le temps
+ sleepTime += 2000;
+ }
+ }
+ }
+
+ }
+
+ public void updateControl(SimulationControl control) throws Exception {
+ // essai l'ancienne etait en dur: "http://localhost:9090"
+ IsisConfig config = IsisContext.get().getMainConfig();
+ XmlRpcClient c = new XmlRpcClient(config.getSimulationServer());
+ c.setBasicAuthentication(config.getLogin(), config.getPassword());
+
+ Vector a = new Vector();
+ a.add(control.getUpdateHashtable());
+ Hashtable<String, Object> result = (Hashtable<String, Object>)c.execute("checkPoint", a);
+ // on remet de le temps normal, vu que la connexion a reussi
+ control.updateFromHashtable(result);
+ }
+
+} // SimulationCheckpointRemoteThread
Deleted: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointThread.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointThread.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationCheckpointThread.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -1,92 +0,0 @@
-/**
-* SimulationCheckpointThread.java
-*
-* Created: Wed Aug 28 2002
-*
-* @author <poussin at codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package fr.ifremer.isisfish.simulator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Hashtable;
-import java.util.Vector;
-
-import org.apache.xmlrpc.XmlRpcClient;
-
-import fr.ifremer.isisfish.IsisConfig;
-import fr.ifremer.isisfish.IsisContext;
-
-/**
- * This thread is responsable to synchronized SimulationControl used localy with
- * remote simulation control for remote simulation.
- *
- * This thread dead when {@link SimulationControl#isRunning()} is false
- *
- * @author poussin
- */
-public class SimulationCheckpointThread extends Thread { // SimulationCheckpointThread
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory
- .getLog(SimulationCheckpointThread.class);
-
- protected SimulationControl control = null;
- int badId = 0;
-
- public SimulationCheckpointThread(SimulationControl control) {
- this.control = control;
- }
-
- public void run(){
- int sleepTime = 2000;
- while(true){
- try{
- Thread.sleep(sleepTime);
-
- updateControl(control);
- // on remet de le temps normal, vu que la connexion a reussi
- sleepTime = 2000;
-
- if (!control.isRunning()) {
- return;
- }
-
- } catch (Exception eee) {
- // on supporte 10 erreurs puis ensuite on quitte le thread.
- if ( badId++ > 10){
- log.error("Error !!! ", eee);
- break;
- }else{
- // on a echouer sur une tentative, on allonge un
- // peu le temps
- sleepTime += 2000;
- }
- }
- }
-
- }
-
- public void updateControl(SimulationControl control) throws Exception {
- // essai l'ancienne etait en dur: "http://localhost:9090"
- IsisConfig config = IsisContext.get().getMainConfig();
- XmlRpcClient c = new XmlRpcClient(config.getSimulationServer());
- c.setBasicAuthentication(config.getLogin(), config.getPassword());
-
- Vector a = new Vector();
- a.add(control.getUpdateHashtable());
- Hashtable<String, Object> result = (Hashtable<String, Object>)c.execute("checkPoint", a);
- // on remet de le temps normal, vu que la connexion a reussi
- control.updateFromHashtable(result);
- }
-
-} // SimulationCheckpointThread
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationControl.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationControl.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationControl.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -31,6 +31,7 @@
package fr.ifremer.isisfish.simulator;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
@@ -40,6 +41,7 @@
import org.apache.commons.logging.LogFactory;
import fr.ifremer.isisfish.types.Date;
+import java.util.Properties;
/**
* Permit to communicate with user interface from simulation thread
@@ -52,8 +54,12 @@
protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
protected boolean inUpdateFromHashtable = false;
+ protected transient SimulationStorage simulation = null;
+ /** si vrai des qu'une propriete change, sauvegarde sont etat */
+ protected transient boolean autoSaveState = false;
protected String id = null;
+ protected boolean started = false;
protected boolean running = true;
protected boolean stop = false;
protected Date date = new Date();
@@ -70,16 +76,60 @@
this.id = id;
addPropertyChangeListener(this);
}
+
+ public void setAutoSaveState(boolean autoSaveState) {
+ this.autoSaveState = autoSaveState;
+ }
+
+ public boolean isAutoSaveState() {
+ return autoSaveState;
+ }
+ /**
+ * Retourne la simulation associe a ce control
+ * @return retourne null si la simulation n'existe pas encore
+ */
+ public SimulationStorage getSimulation() {
+ if (simulation == null) {
+ simulation = SimulationStorage.getSimulation(id);
+ }
+ return simulation;
+ }
+
+
+
+ public void addPropertyChangeListener(String propName, PropertyChangeListener l) {
+ listeners.addPropertyChangeListener(propName, l);
+ }
+
public void addPropertyChangeListener(PropertyChangeListener l) {
listeners.addPropertyChangeListener(l);
}
+ public void removePropertyChangeListener(String propName, PropertyChangeListener l) {
+ listeners.removePropertyChangeListener(propName, l);
+ }
+
public void removePropertyChangeListener(PropertyChangeListener l) {
listeners.removePropertyChangeListener(l);
}
+ public boolean isStarted() {
+ return started;
+ }
+
/**
+ * appelee juste avant de reellement demarrer le thread de simulation
+ * indique que cette simulation est en cours et qu'il ne faut plus la lancer
+ * @param running The running to set.
+ */
+ public void setStarted(boolean started) {
+ boolean oldValue = this.started;
+ this.started = started;
+ listeners.firePropertyChange("started", oldValue, this.started);
+ }
+
+ /**
* Method running
*
* @return faux une fois que stopSimulation a ete appele.
@@ -221,12 +271,75 @@
}
/**
+ * Met dans un Properties tous les champs
+ * @return un Properties avec tous les champs
+ */
+ public Properties getProperties() {
+ Properties result = new Properties();
+ result.setProperty("id", id);
+ result.setProperty("started", String.valueOf(started));
+ result.setProperty("running", String.valueOf(running));
+ result.setProperty("stop", String.valueOf(stop));
+ result.setProperty("date", String.valueOf(date.getDate()));
+ result.setProperty("progressMax", String.valueOf(progressMax));
+ result.setProperty("progress", String.valueOf(progress));
+ result.setProperty("text", text);
+
+ return result;
+ }
+
+ /**
+ * update current object from Properties representation
+ *
+ */
+ public void updateFromProperties(Properties h) {
+ inUpdateFromHashtable = true;
+ try {
+ if (h.contains("started")) {
+ boolean started = "true".equalsIgnoreCase(h.getProperty("started"));
+ setStarted(started);
+ }
+ if (h.contains("running")) {
+ boolean running = "true".equalsIgnoreCase(h.getProperty("running"));
+ setRunning(running);
+ }
+ if (h.contains("stop")) {
+ boolean stop = "true".equalsIgnoreCase(h.getProperty("stop"));
+ setStopSimulationRequest(stop);
+ }
+ if (h.contains("date")) {
+ Date date = new Date(Integer.parseInt(h.getProperty("date")));
+ setDate(date);
+ }
+ if (h.contains("progressMax")) {
+ int progressMax = Integer.parseInt(h.getProperty("progressMax"));
+ setProgressMax(progressMax);
+ }
+ if (h.contains("progress")) {
+ int progress = Integer.parseInt(h.getProperty("progress"));
+ setProgress(progress);
+ }
+ if (h.contains("text")) {
+ String text = h.getProperty("text");
+ setText(text);
+ }
+ } finally {
+ inUpdateFromHashtable = false;
+ }
+ }
+
+
+ /**
* update current object from hashtable representation
*
*/
public void updateFromHashtable(Hashtable h) {
inUpdateFromHashtable = true;
try {
+ if (h.contains("started")) {
+ boolean started = (Boolean)h.get("started");
+ setStarted(started);
+ }
if (h.contains("running")) {
boolean running = (Boolean)h.get("running");
setRunning(running);
@@ -266,6 +379,9 @@
} else {
Object value = e.getNewValue();
update.put(property, value);
+ if (isAutoSaveState() && getSimulation() != null) {
+ getSimulation().saveControl(this);
+ }
}
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationDoneQueueModel.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationDoneQueueModel.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationDoneQueueModel.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -62,13 +62,13 @@
* @see AbstractSimulationQueueModel at getSimulationIds()
*/
protected java.util.List<String> getSimulationIds() {
- return getQueue().idDones;
+ return getQueue().getDoneIds();
}
/* (non-Javadoc)
* @see AbstractSimulationQueueModel at getQueueItemsAsMap()
*/
- protected java.util.Map<String, SimulationManager.QueueItem> getQueueItemsAsMap() {
+ protected java.util.Map<String, SimulationManager.SimulationItem> getQueueItemsAsMap() {
return getQueue().mapDones;
}
@@ -89,57 +89,32 @@
// IsisConfig.SIMULATION_SHOW_ONLY_XXX properties)
int pos = getSimulationIndex(e.getId());
if (isRowIndexValid(pos)) {
- log.info(" in done model for " + e.getId() + " pos " + getSimulationIndex(e.getId()));
+ log.info(" in done model for " + e.getId() + " pos " + pos);
fireTableRowsInserted(pos, pos);
+
+ // on indique si la simulation a ete annulee
SimulationControl control = getSimulationControl(e.getId());
log.info("isStopSimulationRequest : "+control.isStopSimulationRequest());
if (control.isStopSimulationRequest()) {
control.setText(I18n._("isisfish.queue.cancelled"));
}
- SimulationManager.QueueItem item = getQueueItemsAsMap().get(e.getId());
- try {
- //TODO I don't known if this is good ?
- SimulationStorage lastSim = item.lastSimulation;
- SimulationParameter simulationParameter = getSimulationParameter(e.getId());
- if (lastSim != null) {
- if (simulationParameter.getUseAnalysePlan()) {
- //TODO Is the lastSimulation is the good one ???
- SimulationInformation infos = getItem(e.getId()).lastSimulation.getInformation();
- if (infos != null && infos.getException() != null) {
- // should deal with error
- log.error(I18n._("isisfish.error.while.simulation", infos.getException()));
- control.setText(I18n._("isisfish.message.stop.with.error"));
- }
- } else if (lastSim.getName().equals(e.getId())) {
- SimulationInformation infos = getItem(e.getId()).lastSimulation.getInformation();
- if (infos != null && infos.getException() != null) {
- // should deal with error
- log.error(I18n._("isisfish.error.while.simulation", infos.getException()));
- control.setText(I18n._("isisfish.message.stop.with.error",infos.getException()));
- }
+ // on change le message pour dire qu'il y a eu une erreur
+ try {
+ SimulationManager.SimulationItem item = getQueueItemsAsMap().get(e.getId());
+ if (!item.hasSimulation()) {
+ SimulationInformation infos = item.getSimulation().getInformation();
+ if (infos.hasError()) {
+ log.error(I18n._("isisfish.error.while.simulation", infos.getException()));
+ control.setText(I18n._("isisfish.message.stop.with.error"));
}
}
- // I don't known if you can come here with no previous simulation ?
- } catch (Exception e1) {
- log.warn(I18n._("isisfish.error.obtain.information.file", e.getId()));
+ } catch (Exception eee) {
+ log.warn(I18n._("isisfish.error.obtain.information.file", e.getId()), eee);
}
control.addPropertyChangeListener(this);
}
}
- /* (non-Javadoc)
- * @see SimulationQueueListener#simulationStart(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationStart(SimulationQueueEvent e) {
- // nothing to do
- }
-
- /* (non-Javadoc)
- * @see SimulationQueueListener#simulationStop(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationStop(SimulationQueueEvent e) {
- // nothing to do
- }
}// SimulationDoneQueueModel
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -63,6 +63,7 @@
import fr.ifremer.isisfish.IsisConfig;
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.IsisContext;
+import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.aspect.AspectClassLoader;
import fr.ifremer.isisfish.aspect.Cache;
import fr.ifremer.isisfish.aspect.Trace;
@@ -311,7 +312,11 @@
static public SimulationStorage simulate(SimulationControl control, SimulationStorage simulation) throws Exception {
SimulationStorage result;
if (simulation.getParameter().getLocal()) {
- result = localSimulate(control, simulation);
+ if (simulation.getParameter().isSubProcess()) {
+ result = subProcessSimulate(control, simulation);
+ } else {
+ result = localSimulate(control, simulation);
+ }
} else {
result = remoteSimulate(control, simulation);
}
@@ -328,14 +333,15 @@
* @return le storage après simulation
* @throws Exception pour toute erreur
*/
- static public SimulationStorage remoteSimulate(SimulationControl control, SimulationStorage simulation) throws Exception {
+ static public SimulationStorage remoteSimulate(SimulationControl control,
+ SimulationStorage simulation) throws Exception {
// export en zip du storage
File zip = simulation.createZip();
if (control != null) {
// creation du thread de surveillance de la simulation distante
// qui sert a mettre a jour les valeurs de control
- new SimulationCheckpointThread(control).start();
+ new SimulationCheckpointRemoteThread(control).start();
}
// envoie le zip au serveur de simulation
@@ -362,7 +368,41 @@
result = SimulationStorage.importAndRenameZip(tmpzip, control.getId());
return result;
}
-
+
+ static public SimulationStorage subProcessSimulate(SimulationControl control,
+ SimulationStorage simulation) throws Exception {
+
+ String simulationId = simulation.getName();
+
+ // on ferme le SimulationStorage pour ne pas interferer avec le process
+ simulation.closeStorage();
+
+ String java = System.getProperty("java.home") +
+ File.separator + "bin" + File.separator + "java";
+ String classpath = System.getProperty("java.class.path");
+
+ // prepare le process
+ ProcessBuilder processBuilder = new ProcessBuilder(java, "-classpath", classpath,
+ IsisFish.class.getName(),
+ "--simulate", simulationId);
+ processBuilder.redirectErrorStream(true);
+
+ // demarrage du process
+ Process process = processBuilder.start();
+
+ if (control != null) {
+ // prepare de thread de surveillance du process si control n'est pas null
+ Thread monitor = new SimulationCheckpointExternalProcessThread(control, simulation, process);
+ }
+
+ // on attend que la simulation soit fini
+ process.waitFor();
+
+ // on retourne directement le simulation storage passe en argument
+ // car la simulation a ete faite avec
+ return simulation;
+ }
+
/**
* fait la simulation en local dans un nouveau thread, cela permet
* pour chaque simulation d'avoir les bons scripts dans le classloader
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -35,6 +35,7 @@
import fr.ifremer.isisfish.IsisContext;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.types.Date;
+import java.beans.PropertyChangeEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.codelutin.i18n.I18n._;
@@ -46,9 +47,14 @@
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.PriorityBlockingQueue;
@@ -64,30 +70,33 @@
static protected SimulationManager instance = null;
- protected boolean autoLaunch = false;
+// protected boolean autoLaunch = false;
protected ListenerSet<SimulationQueueListener> listeners = new ListenerSet<SimulationQueueListener>();
protected PropertyChangeSupport propertyListeners = new PropertyChangeSupport(this);
- protected SimulationThread localThread;
- protected SimulationThread remoteThread;
+// protected SimulationThread localThread;
+// protected SimulationThread remoteThread;
- /** La queue, bloquante lorsqu'elle est vide, utilisé par le thread de simulation local*/
- protected PriorityBlockingQueue<QueueItem> localQueue = new PriorityBlockingQueue<QueueItem>();
- /** La queue, bloquante lorsqu'elle est vide, utilisé par le thread de simulation remote*/
- protected PriorityBlockingQueue<QueueItem> remoteQueue = new PriorityBlockingQueue<QueueItem>();
- /** La liste des simulations terminées */
- protected LinkedHashSet<QueueItem> dones = new LinkedHashSet<QueueItem>();
+ protected ExecutorService localExecutor;
+ protected ExecutorService remoteExecutor;
+
+// /** La queue, bloquante lorsqu'elle est vide, utilisé par le thread de simulation local*/
+// protected PriorityBlockingQueue<QueueItem> localQueue = new PriorityBlockingQueue<QueueItem>();
+// /** La queue, bloquante lorsqu'elle est vide, utilisé par le thread de simulation remote*/
+// protected PriorityBlockingQueue<QueueItem> remoteQueue = new PriorityBlockingQueue<QueueItem>();
+// /** La liste des simulations terminées */
+// protected LinkedHashSet<SimulationItem> dones = new LinkedHashSet<SimulationItem>();
- /** une liste des id (local et remote) */
- protected ArrayList<String> ids = new ArrayList<String>();
- /** une map id->item pour accelerer les acces */
- protected Map<String, QueueItem> map = new HashMap<String, QueueItem>();
+// /** une liste des id (local et remote) */
+// protected ArrayList<String> ids = new ArrayList<String>();
+ /** une map id->simItem pour accelerer les acces */
+ protected Map<String, SimulationItem> map = new LinkedHashMap<String, SimulationItem>();
- /** une liste des id des simulations terminées */
- protected ArrayList<String> idDones = new ArrayList<String>();
- /** une map id->item pour accelerer les acces aux simulation terminées */
- protected Map<String, QueueItem> mapDones = new HashMap<String, QueueItem>();
+// /** une liste des id des simulations terminées */
+// protected ArrayList<String> idDones = new ArrayList<String>();
+ /** une map id->simItem pour accelerer les acces aux simulation terminées */
+ protected Map<String, SimulationItem> mapDones = new LinkedHashMap<String, SimulationItem>();
static public SimulationManager getInstance() {
if (instance == null) {
@@ -100,20 +109,27 @@
* Cree l'objet et lance les deux threads de simulation (local/remote)
*/
protected SimulationManager() {
- localThread = new SimulationThread("local", this, localQueue);
- remoteThread = new SimulationThread("remote", this, remoteQueue);
+// localThread = new SimulationThread("local", this, localQueue);
+// remoteThread = new SimulationThread("remote", this, remoteQueue);
+//
+// localThread.start();
+// remoteThread.start();
- localThread.start();
- remoteThread.start();
+ // TODO passer ces valeurs en valeur configurable
+ int cpus = Runtime.getRuntime().availableProcessors();
+ int MAX_REMOTE_SIMULATION = 1;
+
+ localExecutor = Executors.newFixedThreadPool(cpus);
+ remoteExecutor = Executors.newFixedThreadPool(MAX_REMOTE_SIMULATION);
}
- /**
- * @return Returns the autoLaunch.
- */
- public boolean isAutoLaunch() {
- return this.autoLaunch;
- }
+// /**
+// * @return Returns the autoLaunch.
+// */
+// public boolean isAutoLaunch() {
+// return this.autoLaunch;
+// }
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyListeners.addPropertyChangeListener(listener);
@@ -131,32 +147,52 @@
propertyListeners.removePropertyChangeListener(propertyName, listener);
}
- /**
- * @param autoLaunch The autoLaunch to set.
- */
- public void setAutoLaunch(boolean autoLaunch) {
- boolean oldValue = this.autoLaunch;
- this.autoLaunch = autoLaunch;
- propertyListeners.firePropertyChange("autoLaunch", oldValue, autoLaunch);
- }
+// /**
+// * @param autoLaunch The autoLaunch to set.
+// */
+// public void setAutoLaunch(boolean autoLaunch) {
+// boolean oldValue = this.autoLaunch;
+// this.autoLaunch = autoLaunch;
+// propertyListeners.firePropertyChange("autoLaunch", oldValue, autoLaunch);
+// }
/**
* Cree l'objet de gestion de la simulation en interne et le place dans la
* bonne queue de simulation (local/remote). Appel le
- * {@link #fireAddEvent(String, QueueItem)}
+ * {@link #fireAddEvent(String, SimulationItem)}
* @param id l'id de simulation
* @param param les paramètres de la simulation
*/
- public void addSimulation(String id, SimulationParameter param) {
- QueueItem item = new QueueItem(id, param);
- fireAddEvent(id, item); // must be before thread notification because thread look in map
+ public void addSimulation(String id, SimulationParameter param) throws Exception {
+ ExecutorService executor = null;
if (param.getLocal()) {
- localQueue.add(item);
+ executor = localExecutor;
log.debug(_("isisfish.message.add.queue", id));
} else {
- remoteQueue.add(item);
+ executor = remoteExecutor;
log.debug(_("isisfish.message.add.queue.remote", id));
}
+
+ // on construit le bon type de SimulationItem pour le job
+ SimulationItem item = null;
+ if (param.getUseAnalysePlan()) {
+ if (!param.isIndependentPlan()) {
+ item = new SimulationItemPlan(id, param);
+ } else {
+ item = new SimulationItemPlanIndependent(id, param);
+ // l'item est independant, on ajoute toutes ces simulations en plus
+ // mais pas dans la map pour qu'il n'y ait bien que l'initiale
+ // plus celles en cours d'affichees
+ while(item.hasNext()) {
+ executor.submit(new SimulationJob(this, item.next()));
+ }
+ }
+ } else {
+ item = new SimulationItem(id, param);
+ }
+ fireAddEvent(id, item); // must be before thread notification because thread look in map
+
+ executor.submit(new SimulationJob(this, item));
}
/**
@@ -166,7 +202,7 @@
* @param id l'id de simulation
*/
public void removeSimulation(String id) {
- QueueItem item = map.get(id);
+ SimulationItem item = map.get(id);
if (item != null) {
item.control.setStopSimulationRequest(true);
}
@@ -174,6 +210,26 @@
}
/**
+ * Retourne une liste toujours dans le meme ordre des ids de simulation
+ * a faire
+ * @return
+ */
+ public List<String> getIds() {
+ List<String> result = new ArrayList<String>(map.keySet());
+ return result;
+ }
+
+ /**
+ * Retourne une liste toujours dans le meme ordre des ids de simulation
+ * a faire
+ * @return
+ */
+ public List<String> getDoneIds() {
+ List<String> result = new ArrayList<String>(mapDones.keySet());
+ return result;
+ }
+
+ /**
* @param id l'id de simulation
* @return <code>true</code> si un identifiant est utilisé pour une simulation
*/
@@ -202,8 +258,8 @@
listeners.remove(l);
}
- protected void fireAddEvent(String id, QueueItem item) {
- ids.add(id);
+ protected void fireAddEvent(String id, SimulationItem item) {
+// ids.add(id);
map.put(id, item);
SimulationQueueEvent e = new SimulationQueueEvent(this, id);
for (SimulationQueueListener l : listeners) {
@@ -216,21 +272,29 @@
// add the simulation in done model
// check if we should keep the simulation in done model
if (mustShowSimulationDone(id)) {
- idDones.add(id);
- SimulationManager.QueueItem queueItem = map.get(id);
- dones.add(queueItem);
+// idDones.add(id);
+ SimulationItem queueItem = map.get(id);
+// dones.add(queueItem);
mapDones.put(id, queueItem);
}
SimulationQueueEvent e = new SimulationQueueEvent(this, id);
for (SimulationQueueListener l : listeners) {
l.simulationWillBeRemoved(e);
}
- ids.remove(id);
+// ids.remove(id);
map.remove(id);
}
}
- protected void fireStartEvent(String id) {
+ protected void fireStartEvent(String id, SimulationItem item) {
+ if (!exists(id) && item.isIndependent()) {
+ // la simulation qui vient d'etre lancee n'existe pas, c parce qu'il
+ // s'agit d'une simulation de plan, on l'ajoute a la liste pour que
+ // l'utilisateur puisse la visualiser. On ne le fait pas pour les
+ // plan dependant car, il partage le meme controleur, donc
+ // l'utilisateur voit deja ce qui se passe
+ fireAddEvent(id, item);
+ }
SimulationQueueEvent e = new SimulationQueueEvent(this, id);
for (SimulationQueueListener l : listeners) {
l.simulationStart(e);
@@ -258,7 +322,7 @@
*/
public SimulationControl getControl(String id) {
SimulationControl result = null;
- QueueItem item = map.get(id);
+ SimulationItem item = map.get(id);
if (item != null) {
result = item.control;
}
@@ -273,233 +337,597 @@
protected boolean mustShowSimulationDone(String id) {
boolean result = true;
- QueueItem item = map.get(id);
- SimulationParameter simulationParameter = getParameter(id);
- IsisConfig config = IsisContext.get().getMainConfig();
- if (config.isSimulationShowOnlyQueue() && !simulationParameter.getLocal()) {
- return false;
- }
+ try {
+ IsisConfig config = IsisContext.get().getMainConfig();
- try {
- //TODO cela ne fonctionne pas, le fichier existe-il à ce moment ?
- if (config.isSimulationShowOnlyError() && item.lastSimulation.getInformation().getException() != null) {
- return true;
+ SimulationItem item = map.get(id);
+ if (item.hasPlanItem() && !item.getSimulation().getInformation().hasError()) {
+ // on ne met jamais dans la queue done les simulations de plan
+ // sauf si elle echoue
+ result = false;
+ } else if (!(config.isSimulationShowOnlyError() &&
+ !(item instanceof SimulationItemPlan) &&
+ item.getSimulation().getInformation().hasError())) {
+ result = false;
}
- } catch (Exception e) {
+ } catch (Exception eee) {
+ log.debug("Ne devrait pas arriver", eee);
// I don't known how it could appear, but in doubt, show it!
- return true;
}
return result;
}
+// /**
+// * Thread permettant de faire les simulations se trouvant dans la queue
+// * passée en parametre.
+// * <p>
+// * Si la simulation prise dans la queue n'existe plus, au moment ou on
+// * souhaite l'utiliser dans le {@link SimulationManager} alors elle est
+// * passée et on en recherche une autre.
+// *
+// * @author poussin
+// */
+// static class SimulationThread extends Thread {
+// protected SimulationManager simulationManager;
+// protected BlockingQueue<QueueItem> queue;
+//
+// /**
+// *
+// * @param name just small name to differenciate thread (local/remote)
+// * @param simulationManager le manager de simulation
+// * @param queue la queue de simulations
+// */
+// public SimulationThread(String name, SimulationManager simulationManager, BlockingQueue<QueueItem> queue) {
+// super("Simulation Thread " + name);
+// this.simulationManager = simulationManager;
+// this.queue = queue;
+// }
+//
+// /* (non-Javadoc)
+// * @see java.lang.Thread#run()
+// */
+// @Override
+// public void run() {
+// log.info("Start simulation thread");
+// while (true) {
+// // simItem qui sert a faire la simulation courante
+// QueueItem simItem = null;
+// try {
+// //
+// // recheche d'une simulation
+// //
+// while (simItem == null) {
+// log.debug("try to take simulation");
+// simItem = queue.take();
+// log.debug("Just take " + simItem.id);
+// if (!simulationManager.exists(simItem.id)) {
+// // on ne le retrouve pas dans la map, la simulation
+// // a donc ete supprimée par l'utilisateur on passe a la
+// // suivante
+// simItem = null;
+// } else if (!simulationManager.isAutoLaunch() && simItem.param.getInQueue()) {
+// // don't use simItem, because is queue and queue is not launched
+// queue.add(simItem);
+// simItem = null;
+// // sleep 1s. Because all other simItem is in queue too
+// // this sleep permit to user to put not queue simItem,
+// // with out eat cpu
+// sleep(1000);
+// }
+// }
+//
+// log.debug("use if has next simulation: " + simItem.id);
+// if (simItem.hasNext()) {
+// SimulationStorage sim = simItem.getSimulation();
+// String simId = sim.getName();
+// log.debug("Start simulation: " + simId);
+// SimulationControl control = simItem.control;
+// // set date to 0 at beginning of simulation
+// control.setDate(new Date());
+// control.setProgress(0);
+// control.setStarted(true);
+//
+// simulationManager.fireStartEvent(simItem.id);
+// try {
+// sim = SimulationHelper.simulate(control, sim);
+// simItem.setLastSimulation(sim);
+// } finally {
+// simulationManager.fireStopEvent(simItem.id);
+// }
+// // copie les exports de simulation dans le repertoire
+// // souhaiter par l'utilisateur
+// SimulationParameter param = sim.getParameter();
+// if (param.getExportNames() != null && param.getExportNames().size() > 0) {
+// File exportDir = IsisConfig.getResultExportDirectory(sim.getDirectory());
+// FileUtil.copyAndRenameRecursively(
+// exportDir,
+// new File(param.getExportDirectory()),
+// exportDir.getName(), simItem.id);
+//// FileUtil.copyAndRenameRecursively(
+//// exportDir,
+//// new File(sim.getDirectory(), IsisConfig.RESULT_EXPORT),
+//// IsisConfig.RESULT_EXPORT, simItem.id);
+// }
+//
+// if (simItem.hasNext() && simulationManager.exists(simItem.id)) {
+// // il y a encore des simulations a faire pour cet simItem
+// // on le remet dans la queue (on ne fait pas les autres
+// // simulations de cet simItem
+// // tout de suite car l'simItem peut-etre un simItem de queue
+// // moins prioritaire que les autres simulations
+// // il faut donc qu'il reprenne sa place dans l'ordre)
+//
+// queue.add(simItem);
+// } else {
+// // Si l'utilisateur souhaite seulement les exports
+// // on supprimer la/les simulations. Il faut le faire
+// // lorsqu'il n'y a plus de next car le calcul des plans
+// // peut avoir besoin des simulations precedentes
+// if (param.getOnlyExport()) {
+// if (param.getUseAnalysePlan()) {
+// for(File file : FileUtil.find(
+// IsisConfig.getSimulationDirectory(),
+// simItem.id + "_[0-9]+$", false)) {
+// log.debug("Delete simulation " + file);
+// FileUtil.deleteRecursively(file);
+// }
+// } else {
+// sim.delete(false);
+// }
+// }
+// simulationManager.fireRemoveEvent(simItem.id);
+//
+// if (simulationManager.isAutoLaunch() && simItem.param.getInQueue()) {
+// // if simItem is last in queue, stop the queue after that
+// QueueItem [] items = queue.toArray(new QueueItem[queue.size()]);
+// if (items.length > 0) {
+// QueueItem last = items[items.length-1];
+// if (!last.param.getInQueue()) {
+// // la derniere n'est pas en queue, donc plus de simulation en queue
+// simulationManager.setAutoLaunch(false);
+// }
+// } else {
+// // aucun simulation, donc forcement plus en queue non plus
+// simulationManager.setAutoLaunch(false);
+// }
+// }
+// }
+// }
+//
+//// } catch (Exception eee) {
+// } catch (Throwable eee) {
+// try {
+// // on sauvegarde l'erreur rencontrée, elle sera traité lors
+// // du fireRemoveEvent
+// simItem.lastSimulation.getInformation().setException(eee);
+// } catch (Exception e) {
+// if (log.isWarnEnabled()) {
+// log.warn(_("isisfish.error.during.simulation.information.file", simItem.id), eee);
+// }
+// } finally {
+// // error during simulation, remove bad simulation
+// simulationManager.fireRemoveEvent(simItem.id);
+// if (log.isWarnEnabled()) {
+// log.warn(_("isisfish.error.during.simulation", simItem.id), eee);
+// }
+// }
+//
+// } finally {
+// simItem = null;
+// }
+// }
+// }
+// }
+
+// /**
+// * Utilise pour les simulations avec plan d'analyse dependant
+// */
+// static class SimulationPlanJob implements Runnable {
+//
+// protected SimulationManager simulationManager;
+// protected SimulationItemPlan item;
+//
+// public SimulationPlanJob(SimulationManager simulationManager, SimulationItemPlan item) {
+// this.simulationManager = simulationManager;
+// this.item = item;
+// }
+//
+// public void run() {
+// try {
+// log.debug("use if has next simulation: " + item.id);
+// // on traite tout l'simItem dans le meme thread
+// while (simulationManager.exists(item.id) && item.hasNext()) {
+// SimulationStorage sim = item.getSimulation();
+// String simId = sim.getName();
+// log.debug("Start simulation: " + simId);
+// SimulationControl control = item.control;
+// // set date to 0 at beginning of simulation
+// control.setDate(new Date());
+// control.setProgress(0);
+// control.setStarted(true);
+//
+// simulationManager.fireStartEvent(item.id);
+// try {
+// sim = SimulationHelper.simulate(control, sim);
+// item.setLastSimulation(sim);
+// } finally {
+// simulationManager.fireStopEvent(item.id);
+// }
+// // copie les exports de simulation dans le repertoire
+// // souhaiter par l'utilisateur
+// SimulationParameter param = sim.getParameter();
+// if (param.getExportNames() != null &&
+// param.getExportNames().size() > 0) {
+// File exportDir = IsisConfig.getResultExportDirectory(
+// sim.getDirectory());
+// FileUtil.copyAndRenameRecursively(
+//
+// exportDir,
+// new File(param.getExportDirectory()),
+// exportDir.getName(), item.id);
+//// FileUtil.copyAndRenameRecursively(
+//// exportDir,
+//// new File(sim.getDirectory(), IsisConfig.RESULT_EXPORT),
+//// IsisConfig.RESULT_EXPORT, simItem.id);
+// }
+// }
+//
+// if (item.lastSimulation != null) {
+// SimulationParameter param = item.param;
+// // Si l'utilisateur souhaite seulement les exports
+// // on supprimer la/les simulations. Il faut le faire
+// // lorsqu'il n'y a plus de next car le calcul des plans
+// // peut avoir besoin des simulations precedentes
+// if (param.getOnlyExport()) {
+// if (param.getUseAnalysePlan()) {
+// for (File file : FileUtil.find(
+// IsisConfig.getSimulationDirectory(),
+// item.id + "_[0-9]+$", false)) {
+// log.debug("Delete simulation " + file);
+// FileUtil.deleteRecursively(file);
+// }
+// } else {
+// item.lastSimulation.delete(false);
+// }
+// }
+// }
+// // on previent que c la fin de la simulation
+// simulationManager.fireRemoveEvent(item.id);
+// } catch (Throwable eee) {
+// try {
+// // on sauvegarde l'erreur rencontrée, elle sera traité lors
+// // du fireRemoveEvent
+// if (item.lastSimulation != null) {
+// item.lastSimulation.getInformation().setException(eee);
+// }
+// } catch (Exception e) {
+// if (log.isWarnEnabled()) {
+// log.warn(_("isisfish.error.during.simulation.information.file", item.id), eee);
+// }
+// } finally {
+// // error during simulation, remove bad simulation
+// simulationManager.fireRemoveEvent(item.id);
+// if (log.isWarnEnabled()) {
+// log.warn(_("isisfish.error.during.simulation", item.id), eee);
+// }
+// }
+//
+// } finally {
+// item = null;
+// }
+// }
+//
+// }
+
/**
- * Thread permettant de faire les simulations se trouvant dans la queue
- * passée en parametre.
- * <p>
- * Si la simulation prise dans la queue n'existe plus, au moment ou on
- * souhaite l'utiliser dans le {@link SimulationManager} alors elle est
- * passée et on en recherche une autre.
- *
- * @author poussin
+ * Utilise pour les simulations sans plan d'analyse ou des plans independant
*/
- static class SimulationThread extends Thread {
+ static class SimulationJob implements Runnable {
+
protected SimulationManager simulationManager;
- protected BlockingQueue<QueueItem> queue;
+ protected SimulationItem simItem;
/**
- *
- * @param name just small name to differenciate thread (local/remote)
- * @param simulationManager le manager de simulation
- * @param queue la queue de simulations
+ *
+ * @param simulationManager
+ * @param parentId si ce job est le resulat d'un plan d'analyse
+ * independant, sinon null ou la meme valeur que id
+ * @param id l'identifiant de la simulation (avec _N pour ceux qui
+ * proviennent d'un plan d'analyse)
+ * @param zip le zip contenant la simulation
*/
- public SimulationThread(String name, SimulationManager simulationManager, BlockingQueue<QueueItem> queue) {
- super("Simulation Thread " + name);
+ public SimulationJob(SimulationManager simulationManager,
+ SimulationItem item) {
this.simulationManager = simulationManager;
- this.queue = queue;
+ this.simItem = item;
}
-
- /* (non-Javadoc)
- * @see java.lang.Thread#run()
- */
- @Override
+
public void run() {
- log.info("Start simulation thread");
- while (true) {
- // item qui sert a faire la simulation courante
- QueueItem item = null;
- try {
- //
- // recheche d'une simulation
- //
- while (item == null) {
- log.debug("try to take simulation");
- item = queue.take();
- log.debug("Just take " + item.id);
- if (!simulationManager.exists(item.id)) {
- // on ne le retrouve pas dans la map, la simulation
- // a donc ete supprimée par l'utilisateur on passe a la
- // suivante
- item = null;
- } else if (!simulationManager.isAutoLaunch() && item.param.getInQueue()) {
- // don't use item, because is queue and queue is not launched
- queue.add(item);
- item = null;
- // sleep 1s. Because all other item is in queue too
- // this sleep permit to user to put not queue item,
- // with out eat cpu
- sleep(1000);
- }
- }
+ try {
+ // si l'simItem exist encore (que l'utilisateur ne la pas retire)
+ while (simulationManager.exists(simItem.getPlanIdOrId()) &&
+ simItem.hasNext()) {
+ SimulationItem item = simItem.next();
+ try {
+ String id = item.id;
- log.debug("use if has next simulation: " + item.id);
- if (item.hasNext()) {
- SimulationStorage sim = item.getSimulation();
- String simId = sim.getName();
- log.debug("Start simulation: " + simId);
+ log.debug("Start simulation: " + id);
+ SimulationStorage simulation = item.getSimulation();
SimulationControl control = item.control;
// set date to 0 at beginning of simulation
control.setDate(new Date());
control.setProgress(0);
+ control.setStarted(true);
- simulationManager.fireStartEvent(item.id);
+ simulationManager.fireStartEvent(id, item);
try {
- sim = SimulationHelper.simulate(control, sim);
- item.setLastSimulation(sim);
+ simulation = SimulationHelper.simulate(control, simulation);
+ item.setLastSimulation(simulation);
} finally {
- simulationManager.fireStopEvent(item.id);
+ simulationManager.fireStopEvent(id);
}
// copie les exports de simulation dans le repertoire
// souhaiter par l'utilisateur
- SimulationParameter param = sim.getParameter();
- if (param.getExportNames() != null && param.getExportNames().size() > 0) {
- File exportDir = IsisConfig.getResultExportDirectory(sim.getDirectory());
+ SimulationParameter param = simulation.getParameter();
+ if (param.getExportNames() != null &&
+ param.getExportNames().size() > 0) {
+ File exportDir = IsisConfig.getResultExportDirectory(
+ simulation.getDirectory());
FileUtil.copyAndRenameRecursively(
exportDir,
new File(param.getExportDirectory()),
- exportDir.getName(), item.id);
+ // FIXME, est-ce bien parentId et pas id ?
+ exportDir.getName(), id);
// FileUtil.copyAndRenameRecursively(
// exportDir,
// new File(sim.getDirectory(), IsisConfig.RESULT_EXPORT),
-// IsisConfig.RESULT_EXPORT, item.id);
+// IsisConfig.RESULT_EXPORT, simItem.id);
}
-
- if (item.hasNext() && simulationManager.exists(item.id)) {
- // il y a encore des simulations a faire pour cet item
- // on le remet dans la queue (on ne fait pas les autres
- // simulations de cet item
- // tout de suite car l'item peut-etre un item de queue
- // moins prioritaire que les autres simulations
- // il faut donc qu'il reprenne sa place dans l'ordre)
-
- queue.add(item);
- } else {
- // Si l'utilisateur souhaite seulement les exports
- // on supprimer la/les simulations. Il faut le faire
- // lorsqu'il n'y a plus de next car le calcul des plans
- // peut avoir besoin des simulations precedentes
- if (param.getOnlyExport()) {
- if (param.getUseAnalysePlan()) {
- for(File file : FileUtil.find(
- IsisConfig.getSimulationDirectory(),
- item.id + "_[0-9]+$", false)) {
- log.debug("Delete simulation " + file);
- FileUtil.deleteRecursively(file);
- }
- } else {
- sim.delete(false);
- }
+ // Si l'utilisateur souhaite seulement les exports
+ // on supprimer la/les simulations.
+ // pour les plan dependant il faut le faire apres toutes
+ // les simulations
+ if (simItem.isIndependent() && param.getOnlyExport()) {
+ simulation.delete(false);
+ }
+ // on previent que c la fin de la simulation
+ simulationManager.fireRemoveEvent(id);
+ } catch (Throwable eee) {
+ try {
+ // on sauvegarde l'erreur rencontrée, elle sera traité lors
+ // du fireRemoveEvent
+ item.getSimulation().getInformation().setException(eee);
+ } catch (Exception e) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("isisfish.error.during.simulation.information.file", item.id), eee);
}
+ } finally {
+ // error during simulation, remove bad simulation
simulationManager.fireRemoveEvent(item.id);
-
- if (simulationManager.isAutoLaunch() && item.param.getInQueue()) {
- // if item is last in queue, stop the queue after that
- QueueItem [] items = queue.toArray(new QueueItem[queue.size()]);
- if (items.length > 0) {
- QueueItem last = items[items.length-1];
- if (!last.param.getInQueue()) {
- // la derniere n'est pas en queue, donc plus de simulation en queue
- simulationManager.setAutoLaunch(false);
- }
- } else {
- // aucun simulation, donc forcement plus en queue non plus
- simulationManager.setAutoLaunch(false);
- }
+ if (log.isWarnEnabled()) {
+ log.warn(_("isisfish.error.during.simulation", item.id), eee);
}
}
}
-
-// } catch (Exception eee) {
- } catch (Throwable eee) {
- try {
- // on sauvegarde l'erreur rencontrée, elle sera traité lors
- // du fireRemoveEvent
- item.lastSimulation.getInformation().setException(eee);
- } catch (Exception e) {
- if (log.isWarnEnabled()) {
- log.warn(_("isisfish.error.during.simulation.information.file", item.id), eee);
- }
- } finally {
- // error during simulation, remove bad simulation
- simulationManager.fireRemoveEvent(item.id);
- if (log.isWarnEnabled()) {
- log.warn(_("isisfish.error.during.simulation", item.id), eee);
- }
- }
-
- } finally {
- item = null;
}
+ } catch (Exception eee) {
+ log.error("Can't take next simulation: " + simItem.id, eee);
}
- }
+ // suppression des simulations pour les plans dependants
+ // Si l'utilisateur souhaite seulement les exports
+ // on supprimer la/les simulations. Il faut le faire
+ // lorsqu'il n'y a plus de next car le calcul des plans
+ // peut avoir besoin des simulations precedentes
+ if (!simItem.isIndependent() && simItem.param.getOnlyExport()) {
+ for (File file : FileUtil.find(
+ IsisConfig.getSimulationDirectory(),
+ simItem.id + "_[0-9]+$", false)) {
+ log.debug("Delete simulation " + file);
+ FileUtil.deleteRecursively(file);
+ }
+ }
+
+ if (!simItem.control.isRunning() && simItem.hasSimulation()) {
+ // c'etait la derniere simulation du plan, on arrete le plan
+ simulationManager.fireStopEvent(simItem.id);
+ simulationManager.fireRemoveEvent(simItem.id);
+ }
+ }
}
/**
- * Permet de comparer les simulations pour les ordonner.
- * Les simulations de queue soit moins prioritaire que les autres, ensuite
- * l'ordre se fait sur la date d'arrivé dans la queue de simulation
- *
- * @author poussin
+ * Une simulation a faire sans plan d'experience
*/
- public class QueueItem implements Comparable<QueueItem> {
-
- protected long time;
+ public class SimulationItem {
protected String id;
protected SimulationParameter param;
- protected PlanGenerator plan = null;
+ protected SimulationItemPlan planItem = null;
protected File zip;
protected SimulationControl control;
protected SimulationStorage lastSimulation = null;
- public QueueItem(String id, SimulationParameter param) {
- this.time = System.nanoTime();
+ protected SimulationItem() {
+ }
+
+ public boolean isIndependent() {
+ return true;
+ }
+
+ /**
+ * Utilise pour servir sous simItem pour les items de plan d'experience
+ * @param id
+ * @param control
+ * @param sim
+ */
+ public SimulationItem(SimulationItemPlan planItem, SimulationControl control,
+ SimulationStorage sim) {
+ this.planItem = planItem;
+ this.id = sim.getName();
+ param = sim.getParameter();
+ this.control = control;
+ lastSimulation = sim;
+ }
+
+ /**
+ * Retourne l'id du plan qui a genere cet item, si cet item n'est
+ * pas genere par un plan, retourne directement l'id
+ * @return
+ */
+ public String getPlanIdOrId() {
+ String result = id;
+ if (hasPlanItem()) {
+ result = getPlanItem().id;
+ }
+ return result;
+ }
+
+ public SimulationItemPlan getPlanItem() {
+ return planItem;
+ }
+
+ public boolean hasPlanItem() {
+ boolean result = planItem != null;
+ return result;
+ }
+
+ /**
+ * creer un simItem de simulation et prepare le zip
+ * @param id
+ * @param param
+ */
+ public SimulationItem(String id, SimulationParameter param) {
this.id = id;
this.param = param;
this.control = new SimulationControl(id);
+ zip = SimulationHelper.prepareSimulationZipFile(control, param, true);
+ }
+
+ public boolean hasSimulation() {
+ boolean result = lastSimulation != null;
+ return result;
+ }
+
+ /**
+ * Retourne la simulation qu'il faut faire
+ * @return le storage de simulation
+ * @throws Exception si problème pendant l'import de la simulation
+ */
+ public SimulationStorage getSimulation() throws Exception {
+ if (lastSimulation == null) {
+ lastSimulation = SimulationStorage.importAndRenameZip(zip, id);
+ }
+ return lastSimulation;
+ }
+
+ /**
+ * Appelé apres que la simulation est vraiment eu lieu. On en a besoin
+ * car pour une simulation distante apres la simulation le storage
+ * a ete changé par rapport au storage initialement cree pour la
+ * simulation
+ *
+ * @param lastSimulation The lastSimulation to set.
+ */
+ public void setLastSimulation(SimulationStorage lastSimulation) {
+ this.lastSimulation = lastSimulation;
+ if (hasPlanItem()) {
+ getPlanItem().setLastSimulation(lastSimulation);
+ }
+ }
+
+ /**
+ * @return <code>true</code> s'il y a encore une simulation si on
+ * utilise un plan et qu'il dit qu'il y en a encore, ou si la simulation
+ * n'a pas encore ete faite.
+ */
+ public boolean hasNext() {
+ boolean result;
+ result = !control.isStarted();
+ return result;
+ }
+
+ /**
+ * Ce retourne lui meme, car il n'y a pas de plan
+ * @return
+ */
+ public SimulationItem next() throws Exception {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj instanceof SimulationItem) {
+ result = param.equals(((SimulationItem)obj).param);
+ }
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 3;
+ hash = 53 * hash + (this.param != null ? this.param.hashCode() : 0);
+ return hash;
+ }
+
+ }
+
+ /**
+ * Une simulation a faire qui contient un plan d'experience dependant
+ */
+ public class SimulationItemPlan extends SimulationItem implements PropertyChangeListener {
+ // FIXME a mettre en config MAX_SIMULATION_PLAN
+ // nombre maximal de simulation de plan par simulation
+ // (pour eviter les plans qui ne retroune jamais faux
+ protected static final int MAX_SIMULATION_PLAN = 10000;
+
+ protected int simulationNumber = 0;
+ protected int simulationFinished = 0;
+ protected PlanGenerator plan = null;
+
+ public SimulationItemPlan(String id, SimulationParameter param) {
+ this.id = id;
+ this.param = param;
+ this.control = new SimulationControl(id);
// ne pas inverser la creation de PlanGenerator et du zip.
// car le init des plans est fait dans le constructeur de
// PlanGenerator, et le init peut modifier les parametres
// de simulation
- if (param.getUseAnalysePlan()) {
- plan = new PlanGenerator(id, control, param);
+ if (!param.getUseAnalysePlan()) {
+ throw new SimulationException("Your simulation is not a plan:" + id);
}
+
+ plan = new PlanGenerator(id, control, param);
zip = SimulationHelper.prepareSimulationZipFile(control, param, true);
- if (plan != null) {
- plan.setZip(zip);
- }
+ plan.setZip(zip);
}
+ @Override
+ public boolean isIndependent() {
+ return false;
+ }
+
/**
* Retourne la simulation qu'il faut faire
* @return le storage de simulation
* @throws Exception si problème pendant l'import de la simulation
*/
+ @Override
public SimulationStorage getSimulation() throws Exception {
+ throw new UnsupportedOperationException("Plan item don't have simulation");
+ }
+
+ /**
+ * Retourne la simulation qu'il faut faire
+ * @return le storage de simulation
+ * @throws Exception si problème pendant l'import de la simulation
+ */
+ public SimulationStorage getNextSimulation() throws Exception {
SimulationStorage result;
- if (plan != null) {
- result = plan.next();
- } else {
- result = SimulationStorage.importAndRenameZip(zip, id);
- }
+ result = plan.next();
+ simulationNumber++;
lastSimulation = result;
return result;
}
@@ -512,11 +940,10 @@
*
* @param lastSimulation The lastSimulation to set.
*/
+ @Override
public void setLastSimulation(SimulationStorage lastSimulation) {
this.lastSimulation = lastSimulation;
- if (plan != null) {
- plan.setLastSimulation(lastSimulation);
- }
+ plan.setLastSimulation(lastSimulation);
}
/**
@@ -524,47 +951,66 @@
* utilise un plan et qu'il dit qu'il y en a encore, ou si la simulation
* n'a pas encore ete faite.
*/
+ @Override
public boolean hasNext() {
boolean result;
- result = (plan != null && plan.hasNext()) || lastSimulation == null;
+ result = simulationNumber < MAX_SIMULATION_PLAN &&
+ ((plan != null && plan.hasNext()) || lastSimulation == null);
return result;
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
+ /**
+ * On utilise le meme control pour les plans dependants
+ * @return
*/
@Override
- public boolean equals(Object obj) {
- boolean result = false;
- if (obj instanceof QueueItem) {
- result = param.equals(((QueueItem)obj).param);
- }
+ public SimulationItem next() throws Exception {
+ SimulationStorage sim = getNextSimulation();
+ SimulationItem result = new SimulationItem(this, control, sim);
return result;
}
- /* (non-Javadoc)
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(QueueItem o) {
- int result;
-
- boolean inQueue1 = param.getInQueue();
- boolean inQueue2 = o.param.getInQueue();
- if (inQueue1 == inQueue2) {
- // this et o ont la meme valeur, on compare les temps
- // le plus vieux devant (donc le plus petit)
- result = time<o.time ? -1 : (time==o.time ? 0 : 1);
- } else if (inQueue1) {
- // this est dans la queue donc moins prioritaire
- // on le met donc a la fin
- result = 1;
- } else {
- // o est dans la queue donc moins prioritaire
- result = -1;
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (Boolean.FALSE.equals(evt.getNewValue())) {
+ simulationFinished++;
+ control.setProgress(simulationFinished);
+ control.setText(simulationFinished + " / " + simulationNumber);
+ if (simulationFinished >= simulationNumber) {
+ control.stopSimulation();
+ }
}
+ }
+ }
+
+ /**
+ * Une simulation a faire qui contient un plan d'experience independant
+ */
+ public class SimulationItemPlanIndependent extends SimulationItemPlan {
+
+ public SimulationItemPlanIndependent(String id, SimulationParameter param) {
+ super(id, param);
+ }
+
+ @Override
+ public boolean isIndependent() {
+ return true;
+ }
+
+ /**
+ * On utilise un nouveau control pour les plans independants
+ * @return
+ */
+ @Override
+ public SimulationItem next() throws Exception {
+ SimulationStorage sim = getNextSimulation();
+ control.setProgressMax(simulationNumber);
+ SimulationControl control = new SimulationControl(sim.getName());
+ control.addPropertyChangeListener("running", this);
+ SimulationItem result = new SimulationItem(this, control, sim);
return result;
}
+
}
}
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationParameter.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -127,6 +127,9 @@
/** La simulation doit etre faite en local */
protected boolean local = true;
+ /** La simulation doit etre faite dans un sous process */
+ protected boolean subProcess = false;
+
/** La simulation doit etre lancé dans la queue de simulation (non prioritaire)*/
protected boolean inQueue = false;
@@ -273,6 +276,7 @@
result.setProperty("exports", exportList);
result.setProperty("local", String.valueOf(local));
+ result.setProperty("subProcess", String.valueOf(subProcess));
result.setProperty("inQueue", String.valueOf(inQueue));
result.setProperty("usePreScript", String.valueOf(usePreScript));
result.setProperty("preScript", preScript);
@@ -415,6 +419,7 @@
}
local = Boolean.parseBoolean(props.getProperty("local", "true"));
+ subProcess = Boolean.parseBoolean(props.getProperty("subProcess", "false"));
inQueue = Boolean.parseBoolean(props.getProperty("inQueue", "false"));
usePreScript = Boolean.parseBoolean(props.getProperty("usePreScript",
"false"));
@@ -680,7 +685,14 @@
this.local = local;
}
+ public void setSubProcess(boolean subProcess) {
+ this.subProcess = subProcess;
+ }
+ public boolean isSubProcess() {
+ return subProcess;
+ }
+
/**
* @return Returns the inQueue.
*/
@@ -715,6 +727,17 @@
public boolean getUseStatistic() {
return this.useStatistic;
}
+
+ public boolean isIndependentPlan() {
+ boolean result = true;
+ for (AnalysePlan plan : getAnalysePlans()) {
+ if (!(plan instanceof AnalysePlanIndependent)) {
+ result = false;
+ break;
+ }
+ }
+ return result;
+ }
/**
* @param useStatistic The useStatistic to set.
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModel.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -31,6 +31,9 @@
package fr.ifremer.isisfish.simulator;
+import java.util.ArrayList;
+import java.util.List;
+
/** @author poussin */
public class SimulationQueueModel extends AbstractSimulationQueueModel {
@@ -53,13 +56,13 @@
* @see AbstractSimulationQueueModel at getSimulationIds()
*/
protected java.util.List<String> getSimulationIds() {
- return getQueue().ids;
+ return getQueue().getIds();
}
/* (non-Javadoc)
* @see AbstractSimulationQueueModel at getQueueItemsAsMap()
*/
- protected java.util.Map<String, SimulationManager.QueueItem> getQueueItemsAsMap() {
+ protected java.util.Map<String, SimulationManager.SimulationItem> getQueueItemsAsMap() {
return getQueue().map;
}
@@ -89,18 +92,4 @@
progress.remove(id);
}
- /* (non-Javadoc)
- * @see SimulationQueueListener#simulationStart(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationStart(SimulationQueueEvent e) {
- // nothing to do
- }
-
- /* (non-Javadoc)
- * @see SimulationQueueListener#simulationStop(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationStop(SimulationQueueEvent e) {
- // nothing to do
- }
-
} // SimulationQueueModel
\ No newline at end of file
Deleted: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModelOld.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModelOld.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/simulator/SimulationQueueModelOld.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -1,409 +0,0 @@
-/* *##%
- * Copyright (C) 2006
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-/* *
- * SimulationQueueModel.java
- *
- * Created: 18 août 2006 00:05:41
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package fr.ifremer.isisfish.simulator;
-
-import static org.codelutin.i18n.I18n._;
-
-import java.awt.Component;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.swing.JComponent;
-import javax.swing.JProgressBar;
-import javax.swing.JTable;
-import javax.swing.event.EventListenerList;
-import javax.swing.event.TableModelEvent;
-import javax.swing.event.TableModelListener;
-import javax.swing.table.TableCellRenderer;
-import javax.swing.table.TableModel;
-
-import org.codelutin.log.LutinLog;
-import org.codelutin.log.LutinLogFactory;
-
-
-/**
- * @author poussin
- *
- */
-
-public class SimulationQueueModelOld extends JComponent implements TableModel, SimulationQueueListener, PropertyChangeListener {
-
- /** to use log facility, just put in your code: log.info("..."); */
- static private LutinLog log = LutinLogFactory.getLutinLog(SimulationQueueModel.class);
-
- /** List of listeners */
- protected EventListenerList listenerList = new EventListenerList();
-
- protected SimulationManager queue;
- protected String [] header = new String[]{_("isisfish.queue.id"),_("isisfish.queue.plan"),_("isisfish.queue.name"),_("isisfish.queue.local"),_("isisfish.queue.status"),_("isisfish.queue.progression")};
- protected Class [] columnClass = new Class[]{String.class, String.class, Boolean.class, Boolean.class, String.class, JProgressBar.class};
-
- protected Map<String, JProgressBar> progress = new HashMap<String, JProgressBar>();
-
- /**
- * use SimulationQueue.getInstance() as queue
- */
- public SimulationQueueModelOld() {
- this(SimulationManager.getInstance());
- }
-
- /**
- * if queue is null, then the model used SimulationQueue.getInstance() as queue
- */
- public SimulationQueueModelOld(SimulationManager queue) {
- this.queue = queue;
- if (queue == null) {
- this.queue = SimulationManager.getInstance();
- }
- this.queue.addSimulationQueueListener(this);
-
- // add this model as listener on all already launched simulation
- for (String id : this.queue.ids) {
- SimulationControl control = this.queue.getControl(id);
- if (control != null) {
- control.addPropertyChangeListener(this);
- }
- }
- }
-
- /**
- * @param queue The queue to set.
- */
- public void setQueue(SimulationManager queue) {
- this.queue = queue;
- fireTableDataChanged();
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#getRowCount()
- */
- public int getRowCount() {
- int result = queue.ids.size();
- return result;
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#getColumnCount()
- */
- public int getColumnCount() {
- return header.length;
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.AbstractTableModel#getColumnName(int)
- */
- public String getColumnName(int column) {
- return header[column];
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
- */
- public Class<?> getColumnClass(int columnIndex) {
- return columnClass[columnIndex];
- }
-
- public SimulationControl getSimulationControl(int rowIndex) {
- SimulationControl result = null;
- if (rowIndex >= 0) {
- String id = queue.ids.get(rowIndex);
- result = queue.getControl(id);
- } else {
- log.user(_("isisfish.error.invalide.simulation.index"));
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#getValueAt(int, int)
- */
- public Object getValueAt(int rowIndex, int columnIndex) {
- Object result = "";
- if (rowIndex >= queue.ids.size()) {
- return "error";
- }
- String id = queue.ids.get(rowIndex);
- SimulationControl control = queue.getControl(id);
- switch (columnIndex) {
- case 0:
- result = id;
- break;
- case 1:
- int number = queue.getParameter(id).getAnalysePlanNumber();
- if (number >= 0) {
- result = number;
- } else {
- result = _("isisfish.common.no");
- }
- break;
- case 2:
- result = queue.getParameter(id).getInQueue();
- break;
- case 3:
- result = queue.getParameter(id).getLocal();
- break;
- case 4:
- if (control != null) {
- if (control.isStopSimulationRequest()) {
- result = _("isisfish.launch.stop");
- } else {
- result = control.getText();
- }
- }
- break;
- case 5:
- JProgressBar pb = getProgressBar(id);
- if (control != null) {
- pb.setMaximum(control.getProgressMax());
- pb.setValue(control.getProgress());
- pb.setString(control.date.getMonth() + "/" + control.date.getYear());
- }
- result = pb;
- break;
- }
- return result;
- }
-
- protected JProgressBar getProgressBar(String id) {
- JProgressBar result = progress.get(id);
- if (result == null) {
- result = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
- result.setStringPainted(true);
- progress.put(id, result);
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent evt) {
- SimulationControl control = (SimulationControl)evt.getSource();
- int row = queue.ids.indexOf(control.getId());
- fireTableRowsUpdated(row, row);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.simulator.SimulationQueueListener#simulationAdded(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationAdded(SimulationQueueEvent e) {
- int row = getRowCount();
- fireTableRowsInserted(row, row);
- SimulationControl control = queue.getControl(e.getId());
- control.addPropertyChangeListener(this);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.simulator.SimulationQueueListener#simulationRemoved(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationWillBeRemoved(SimulationQueueEvent e) {
- String id = e.getId();
-
- SimulationControl control = queue.getControl(id);
- if (control != null) {
- control.removePropertyChangeListener(this);
- }
-
- int row = queue.ids.indexOf(id);
- fireTableRowsDeleted(row, row);
- progress.remove(id);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.simulator.SimulationQueueListener#simulationStart(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationStart(SimulationQueueEvent e) {
- // nothing to do
- }
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.simulator.SimulationQueueListener#simulationStop(fr.ifremer.isisfish.simulator.SimulationQueueEvent)
- */
- public void simulationStop(SimulationQueueEvent e) {
- // nothing to do
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#isCellEditable(int, int)
- */
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return false;
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
- */
- public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#addTableModelListener(javax.swing.event.TableModelListener)
- */
- public void addTableModelListener(TableModelListener l) {
- listenerList.add(TableModelListener.class, l);
- if (l instanceof JTable) {
- ((JTable)l).setDefaultRenderer(JProgressBar.class, new JProgressBarTableCellRenderer());
- }
-
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#removeTableModelListener(javax.swing.event.TableModelListener)
- */
- public void removeTableModelListener(TableModelListener l) {
- listenerList.remove(TableModelListener.class, l);
- }
-
- /**
- * Notifies all listeners that all cell values in the table's
- * rows may have changed. The number of rows may also have changed
- * and the <code>JTable</code> should redraw the
- * table from scratch. The structure of the table (as in the order of the
- * columns) is assumed to be the same.
- *
- * @see TableModelEvent
- * @see EventListenerList
- * @see JTable#tableChanged(TableModelEvent)
- */
- public void fireTableDataChanged() {
- fireTableChanged(new TableModelEvent(this));
- }
-
- /**
- * Notifies all listeners that the table's structure has changed.
- * The number of columns in the table, and the names and types of
- * the new columns may be different from the previous state.
- * If the <code>JTable</code> receives this event and its
- * <code>autoCreateColumnsFromModel</code>
- * flag is set it discards any table columns that it had and reallocates
- * default columns in the order they appear in the model. This is the
- * same as calling <code>setModel(TableModel)</code> on the
- * <code>JTable</code>.
- *
- * @see TableModelEvent
- * @see EventListenerList
- */
- public void fireTableStructureChanged() {
- fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
- }
-
- /**
- * Notifies all listeners that rows in the range
- * <code>[firstRow, lastRow]</code>, inclusive, have been inserted.
- *
- * @param firstRow the first row
- * @param lastRow the last row
- *
- * @see TableModelEvent
- * @see EventListenerList
- *
- */
- public void fireTableRowsInserted(int firstRow, int lastRow) {
- fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
- TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
- }
-
- /**
- * Notifies all listeners that rows in the range
- * <code>[firstRow, lastRow]</code>, inclusive, have been updated.
- *
- * @param firstRow the first row
- * @param lastRow the last row
- *
- * @see TableModelEvent
- * @see EventListenerList
- */
- public void fireTableRowsUpdated(int firstRow, int lastRow) {
- fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
- TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
- }
-
- /**
- * Notifies all listeners that rows in the range
- * <code>[firstRow, lastRow]</code>, inclusive, have been deleted.
- *
- * @param firstRow the first row
- * @param lastRow the last row
- *
- * @see TableModelEvent
- * @see EventListenerList
- */
- public void fireTableRowsDeleted(int firstRow, int lastRow) {
- fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
- TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
- }
-
- /**
- * Notifies all listeners that the value of the cell at
- * <code>[row, column]</code> has been updated.
- *
- * @param row row of cell which has been updated
- * @param column column of cell which has been updated
- * @see TableModelEvent
- * @see EventListenerList
- */
- public void fireTableCellUpdated(int row, int column) {
- fireTableChanged(new TableModelEvent(this, row, row, column));
- }
-
- /**
- * Forwards the given notification event to all
- * <code>TableModelListeners</code> that registered
- * themselves as listeners for this table model.
- *
- * @param e the event to be forwarded
- *
- * @see #addTableModelListener
- * @see TableModelEvent
- * @see EventListenerList
- */
- public void fireTableChanged(TableModelEvent e) {
- // Guaranteed to return a non-null array
- Object[] listeners = listenerList.getListenerList();
- // Process the listeners last to first, notifying
- // those that are interested in this event
- for (int i = listeners.length-2; i>=0; i-=2) {
- if (listeners[i]==TableModelListener.class) {
- ((TableModelListener)listeners[i+1]).tableChanged(e);
- }
- }
- }
-
-
- public class JProgressBarTableCellRenderer implements TableCellRenderer {
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- return (JProgressBar)value;
- }
- }// JProgressBarTableCellRenderer
-
-}
\ No newline at end of file
Modified: branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java
===================================================================
--- branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java 2008-08-07 17:05:40 UTC (rev 1290)
+++ branches/isis-fish-3.1.4/src/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java 2008-08-07 19:38:45 UTC (rev 1291)
@@ -115,8 +115,10 @@
* <code>false</code> otherwise
*/
public static boolean isSimulStartButtonEnabled(JTable table) {
- return !SimulationManager.getInstance().isAutoLaunch() &&
- (table.getRowCount() > 0);
+ return false;
+ // L'auto launche a disparu maintenant
+// return !SimulationManager.getInstance().isAutoLaunch() &&
+// (table.getRowCount() > 0);
}
/**
1
0
Author: bpoussin
Date: 2008-08-07 17:05:40 +0000 (Thu, 07 Aug 2008)
New Revision: 1290
Added:
branches/isis-fish-3.1.3/
Log:
sauvegarde de la version 3.1.3 avant
de casser le mecanisme de simulation
Copied: branches/isis-fish-3.1.3 (from rev 1289, branches/isis-fish-3.1.4)
1
0
Author: bpoussin
Date: 2008-08-05 20:17:04 +0000 (Tue, 05 Aug 2008)
New Revision: 1289
Removed:
branches/3.1.4/
Log:
repertoire vide maintenant
1
0
Author: bpoussin
Date: 2008-08-05 20:16:32 +0000 (Tue, 05 Aug 2008)
New Revision: 1288
Added:
branches/isis-fish-3.1.4/
Removed:
branches/3.1.4/isis-fish/
Log:
en fait comme la dit eric, c plus logique d'avoir le numero apres que avant
Copied: branches/isis-fish-3.1.4 (from rev 1287, branches/3.1.4/isis-fish)
1
0
Author: bpoussin
Date: 2008-08-05 20:14:53 +0000 (Tue, 05 Aug 2008)
New Revision: 1287
Removed:
branches/3.1.4/mod/
Log:
suppression de mod qui est vide et donc pas vraiment necessaire dans la branche
1
0
Author: bpoussin
Date: 2008-08-05 20:14:18 +0000 (Tue, 05 Aug 2008)
New Revision: 1286
Removed:
branches/3.1.4/isis-fish-data/
Log:
suppression du repertoire isis-fish-data qui a sont propre projet
1
0
Author: bpoussin
Date: 2008-08-05 20:13:46 +0000 (Tue, 05 Aug 2008)
New Revision: 1285
Removed:
branches/3.1.4/CVSROOT/
Log:
suppression du repertoire CVSROOT
1
0