Exemplo n.º 1
0
  public AckSpoutMsg(
      ISpout _spout, TupleInfo tupleInfo, CommonStatsRolling _task_stats, boolean _isDebug) {

    this.task_stats = _task_stats;

    this.spout = _spout;
    this.isDebug = _isDebug;

    this.msgId = tupleInfo.getMessageId();
    this.stream = tupleInfo.getStream();
    this.timeStamp = tupleInfo.getTimestamp();
    this.values = tupleInfo.getValues();
  }
Exemplo n.º 2
0
  private List<Integer> sendSpoutMsg(
      String out_stream_id, List<Object> values, Object message_id, Integer out_task_id) {

    emitTotalTimer.start();

    try {
      java.util.List<Integer> out_tasks = null;
      if (out_task_id != null) {
        out_tasks = sendTargets.get(out_task_id, out_stream_id, values);
      } else {
        out_tasks = sendTargets.get(out_stream_id, values);
      }

      if (out_tasks.size() == 0) {
        // don't need send tuple to other task
        return out_tasks;
      }
      List<Long> ackSeq = new ArrayList<Long>();
      Boolean needAck = (message_id != null) && (ackerNum > 0);

      // This change storm logic
      // Storm can't make sure root_id is unique
      // storm's logic is root_id = MessageId.generateId(random);
      // when duplicate root_id, it will miss call ack/fail
      Long root_id = MessageId.generateId(random);
      if (needAck) {
        while (pending.containsKey(root_id) == true) {
          root_id = MessageId.generateId(random);
        }
      }
      for (Integer t : out_tasks) {
        MessageId msgid;
        if (needAck) {
          // Long as = MessageId.generateId();
          Long as = MessageId.generateId(random);
          msgid = MessageId.makeRootId(root_id, as);
          ackSeq.add(as);
        } else {
          msgid = MessageId.makeUnanchored();
        }

        TupleImplExt tp = new TupleImplExt(topology_context, values, task_id, out_stream_id, msgid);
        tp.setTargetTaskId(t);
        transfer_fn.transfer(tp);
      }

      if (needAck) {

        TupleInfo info = new TupleInfo();
        info.setStream(out_stream_id);
        info.setValues(values);
        info.setMessageId(message_id);
        info.setTimestamp(System.currentTimeMillis());

        pending.putHead(root_id, info);

        List<Object> ackerTuple =
            JStormUtils.mk_list((Object) root_id, JStormUtils.bit_xor_vals(ackSeq), task_id);

        UnanchoredSend.send(
            topology_context, sendTargets, transfer_fn, Acker.ACKER_INIT_STREAM_ID, ackerTuple);

      } else if (message_id != null) {
        TupleInfo info = new TupleInfo();
        info.setStream(out_stream_id);
        info.setValues(values);
        info.setMessageId(message_id);
        info.setTimestamp(0);

        AckSpoutMsg ack = new AckSpoutMsg(spout, info, task_stats, isDebug);
        ack.run();
      }

      return out_tasks;
    } finally {
      emitTotalTimer.stop();
    }
  }