public boolean checkLink(DownloadLink link) {
        if (isDeleteAll()) {
            return true;
        }

        if (isDeleteDisabled() && !link.isEnabled()) {

            return true;
        }
        if (isDeleteFailed() && FinalLinkState.CheckFailed(link.getFinalLinkState())) {

            return true;
        }
        if (isDeleteFinished() && FinalLinkState.CheckFinished(link.getFinalLinkState())) {

            return true;
        }
        if (isDeleteFinishedPackage() && link.getFilePackage().getView().isFinished()) {
            return true;

        }
        if (isDeleteOffline() && link.getFinalLinkState() == FinalLinkState.OFFLINE) {

            return true;
        }
        return false;
    }
Example #2
0
    public AggregatedNumbers(SelectionInfo<FilePackage, DownloadLink> selection) {
        totalBytes = 0l;
        disabledTotalBytes = 0l;
        disabledLoadedBytes = 0l;

        loadedBytes = 0l;
        downloadSpeed = 0l;
        running = 0l;
        connections = 0l;
        packageCount = selection.getPackageViews().size();
        linkCount = selection.getChildren().size();
        downloadsFinished = 0l;
        downloadsFailed = 0l;
        downloadsSkipped = 0l;
        disabledDownloadsFinished = 0l;
        disabledDownloadsFailed = 0l;
        disabledDownloadsSkipped = 0l;
        for (DownloadLink dl : selection.getChildren()) {
            if (dl == null) continue;

            if (dl.isEnabled()) {
                FinalLinkState state = dl.getFinalLinkState();
                if (state == null) {
                    if (dl.isSkipped()) {
                        downloadsSkipped++;
                    }
                } else {
                    if (state.isFailed()) {
                        downloadsFailed++;
                    } else if (state.isFinished()) {
                        downloadsFinished++;
                    }
                }
                totalBytes += dl.getView().getBytesTotalEstimated();
                loadedBytes += dl.getView().getBytesLoaded();

            } else {
                FinalLinkState state = dl.getFinalLinkState();
                if (state == null) {
                    if (dl.isSkipped()) {
                        disabledDownloadsSkipped++;
                    }
                } else {
                    if (state.isFailed()) {
                        disabledDownloadsFailed++;
                    } else if (state.isFinished()) {
                        disabledDownloadsFinished++;
                    }
                }
                disabledTotalBytes += dl.getView().getBytesTotalEstimated();
                disabledLoadedBytes += dl.getView().getBytesLoaded();

            }

            downloadSpeed += dl.getView().getSpeedBps();
            SingleDownloadController sdc = dl.getDownloadLinkController();
            if (sdc != null) {
                running++;
                DownloadInterface conInst = sdc.getDownloadInstance();
                if (conInst != null) {
                    ManagedThrottledConnectionHandler handlerP = conInst.getManagedConnetionHandler();
                    if (handlerP != null) {
                        connections += handlerP.size();

                    }

                }
            }

        }

        eta = downloadSpeed == 0 ? 0 : (totalBytes - loadedBytes) / downloadSpeed;

    }
Example #3
0
 public static boolean CheckFailed(FinalLinkState state) {
     return state != null && state.isFailed();
 }
  @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();
  }