Package dijjer.util

Examples of dijjer.util.AbstractThread


      return true;
    } else if (m.getSpec().equals(DMT.joinRequest)) {
      final Integer uid = new Integer(m.getInt(DMT.UID));
      if (!_seenUids.contains(uid)) {
        _seenUids.add(uid);
        new AbstractThread() {

          protected boolean loop() throws InterruptedException {
            handleJoinRequest(m);
            _seenUids.remove(uid);
            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.requestData)) {
      final Integer uid = new Integer(m.getInt(DMT.UID));
      if (!_seenUids.contains(uid)) {
        _seenUids.add(uid);
        new AbstractThread() {

          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));
View Full Code Here

TOP

Related Classes of dijjer.util.AbstractThread

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.