Example #1
0
 private PoolSummary compilePoolSummary(Pool pool) {
   PoolSummary.Builder poolSummaryBuilder = aPoolSummary().withPoolName(pool.getName());
   for (Device device : pool.getDevices()) {
     compileResultsForDevice(pool, poolSummaryBuilder, device);
   }
   Device watchdog = getPoolWatchdog(pool.getName());
   compileResultsForDevice(pool, poolSummaryBuilder, watchdog);
   return poolSummaryBuilder.build();
 }
Example #2
0
 /**
  * get all worksite
  *
  * @return
  */
 public WorkSite[] batch() {
   WorkSite[] sites = null;
   super.lockMulti();
   try {
     int size = mapSite.size();
     if (size > 0) {
       sites = new WorkSite[size];
       mapSite.values().toArray(sites);
     }
   } catch (Throwable exp) {
     Logger.fatal(exp);
   } finally {
     super.unlockMulti();
   }
   return sites;
 }
Example #3
0
  @Test
  public void testPools() {
    try {
      int expected = getDataSet().getTable("Pool").getRowCount();

      int actual = getPoolDAO().count();

      TestCase.assertEquals("Wrong number of Pools", expected, actual);
      System.out.println("Expected number of Pools: " + expected + ", actual: " + actual);

      for (Pool d : random(getPoolDAO(), actual, 1)) {
        TestCase.assertNotNull(d);
        TestCase.assertNotNull(d.getId());
      }
    } catch (Exception e) {
      e.printStackTrace();
      TestCase.fail();
    }
  }
Example #4
0
  /** check timeout site */
  private void check() {
    int size = mapTime.size();
    if (size == 0) return;

    ArrayList<SiteHost> dels = new ArrayList<SiteHost>(size);
    ArrayList<SiteHost> notifys = new ArrayList<SiteHost>(size);
    super.lockSingle();
    try {
      long nowTime = System.currentTimeMillis();
      for (SiteHost host : mapTime.keySet()) {
        Long value = mapTime.get(host);
        if (value == null) {
          dels.add(host);
          continue;
        }
        long time = value.longValue();
        if (nowTime - time >= deleteTime) {
          dels.add(host);
        } else if (nowTime - time >= refreshTimeout) {
          notifys.add(host);
        }
      }
    } catch (Throwable exp) {
      exp.printStackTrace();
    } finally {
      super.unlockSingle();
    }
    // remove timeout site
    for (SiteHost host : dels) {
      Logger.error("WorkPool.check, delete timeout site:%s", host);
      remove(host);
    }
    // notify site
    SiteHost listen = Launcher.getInstance().getLocalHost();
    for (SiteHost host : notifys) {
      Logger.warning("WorkPool.check, notify timeout site:%s", host);
      this.sendTimeout(host, listen, 2);
    }
  }
Example #5
0
  public void start() {
    inputs = new AtomicReferenceArray<>(0);
    outputs = inputs;
    freeReceptors = new CopyOnWriteArrayList<>();
    sequence = 0;
    finalSequence = 0;
    finalProduct = null;
    reuseReceptors = new ArrayList<>(0);
    executor = Executors.newSingleThreadExecutor();

    started = true;
    if (poolSize > 0) {
      group = new ThreadGroup("FatPipe");
      group.setMaxPriority(Thread.MAX_PRIORITY);
    }
    signals = new SignalImpl[ARBITARY_THREADS + poolSize];
    threads = new Thread[ARBITARY_THREADS + poolSize];
    startTime = System.currentTimeMillis();
    sleptTime = 0;
    toSleepTime = 0;

    for (int i = 0; i < poolSize; i++) {
      Thread t = new Thread(group, this, name + "-" + i);
      t.setDaemon(true);
      threads[i] = t;
      t.start();
      if (sleep == 0) t.setPriority(Thread.MAX_PRIORITY);
      else if (sleep < 0) t.setPriority(Thread.NORM_PRIORITY);
      else t.setPriority(Thread.MIN_PRIORITY);
    }
    for (int i = 0; i < signals.length; i++) {
      signals[i] = new SignalImpl(lock);
    }
    if (pool != null) pool.add(this);
    lock.release();
  }
  public JSONObject saveImportedElements(HttpSession session, JSONObject json) {
    if (json.has("elements")) {
      Plate currentPlate = null;
      Pool currentPool = null;

      try {
        String description = json.getString("description");
        String creationDate = json.getString("creationDate");
        String plateMaterialType = null;
        if (json.has("plateMaterialType") && !json.getString("plateMaterialType").equals("")) {
          plateMaterialType = json.getString("plateMaterialType");
        }

        JSONObject elements = json.getJSONObject("elements");
        JSONArray pools = JSONArray.fromObject(elements.get("pools"));
        JSONArray savedPlates = new JSONArray();
        ObjectMapper mapper = new ObjectMapper();

        for (JSONArray innerPoolList : (Iterable<JSONArray>) pools) {
          for (JSONObject pool : (Iterable<JSONObject>) innerPoolList) {
            log.info(pool.toString());

            PlatePool platePool =
                mapper.readValue(pool.toString(), new TypeReference<PlatePool>() {});
            currentPool = platePool;

            for (Plate<LinkedList<Library>, Library> plate : platePool.getPoolableElements()) {
              JSONObject j = new JSONObject();

              //              if (json.has("tagBarcode")) {
              //                String tagBarcode = json.getString("tagBarcode");
              //
              // plate.setTagBarcode(requestManager.listAllTagBarcodesByStrategyName());
              //              }

              if (plate.getDescription() == null) {
                plate.setDescription(description);
              }

              if (plate.getCreationDate() == null) {
                // plate.setCreationDate(DateFormat.getInstance().parse(creationDate));
              }

              if (plate.getPlateMaterialType() == null && plateMaterialType != null) {
                plate.setPlateMaterialType(PlateMaterialType.valueOf(plateMaterialType));
              }
              log.info("Saving plate: " + plate.toString());
              currentPlate = plate;
              long plateId = requestManager.savePlate(plate);
              j.put("plateId", plateId);
              savedPlates.add(j);
              currentPlate = null;
            }

            log.info("Saving pool: " + pool.toString());
            requestManager.savePool(platePool);
            currentPool = null;
          }
        }
        JSONObject resp = new JSONObject();
        resp.put("plates", savedPlates);
        return resp;
      } catch (IOException e) {
        if (currentPool != null) {
          log.error(
              "Error saving pool elements on new plate save. Deleting pool "
                  + currentPool.toString());
          // clear out child elements to make sure plate meets delete requirements
          currentPool.getPoolableElements().clear();
          try {
            requestManager.deletePool(currentPool);
          } catch (IOException e1) {
            log.error("Cannot delete pool. Nothing left to do.");
            e1.printStackTrace();
          }
        }

        if (currentPlate != null) {
          log.error(
              "Error saving plate elements on new plate save. Deleting plate "
                  + currentPlate.toString());
          // clear out child elements to make sure plate meets delete requirements
          currentPlate.getElements().clear();
          try {
            requestManager.deletePlate(currentPlate);
          } catch (IOException e1) {
            log.error("Cannot delete plate. Nothing left to do.");
            e1.printStackTrace();
          }
        }

        log.error("Caused by...");
        e.printStackTrace();
        return JSONUtils.SimpleJSONError("Cannot save imported plate: " + e.getMessage());
      }
    } else {
      return JSONUtils.SimpleJSONError("No valid plates available to save");
    }
  }