예제 #1
0
  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
  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
  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
  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;
  }