Esempio n. 1
0
  public void up(MessageBatch batch) {
    for (Message msg : batch) {
      DaisyHeader hdr = (DaisyHeader) msg.getHeader(getId());
      if (hdr != null) {
        // 1. forward the message to the next in line if ttl > 0
        short ttl = hdr.getTTL();
        if (log.isTraceEnabled())
          log.trace(local_addr + ": received message from " + msg.getSrc() + " with ttl=" + ttl);
        if (--ttl > 0) {
          Message copy = msg.copy(true);
          copy.setDest(next);
          copy.putHeader(getId(), new DaisyHeader(ttl));
          msgs_forwarded++;
          if (log.isTraceEnabled())
            log.trace(local_addr + ": forwarding message to " + next + " with ttl=" + ttl);
          down_prot.down(new Event(Event.MSG, copy));
        }

        // 2. Pass up
        msg.setDest(null);
      }
    }

    if (!batch.isEmpty()) up_prot.up(batch);
  }
Esempio n. 2
0
  public Object up(Event evt) {
    switch (evt.getType()) {
      case Event.MSG:
        Message msg = (Message) evt.getArg();
        DaisyHeader hdr = (DaisyHeader) msg.getHeader(getId());
        if (hdr == null) break;

        // 1. forward the message to the next in line if ttl > 0
        short ttl = hdr.getTTL();
        if (log.isTraceEnabled())
          log.trace(local_addr + ": received message from " + msg.getSrc() + " with ttl=" + ttl);
        if (--ttl > 0) {
          Message copy = msg.copy(true);
          copy.setDest(next);
          copy.putHeader(getId(), new DaisyHeader(ttl));
          msgs_forwarded++;
          if (log.isTraceEnabled())
            log.trace(local_addr + ": forwarding message to " + next + " with ttl=" + ttl);
          down_prot.down(new Event(Event.MSG, copy));
        }

        // 2. Pass up
        msg.setDest(null);
        break;
    }
    return up_prot.up(evt);
  }