コード例 #1
0
 @Override
 public void calledOperationFailed(Operation op) {
   if (op instanceof BTOperationDownload) {
     logger.process(
         this.getClass().toString(),
         new Object[] {op, new Long(Simulator.getCurrentTime()), new Boolean(false)});
   }
 }
コード例 #2
0
 /**
  * This method starts a download by creating and activating a download operation.
  *
  * @param theOverlayKey the key/hash of the document that we want to download.
  * @param theOtherPeers a list of peers start also participate in this torrent. We normaly get
  *     this list from the tracker.
  * @return the operation id of the started download operation.
  */
 public int downloadDocument(
     OverlayKey theOverlayKey, List<TransInfo> theOtherPeers, OperationCallback theCallback) {
   log.debug(
       "Time: "
           + Simulator.getCurrentTime()
           + "; Starting download at '"
           + this.itsOwnContact
           + "'.");
   BTDocument document;
   BTConnectionManager connectionManager;
   if (!this.itsContentStorage.containsDocument(theOverlayKey)) {
     document =
         new BTDocument(
             theOverlayKey,
             ((BTTorrent) this.itsDataBus.getPerTorrentData(theOverlayKey, "Torrent")).getSize());
     this.itsContentStorage.storeDocument(document);
   } else {
     document = (BTDocument) this.itsContentStorage.loadDocument(theOverlayKey);
   }
   if (!this.itsConnectionManagers.containsKey(theOverlayKey)) {
     connectionManager = new BTConnectionManager(this.itsOwnContact);
     this.itsConnectionManagers.put(theOverlayKey, connectionManager);
   } else {
     connectionManager = this.itsConnectionManagers.get(theOverlayKey);
   }
   BTOperationDownload<BTPeerDistributeNode> downloadOperation =
       new BTOperationDownload<BTPeerDistributeNode>(
           this.itsDataBus,
           document,
           this.itsOwnContact,
           this,
           this,
           connectionManager,
           this.itsStatistic,
           this.itsRandomGenerator);
   this.itsDownloadOperations.add(downloadOperation);
   downloadOperation.scheduleImmediately();
   return downloadOperation.getOperationID();
 }
コード例 #3
0
 public void scheduleAtTime(long time) {
   time = Math.max(time, Simulator.getCurrentTime());
   Simulator.scheduleEvent(this, time, this, SimulationEvent.Type.TIMEOUT_EXPIRED);
 }
コード例 #4
0
 public void scheduleWithDelay(long delay) {
   long time = Simulator.getCurrentTime() + delay;
   scheduleAtTime(time);
 }