示例#1
0
  @Override
  public void handleEvent(TorrentEvent event) {
    if (event == TorrentEvent.STOPPED) {
      if (!finished.get()) {
        cancel();
      } else {
        remove();
      }
    } else if (event == TorrentEvent.STATUS_CHANGED) {
      // considered to be finished uploading if seed ratio has been
      // reached
      boolean finished = torrent.isFinished();
      float seedRatio = torrent.getSeedRatio();
      TorrentStatus status = torrent.getStatus();
      int seedTime = status != null ? status.getSeedingTime() : 0;

      float targetSeedRatio = torrentManager.getTorrentManagerSettings().getSeedRatioLimit();
      int targetSeedTime = torrentManager.getTorrentManagerSettings().getSeedTimeLimit();

      if (finished && (seedRatio >= targetSeedRatio || seedTime >= targetSeedTime)) {
        this.finished.set(true);
        torrent.stop();
      }
    }
  }
示例#2
0
  @Override
  public boolean isInactive() {

    if (torrent.getStatus().isPaused() || torrent.getStatus().isFinished()) {
      return true;
    }

    return false;
  }
示例#3
0
 @Override
 public String getCustomIconDescriptor() {
   if (torrent.isSingleFileTorrent()) {
     return null;
   }
   return BITTORRENT_UPLOAD;
 }
示例#4
0
  @Override
  public UploadStatus getState() {
    if (cancelled.get()) {
      return UploadStatus.CANCELLED;
    }

    if (finished.get()) {
      return UploadStatus.COMPLETE;
    }

    TorrentStatus status = torrent.getStatus();

    if (status == null) {
      return UploadStatus.CONNECTING;
    }

    if (torrent.isPaused() || (torrent.isFinished() && torrent.getNumUploads() == 0)) {
      return UploadStatus.QUEUED;
    }

    if (status.isError()) {
      // TODO add retry
      // TODO custom error state
      return UploadStatus.UNAVAILABLE_RANGE;
    }

    if (status.isPaused()) {
      return UploadStatus.UPLOADING;
    } else {
      TorrentState state = status.getState();

      switch (state) {
        case DOWNLOADING:
        case FINISHED:
        case SEEDING:
          return UploadStatus.UPLOADING;
        case QUEUED_FOR_CHECKING:
        case CHECKING_FILES:
        case DOWNLOADING_METADATA:
        case ALLOCATING:
          return UploadStatus.CONNECTING;
        default:
          throw new UnsupportedOperationException("Unknown state: " + state);
      }
    }
  }
示例#5
0
 @Override
 public URN getUrn() {
   if (urn == null) {
     synchronized (this) {
       if (urn == null) {
         try {
           urn = URN.createSha1UrnFromHex(torrent.getSha1());
         } catch (IOException e) {
           throw new RuntimeException(e);
         }
       }
     }
   }
   return urn;
 }
示例#6
0
 private void remove() {
   torrent.removeListener(this);
   torrentUploadManager.removeMemento(torrent);
   activityCallback.removeUpload(this);
 };
示例#7
0
 public void registerTorrentListener() {
   torrent.addListener(this);
 }
示例#8
0
 @Override
 public float getSeedRatio() {
   return torrent.getSeedRatio();
 }
示例#9
0
 @Override
 public int getNumUploadConnections() {
   return torrent.getNumConnections();
 }
示例#10
0
 @Override
 public File getFile() {
   return torrent.getTorrentDataFile();
 }
示例#11
0
 @Override
 public float getAverageBandwidth() {
   // Unused
   return (torrent.getUploadRate() / 1024);
 }
示例#12
0
 @Override
 public float getMeasuredBandwidth() throws InsufficientDataException {
   return (torrent.getUploadRate() / 1024);
 }
示例#13
0
 @Override
 public long getTotalAmountUploaded() {
   return torrent.getTotalUploaded();
 }
示例#14
0
 @Override
 public long getFileSize() {
   TorrentStatus status = torrent.getStatus();
   long fileSize = status != null ? status.getTotalWanted() : -1;
   return fileSize;
 }
示例#15
0
 @Override
 public String getFileName() {
   return torrent.getName();
 }