public FilePackageStorable(FilePackage filePackage) {
   this.filePackage = filePackage;
   links = new ArrayList<DownloadLinkStorable>(filePackage.size());
   boolean readL = filePackage.getModifyLock().readLock();
   try {
     for (DownloadLink link : filePackage.getChildren()) {
       links.add(new DownloadLinkStorable(link));
     }
   } finally {
     filePackage.getModifyLock().readUnlock(readL);
   }
 }
Beispiel #2
0
  @SuppressWarnings("rawtypes")
  private PollingResultAPIStorable getDownloadProgress() {

    // get packageUUIDs who should be filled with download progress of the containing links e.g
    // because they are expanded in the
    // view
    List<Long> expandedPackageUUIDs = new ArrayList<Long>();
    if (!queryParams._getQueryParam("downloadProgress", List.class, new ArrayList()).isEmpty()) {
      List uuidsFromQuery =
          queryParams._getQueryParam("downloadProgress", List.class, new ArrayList());
      for (Object o : uuidsFromQuery) {
        try {
          expandedPackageUUIDs.add((Long) o);
        } catch (ClassCastException e) {
          continue;
        }
      }
    }

    PollingResultAPIStorable prs = new PollingResultAPIStorable();
    prs.setEventName("downloadProgress");

    List<PollingAPIFilePackageStorable> fpas = new ArrayList<PollingAPIFilePackageStorable>();

    for (FilePackage fp : dwd.getRunningFilePackages()) {
      PollingAPIFilePackageStorable fps = new PollingAPIFilePackageStorable(fp);
      fps.setSpeed(dwd.getDownloadSpeedbyFilePackage(fp));

      // if packages is expanded in view, current state of all running links inside the package
      if (expandedPackageUUIDs.contains(fp.getUniqueID().getID())) {
        boolean readL = fp.getModifyLock().readLock();
        try {
          for (DownloadLink dl : fp.getChildren()) {
            if (dwd.getRunningDownloadLinks().contains(dl.getDownloadLinkController())) {
              PollingAPIDownloadLinkStorable pdls = new PollingAPIDownloadLinkStorable(dl);
              fps.getLinks().add(pdls);
            }
          }
        } finally {
          fp.getModifyLock().readUnlock(readL);
        }
      }
      fpas.add(fps);
    }

    org.jdownloader.myjdownloader.client.json.JsonMap eventData =
        new org.jdownloader.myjdownloader.client.json.JsonMap();
    eventData.put("data", fpas);
    prs.setEventData(eventData);

    return prs;
  }
  @Override
  public void onDownloadControllerUpdatedData(DownloadLink dl, DownloadLinkProperty property) {

    if (property != null) {
      FilePackage parent = dl.getParentNode();
      HashMap<String, Object> dls = null;
      // [DATA_UPDATE.extractionStatus, DATA_UPDATE.finished, DATA_UPDATE.priority,
      // DATA_UPDATE.speed, DATA_UPDATE.url,
      // DATA_UPDATE.enabled, DATA_UPDATE.skipped, DATA_UPDATE.running, DATA_UPDATE.bytesLoaded,
      // DATA_UPDATE.eta,
      // DATA_UPDATE.maxResults, DATA_UPDATE.packageUUIDs, DATA_UPDATE.host, DATA_UPDATE.comment,
      // DATA_UPDATE.bytesTotal,
      // DATA_UPDATE.startAt, DATA_UPDATE.status]
      System.out.println("Property Change: " + property.getProperty());
      switch (property.getProperty()) {
        case ARCHIVE:
          break;
        case ARCHIVE_ID:
          // //archive properties changed;
          break;

        case AVAILABILITY:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("availability", property.getValue());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".availability",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".availability." + dl.getUniqueID().getID());
          break;
        case CHUNKS:
          break;
        case COMMENT:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("comment", property.getValue());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".comment",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".comment." + dl.getUniqueID().getID());
          break;
        case URL_CONTAINER:
        case URL_ORIGIN:
        case URL_REFERRER:
        case URL_CONTENT:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("url", dl.getView().getDisplayUrl());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".url",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".url." + dl.getUniqueID().getID());

          break;
        case CONDITIONAL_SKIPPED:
          pushStatus(dl);
          break;
        case DOWNLOAD_PASSWORD:
          break;
        case DOWNLOADSIZE:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("bytesTotal", property.getValue());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".bytesTotal",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".bytesTotal." + dl.getUniqueID().getID());
          break;
        case DOWNLOADSIZE_VERIFIED:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("bytesTotal", property.getValue());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".bytesTotal",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".bytesTotal." + dl.getUniqueID().getID());
          break;
        case DOWNLOAD_CONTROLLER:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("running", property.getValue() != null);
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".running",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".running." + dl.getUniqueID().getID());
          dls = new HashMap<String, Object>();
          dls.put("uuid", parent.getUniqueID().getID());
          dls.put(
              "running",
              property.getValue() != null
                  || DownloadWatchDog.getInstance().hasRunningDownloads(parent));
          fire(
              BASIC_EVENT.PACKAGE_UPDATE.name() + ".running",
              dls,
              BASIC_EVENT.PACKAGE_UPDATE.name() + ".running." + parent.getUniqueID().getID());
          break;
        case ENABLED:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          boolean enabled = dl.isEnabled();
          dls.put("enabled", enabled);
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".enabled",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".enabled." + dl.getUniqueID().getID());
          dls = new HashMap<String, Object>();
          dls.put("uuid", parent.getUniqueID().getID());
          if (enabled == false) {
            final boolean readL = parent.getModifyLock().readLock();
            try {
              for (DownloadLink link : parent.getChildren()) {
                if (link.isEnabled()) {
                  enabled = true;
                  break;
                }
              }
            } finally {
              parent.getModifyLock().readUnlock(readL);
            }
          }
          dls.put("enabled", enabled);
          fire(
              BASIC_EVENT.PACKAGE_UPDATE.name() + ".enabled",
              dls,
              BASIC_EVENT.PACKAGE_UPDATE.name() + ".enabled." + parent.getUniqueID().getID());
          break;
        case EXTRACTION_STATUS:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          ExtractionStatus es = dl.getExtractionStatus();
          dls.put("extractionStatus", es == null ? null : es.toString());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".extractionStatus",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".extractionStatus." + dl.getUniqueID().getID());

          pushStatus(dl);
          break;
        case FINAL_STATE:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("finished", (FinalLinkState.CheckFinished(dl.getFinalLinkState())));
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".finished",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".finished." + dl.getUniqueID().getID());

          final FinalLinkState finalLinkState = dl.getFinalLinkState();

          pushStatus(dl);

          break;
        case LINKSTATUS:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("status", property.getValue());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".status",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".status." + dl.getUniqueID().getID());

          break;
        case MD5:
          break;
        case NAME:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("name", dl.getView().getDisplayName());
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".name",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".name." + dl.getUniqueID().getID());

          break;
        case PLUGIN_PROGRESS:
          synchronized (linksWithPluginProgress) {
            if (dl.getPluginProgress() == null) {
              linksWithPluginProgress.remove(dl.getUniqueID().getID());
              pushDiff(dl);
              cleanup(dl);
            } else {
              linksWithPluginProgress.put(dl.getUniqueID().getID(), dl);
              updateExecuter(true);
            }
          }
          break;
        case PRIORITY:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put(
              "priority",
              org.jdownloader.myjdownloader.client.bindings.PriorityStorable.valueOf(
                  dl.getPriorityEnum().name()));
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".priority",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".priority." + dl.getUniqueID().getID());

          break;
        case RESET:
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("reset", "true");
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".reset",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".reset." + dl.getUniqueID().getID());

          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("reset", "true");
          fire(
              BASIC_EVENT.PACKAGE_UPDATE.name() + ".reset",
              dls,
              BASIC_EVENT.PACKAGE_UPDATE.name() + ".reset." + parent.getUniqueID().getID());
          break;
        case RESUMABLE:
          break;
        case SHA1:
          break;
        case SHA256:
          break;
        case SKIPPED:
          pushStatus(dl);
          dls = new HashMap<String, Object>();
          dls.put("uuid", dl.getUniqueID().getID());
          dls.put("skipped", property.getValue() != null);
          if (property.getValue() != null) {
            dls.put("skipreason", property.getValue().toString());
          }
          fire(
              BASIC_EVENT.LINK_UPDATE.name() + ".skipped",
              dls,
              BASIC_EVENT.LINK_UPDATE.name() + ".skipped." + dl.getUniqueID().getID());
          break;
        case SPEED_LIMIT:
          break;
        case URL_PROTECTION:
          break;
        case VARIANT:
          break;
        case VARIANTS:
          break;
        case VARIANTS_ENABLED:
          break;
      }
    }
    long newContentChangesCounter = DownloadController.getInstance().getContentChanges();
    if (newContentChangesCounter != this.contentChangesCounter) {
      // avoid dupes
      this.contentChangesCounter = newContentChangesCounter;
      fire(BASIC_EVENT.REFRESH_CONTENT.name(), null, BASIC_EVENT.REFRESH_CONTENT.name());
    }
    flushBuffer();
  }