Package dijjer.io

Examples of dijjer.io.BlockInfo


      int uid = Misc.nextInt();
      Dispatcher.getDispatcher().registerUid(uid);
      VeryLongInteger checkHash = null;
      try {
        checkHash = Dispatcher.getDispatcher().retrieveHash(
            new BlockInfo(_url, _length, _lastModified, blockNo), 10, uid, false);
      } catch (Exception e) {
        Logger.warning("Failed to retrieve hash " + e.getMessage());
      }
      Dispatcher.getDispatcher().unregisterUid(uid);
      if (checkHash != null) {
        _retrievedHashes.put(new Integer(blockNo), checkHash);
      }
      Logger.info("Done with retrieval of hash " + blockNo);
    } else {
      PartiallyReceivedBlock block;
      BlockInfo bi;
      synchronized (this) {
        blockNo = _nextBlockToDownload++;
        bi = new BlockInfo(_url, _length, _lastModified, blockNo);
        block = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK, Dijjer.PACKET_SIZE);
        _pending.addLast(new BlockPair(bi, block));
        this.notify();
      }
      try {
        // If the remote transfer fails we don't want the transfer to the client to be aborted, rather
        // we want to rerequest with TTL of 0, so we tell the PartiallyRetrievedBlock to ignore any
        // abort
        block.setIgnoreAbort(true);
        if (Dispatcher.getDispatcher().retrieveData(bi, 15, block, this)) {
          _fromCacheCount++;
        }
        block.setIgnoreAbort(false);
      } catch (Exception e) {
        Logger.warning("Error during download of block " + blockNo + ": " + e.getMessage());
        try {
          Logger.info("Retrying block " + blockNo + " with TTL of 0");
          Dispatcher.getDispatcher().retrieveData(new BlockInfo(_url, _length, _lastModified, blockNo), 0,
              block, this);
        } catch (Exception e1) {
          Logger.error("Error during direct download of block " + blockNo + ", aborting", e1);
          this.abort();
        }
View Full Code Here


          protected boolean loop() throws InterruptedException {
            try {
              _usm.send(m.getSource(), DMT.createAcknowledgeRequest(m.getInt(DMT.UID)));
              PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK,
                  Dijjer.PACKET_SIZE);
              retrieveData(new BlockInfo(m), m.getInt(DMT.TTL), m.getSource(), m.getInt(DMT.UID),
                  (LinkedList) m.getObject(DMT.FORWARDERS), prb, null);
              _seenUids.remove(uid);
            } catch (Exception e) {
              Logger.warning("Error while retrieving data for another peer", e);
            }
            return false;
          }

          protected void cleanUp() {
          }
        }.startThread();
      } else {
        _usm.send(m.getSource(), DMT.createRejectDueToLoop(m.getInt(DMT.UID)));
      }
      return true;
    } else if (m.getSpec().equals(DMT.requestHash)) {
      final Integer uid = new Integer(m.getInt(DMT.UID));
      if (!_seenUids.contains(uid)) {
        _seenUids.add(uid);
        new AbstractThread() {

          public boolean loop() {
            try {
              _usm.send(m.getSource(), DMT.createRequestHashAck(m.getInt(DMT.UID)));
              VeryLongInteger hash = retrieveHash(new BlockInfo(m), m.getInt(DMT.TTL), m.getInt(DMT.UID),
                  true);
              _usm.send(m.getSource(), DMT.createReplyHash(m.getInt(DMT.UID), hash));
              _seenUids.remove(uid);
            } catch (Exception e) {
              Logger.error(e);
              throw new RuntimeException(e);
            }
            return false;
          }
        }.startThread();
      } else {
        _usm.send(m.getSource(), DMT.createRejectDueToLoop(m.getInt(DMT.UID)));
      }
      return true;
    } else if (m.getSpec().equals(DMT.corruptionNotification)) {
      final Integer uid = new Integer(m.getInt(DMT.UID));
      if (!_seenUids.contains(uid)) { // We don't bother with the rejectDueToLoop
        _seenUids.add(uid);
        new AbstractThread() {

          public boolean loop() {
            try {
              handleCorruptionNotification(new BlockInfo(m), m.getInt(DMT.UID), m.getSource(), m
                  .getBoolean(DMT.IS_HASH));
              _seenUids.remove(uid);
            } catch (Exception e) {
              Logger.error(e);
              throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of dijjer.io.BlockInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.