コード例 #1
0
ファイル: ChecksumWorker.java プロジェクト: BvK200/DNSCore
 /**
  * Updates the Copy with found checksum
  *
  * @param copy
  * @param checksum
  */
 private synchronized void updateCopy(Copy copy, String checksum) {
   Session session = HibernateUtil.openSession();
   session.beginTransaction();
   copy.setChecksumDate(new Date());
   copy.setChecksum(checksum);
   session.update(copy);
   session.getTransaction().commit();
   session.close();
 }
コード例 #2
0
ファイル: ChecksumWorker.java プロジェクト: BvK200/DNSCore
  /**
   * Re-Computing Checksum for Copies
   *
   * @author Jens Peters
   */
  @Override
  public void scheduleTaskImplementation() {
    GregorianCalendar cal = new GregorianCalendar();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int numCopyjobs = getNumCopyjobs(hour);

    logger.debug(
        "number of copyjobs: current=" + numCopyjobs + " & allowed=" + allowedNumOfCopyjobs);
    logger.debug(
        "current time: " + hour + "; allowed time: " + startTime + " - " + endTime + " hour");

    if (allowedTime(hour) || numCopyjobs <= allowedNumOfCopyjobs) {
      try {
        Copy copy = null;
        if ((copy = fetchCopy(node.getId())) == null) {
          logger.warn("Found no copy in custody to compute Checksum for ...");
          return;
        }
        if (secondaryCopyPrefix == null) {
          logger.error("SecondaryCopyPrefix is null");
          return;
        }
        String dest = secondaryCopyPrefix + "/" + copy.getPath();
        logger.info("Checking existence in custody " + dest);
        if (gridFacade.exists(dest)) {
          Calendar oneMonthAgo = Calendar.getInstance();
          oneMonthAgo.add(Calendar.DAY_OF_YEAR, trustChecksumForDays * (-1));
          logger.debug("will look for Checksums older than " + oneMonthAgo.getTime());
          String cs = "";
          if (copy.getChecksumDate() == null) {
            cs = gridFacade.reComputeAndGetChecksumInCustody(dest);
            logger.info("checksum in custody is " + cs + " for " + dest);
          } else if (copy.getChecksumDate().before(oneMonthAgo.getTime())) {
            cs = gridFacade.reComputeAndGetChecksumInCustody(dest);
            logger.info("recompute old checksum in custody, now is " + cs + " for " + dest);
          } else {
            cs = copy.getChecksum();
            logger.info("Checksum does not yet need recomputation. Checksum is " + cs);
          }
          updateCopy(copy, cs);

        } else logger.error(dest + " does not exist.");

      } catch (Exception e) {
        logger.error("Error in ChecksumWorker " + e.getMessage(), e);
      }
    } else {
      logger.debug("Skipping copy checking ...");
    }
  }