Java Code Examples for backtype.storm.tuple.Tuple#getMessageId()

The following examples show how to use backtype.storm.tuple.Tuple#getMessageId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoltBatchCollector.java    From jstorm with Apache License 2.0 6 votes vote down vote up
private boolean sendAckTuple(Tuple input) {
    boolean ret = false;
    Integer pendingCount;
    synchronized (pendingTuples) {
        pendingCount = pendingTuples.get(input);
    }
    if (pendingCount == null || pendingCount <= 0) {
        long ack_val = 0L;
        Object pend_val = pendingAcks.remove(input);
        if (pend_val != null) {
            ack_val = (Long) (pend_val);
        }
        MessageId messageId = input.getMessageId();
        if (messageId != null) {
            for (Map.Entry<Long, Long> e : messageId.getAnchorsToIds().entrySet()) {
                List<Object> ackTuple =
                        JStormUtils.mk_list((Object) e.getKey(), JStormUtils.bit_xor(e.getValue(), ack_val));
                sendBoltMsg(Acker.ACKER_ACK_STREAM_ID, null, ackTuple, null, null);
            }
        }
        ret = true;
    }

    return ret;
}
 
Example 2
Source File: BoltCollector.java    From jstorm with Apache License 2.0 6 votes vote down vote up
protected MessageId getMessageId(Collection<Tuple> anchors) {
    MessageId ret = null;
    if (anchors != null && ackerNum > 0) {
        Map<Long, Long> anchors_to_ids = new HashMap<>();
        for (Tuple a : anchors) {
            if (a.getMessageId() != null) {
                Long edge_id = MessageId.generateId(random);
                put_xor(pendingAcks, a, edge_id);
                MessageId messageId = a.getMessageId();
                if (messageId != null) {
                    for (Long root_id : messageId.getAnchorsToIds().keySet()) {
                        put_xor(anchors_to_ids, root_id, edge_id);
                    }
                }
            }
        }
        ret = MessageId.makeId(anchors_to_ids);
    }
    return ret;
}
 
Example 3
Source File: BoltCollector.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void ack(Tuple input) {
    if (input.getMessageId() != null) {
        Long ack_val = 0L;
        Object pend_val = pendingAcks.remove(input);
        if (pend_val != null) {
            ack_val = (Long) (pend_val);
        }

        for (Entry<Long, Long> e : input.getMessageId().getAnchorsToIds().entrySet()) {
            unanchoredSend(topologyContext, sendTargets, taskTransfer, Acker.ACKER_ACK_STREAM_ID,
                    JStormUtils.mk_list((Object) e.getKey(), JStormUtils.bit_xor(e.getValue(), ack_val)));
        }
    }

    Long latencyStart = (Long) tupleStartTimes.remove(input);
    taskStats.bolt_acked_tuple(input.getSourceComponent(), input.getSourceStreamId());
    if (latencyStart != null && JStormMetrics.enabled) {
        long endTime = System.currentTimeMillis();
        taskStats.update_bolt_acked_latency(input.getSourceComponent(), input.getSourceStreamId(),
                latencyStart, endTime);
    }
}
 
Example 4
Source File: BoltBatchCollector.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void ack(Tuple input) {
    if (input.getMessageId() != null) {
        if (!sendAckTuple(input)) {
            pendingAckQueue.add(input);
        }
    }

    Long latencyStart = (Long) tupleStartTimes.remove(input);
    taskStats.bolt_acked_tuple(input.getSourceComponent(), input.getSourceStreamId());
    if (latencyStart != null && JStormMetrics.enabled) {
        long endTime = System.currentTimeMillis();
        taskStats.update_bolt_acked_latency(input.getSourceComponent(), input.getSourceStreamId(), latencyStart, endTime);
    }
}
 
Example 5
Source File: BoltBatchCollector.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void fail(Tuple input) {
    // if ackerNum == 0, we can just return
    if (input.getMessageId() != null) {
        pendingAcks.remove(input);
        for (Map.Entry<Long, Long> e : input.getMessageId().getAnchorsToIds().entrySet()) {
            List<Object> ackTuple = JStormUtils.mk_list((Object) e.getKey());
            sendBoltMsg(Acker.ACKER_FAIL_STREAM_ID, null, ackTuple, null, null);
        }
    }

    taskStats.bolt_failed_tuple(input.getSourceComponent(), input.getSourceStreamId());
}
 
Example 6
Source File: BoltBatchCollector.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageId getMessageId(Collection<Tuple> anchors) {
    MessageId ret = null;
    if (anchors != null) {
        Map<Long, Long> anchors_to_ids = new HashMap<Long, Long>();
        long now = System.currentTimeMillis();
        if (now - lastRotate > rotateTime) {
            pendingAcks.rotate();
            synchronized (pendingTuples) {
                pendingTuples.rotate();
            }
            lastRotate = now;
        }
        for (Tuple a : anchors) {
            // Long edge_id = MessageId.generateId();
            Long edge_id = MessageId.generateId(random);
            synchronized (pendingAcks) {
                put_xor(pendingAcks, a, edge_id);
            }
            MessageId messageId = a.getMessageId();
            if (messageId != null) {
                for (Long root_id : messageId.getAnchorsToIds().keySet()) {
                    put_xor(anchors_to_ids, root_id, edge_id);
                }
            }
        }
        ret = MessageId.makeId(anchors_to_ids);
    }
    return ret;
}
 
Example 7
Source File: BoltExecutors.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private void processTupleEvent(Tuple tuple) {
    if (tuple.getMessageId() != null && tuple.getMessageId().isAnchored()) {
        tupleStartTimes.put(tuple, System.currentTimeMillis());
    }

    try {
        // for watermarks, just forward to downstream operators
        if (!isSystemBolt && Common.WATERMARK_STREAM_ID.equals(tuple.getSourceStreamId())) {
            outputCollector.emit(Common.WATERMARK_STREAM_ID, tuple.getValues());
        }

        if (!isSystemBolt && tuple.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID)) {
            TopoMasterCtrlEvent event = (TopoMasterCtrlEvent) tuple.getValue(0);
            if (event.isTransactionEvent()) {
                bolt.execute(tuple);
            } else {
                LOG.warn("Received an unexpected control event, {}", event);
            }
        } else if (tuple.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID)) {
            this.metricsReporter.updateMetricMeta((Map<String, Long>) tuple.getValue(0));
        } else {
            bolt.execute(tuple);
        }
    } catch (Throwable e) {
        error = e;
        LOG.error("bolt execute error ", e);
        reportError.report(e);
    }
}
 
Example 8
Source File: BoltCollector.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void fail(Tuple input) {
    // if ackerNum == 0, we can just return
    if (input.getMessageId() != null) {
        pendingAcks.remove(input);
        for (Entry<Long, Long> e : input.getMessageId().getAnchorsToIds().entrySet()) {
            unanchoredSend(topologyContext, sendTargets, taskTransfer, Acker.ACKER_FAIL_STREAM_ID,
                    JStormUtils.mk_list((Object) e.getKey()));
        }
    }

    tupleStartTimes.remove(input);
    taskStats.bolt_failed_tuple(input.getSourceComponent(), input.getSourceStreamId());
}