public void registerListener(int id, MessageListener m) {
    HashSet listenerSet = (HashSet) idTable.get(new Integer(id));

    if (listenerSet == null) {
      listenerSet = new HashSet();
      idTable.put(new Integer(id), listenerSet);
    }
    listenerSet.add(m);
    log.info("New Listener for id=" + id);
  }
Beispiel #2
0
  public Drip(int id) {

    log.info("Started id=" + id);
    try {
      moteIF = new MoteIF();
      moteIF.registerListener(new DripMsg(), this);
    } catch (Exception e) {
      System.out.println("ERROR: Couldn't contact serial forwarder.");
      System.exit(1);
    }

    this.id = id;
  }
Beispiel #3
0
  public void messageReceived(int to, Message m) {

    DripMsg msg = (DripMsg) m;

    int newId = msg.get_metadata_id();
    int newSeqno = msg.get_metadata_seqno();

    log.debug("Received Msg: id=" + newId + ",seqno=" + newSeqno);

    if (newId != id) {
      log.debug("dropped, not ID " + id);
      return;
    }

    if ((newSeqno & ~DripConsts.DRIP_WAKEUP_BIT) == DripConsts.DRIP_SEQNO_NEWEST) {
      log.debug("dropped, a special seqno " + newSeqno);
      return;
    }

    switch (state) {
      case PROBING:
        seqno = newSeqno;
        log.info(
            "Receive: id=" + id + ",seqno=" + dripMsg.get_metadata_seqno() + " Heard Old Seqno");
        incrementSeqno();
        state = SENDING_SEQNO;
      case SENDING_SEQNO:
        if (seqno == newSeqno) {
          log.info(
              "Receive: id=" + id + ",seqno=" + dripMsg.get_metadata_seqno() + " Heard New Seqno");
          trickle.cancel();
          trickleTask.cancel();
          sendDone();
        }
      default:
    }
  }
 public DrainConnector(int p_spAddr, MoteIF p_moteIF) {
   spAddr = p_spAddr;
   moteIF = p_moteIF;
   moteIF.registerListener(new DrainMsg(), this);
   log.info("Started myAddr = " + spAddr + ", listening for DrainMsg");
 }