コード例 #1
0
ファイル: MainAction.java プロジェクト: vitorchaud/ReMoto
  public Simulation recoverStoredSimulation(HttpServletRequest req, int idConfiguration) {
    if (idConfiguration == ReMoto.idGuestUser) return null;

    FileInputStream fis = null;
    ObjectInputStream in = null;
    Simulation sim = null;

    try {
      fis = new FileInputStream(ReMoto.path + "store/" + idConfiguration + ".sim");
      in = new ObjectInputStream(fis);
      sim = (Simulation) in.readObject();
      in.close();

      String oldCdSimulation = sim.getCdSimulation();
      String newCdSimulation = getCdSimulation(req, idConfiguration);

      if (!oldCdSimulation.equals(newCdSimulation)) {
        ReMoto.simulations.remove(oldCdSimulation);
      }

      sim.setCdSimulation(newCdSimulation);
      ReMoto.simulations.put(newCdSimulation, sim);
    } catch (FileNotFoundException e) {
      // Simulation was not stored
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return sim;
  }
コード例 #2
0
ファイル: MainAction.java プロジェクト: vitorchaud/ReMoto
  public void cleanSimulation(HttpServletRequest req) {
    User user = getUser(req);

    if (user == null) return;

    Iterator it = ReMoto.simulations.values().iterator();

    while (it.hasNext()) {
      Simulation sim = (Simulation) it.next();

      if (sim.getStatus() != Simulation.SIM_RUNNING) {
        Date dateSim = sim.getDateFinish();
        Date dateNow = new Date();

        // TRECHO PROVISORIAMENTE COMENTADO
        /*
        // Remove old simulations - time in milliseconds
        if( user.getCdUser().equals( ReMoto.cdGuestUser ) )
        {
        	// Keep during 30 minutes
        	if( dateNow.getTime() > dateSim.getTime() + 1000 * 60 * 30 )
        		it.remove();
        }
        else
        {
        	// Keep during 12 hours
        	if( dateNow.getTime() > dateSim.getTime() + 1000 * 60 * 60 * 12 )
        		it.remove();
        }
        */

      }
    }
  }
コード例 #3
0
ファイル: MainAction.java プロジェクト: vitorchaud/ReMoto
  public boolean isThereSimulationRunning(HttpServletRequest req) {
    int numSims = 0;
    Iterator it = ReMoto.simulations.values().iterator();

    while (it.hasNext()) {
      Simulation sim = (Simulation) it.next();

      if (sim.getStatus() == Simulation.SIM_RUNNING) {
        numSims = numSims + 1;
      }
    }

    System.out.println("numSims: " + numSims);

    if (numSims >= 4) return true;

    return false;
  }
コード例 #4
0
ファイル: MainAction.java プロジェクト: vitorchaud/ReMoto
  public Configuration loadConfiguration(HttpServletRequest req, int idConfiguration) {
    User user = getUser(req);

    if (idConfiguration < 0) {
      idConfiguration = user.getIdConfigurationDefault();
    }

    Simulation sim = getSimulation(req, idConfiguration);
    Configuration conf = null;

    if (sim != null) conf = sim.getConfiguration();

    // Load configuration properties
    if (conf == null) {
      ConfigurationDAO confDAO = new ConfigurationDAO();

      conf = confDAO.getConfiguration(idConfiguration);
    }

    req.getSession().setAttribute("configuration", conf);

    return conf;
  }