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

The following examples show how to use backtype.storm.tuple.Tuple#getSourceStreamId() . 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: SingleJoinBolt.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    List<Object> id = tuple.select(_idFields);
    GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
    if (!_pending.containsKey(id)) {
        _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
    }
    Map<GlobalStreamId, Tuple> parts = _pending.get(id);
    if (parts.containsKey(streamId))
        throw new RuntimeException("Received same side of single join twice");
    parts.put(streamId, tuple);
    if (parts.size() == _numSources) {
        _pending.remove(id);
        List<Object> joinResult = new ArrayList<Object>();
        for (String outField : _outFields) {
            GlobalStreamId loc = _fieldLocations.get(outField);
            joinResult.add(parts.get(loc).getValueByField(outField));
        }
        _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);
        
        for (Tuple part : parts.values()) {
            _collector.ack(part);
        }
    }
}
 
Example 2
Source File: BatchMetaSpout.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
	
	String streamId = input.getSourceStreamId();
	if (streamId.equals(BatchMetaRebalance.REBALANCE_STREAM_ID)) {
		try {
			metaClient.rebalanceMqList();
		} catch (Exception e) {
			LOG.warn("Failed to do rebalance operation", e);
		}
	}else {
		BatchId batchId = (BatchId) input.getValue(0);

		emitBatch(batchId, collector);
	}
	
}
 
Example 3
Source File: AckTransactionBolt.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input) {
    long rootId = getRootId(input);
    if (rootId != 0) {
        long batchId = ((TupleImplExt) input).getBatchId();
        String streamId = input.getSourceStreamId();
        Pair<Long, Integer> pendingBatch = batchXorTracker.getPendingBatch(batchId, streamId, true);
        if (pendingBatch == null) {
            pendingBatch = new Pair<>(0l, 0);
            batchXorTracker.putPendingBatch(batchId, streamId, pendingBatch);
        }
        pendingBatch.setFirst(JStormUtils.bit_xor(pendingBatch.getFirst(), rootId));
        int count = pendingBatch.getSecond();
        pendingBatch.setSecond(++count);
    }
    bolt.execute(input);
}
 
Example 4
Source File: TupleTransform.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
/**
 * 从Storm的Tuple事件转换为内部事件类型IEvent
 * <功能详细描述>
 */
public IEvent getEvent(Tuple tuple)
    throws StreamSerDeException
{
    List<Object> value = tuple.getValues();

    return new TupleEvent(tuple.getSourceStreamId(), iEventType, value.toArray(new Object[value.size()]));
}
 
Example 5
Source File: StormOutputBolt.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple)
{
    LOG.debug("Start up to execute tuple.");
    String sourceStreamName = tuple.getSourceStreamId();
    try
    {
        for (String streamName : output.getInputStream())
        {
            if (sourceStreamName.equals(streamName))
            {
                TupleEvent event = com.huawei.streaming.storm.TupleTransform.tupeToEvent(tuple, output.getInputSchema().get(streamName));
                output.execute(streamName, event);
            }
        }
    }
    catch (StreamingException e)
    {
        LOG.error("Failed to execute tuple.");
        throw new RuntimeException("Failed to execute tuple.", e);
    }

    if (needAck)
    {
        outputCollector.ack(tuple);
    }
}
 
Example 6
Source File: CoordinatedBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private BatchStatus getBatchStatus(Tuple tuple) {
    String streamId = tuple.getSourceStreamId();

    if (streamId.equals(BatchDef.PREPARE_STREAM_ID)) {
        return BatchStatus.PREPARE_COMMIT;
    } else if (streamId.equals(BatchDef.COMMIT_STREAM_ID)) {
        return BatchStatus.COMMIT;
    } else if (streamId.equals(BatchDef.REVERT_STREAM_ID)) {
        return BatchStatus.REVERT_COMMIT;
    } else if (streamId.equals(BatchDef.POST_STREAM_ID)) {
        return BatchStatus.POST_COMMIT;
    } else {
        return BatchStatus.COMPUTING;
    }
}
 
Example 7
Source File: SubtopologyBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(BatchInfo batchInfo, Tuple tuple) {
    String sourceStream = tuple.getSourceStreamId();
    InitialReceiver ir = _roots.get(sourceStream);
    if (ir == null) {
        throw new RuntimeException("Received unexpected tuple " + tuple.toString());
    }
    ir.receive((ProcessorContext) batchInfo.state, tuple);
}
 
Example 8
Source File: SingleJoinBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    List<Object> id = tuple.select(_idFields);
    GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
    if (!_pending.containsKey(id)) {
        _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
    }
    Map<GlobalStreamId, Tuple> parts = _pending.get(id);
    if (parts.containsKey(streamId))
        throw new RuntimeException("Received same side of single join twice");
    parts.put(streamId, tuple);
    if (parts.size() == _numSources) {
        _pending.remove(id);
        List<Object> joinResult = new ArrayList<Object>();
        for (String outField : _outFields) {
            GlobalStreamId loc = _fieldLocations.get(outField);
            joinResult.add(parts.get(loc).getValueByField(outField));
        }
        _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);

        for (Tuple part : parts.values()) {
            _collector.ack(part);
        }
        
        SingleJoinTest.receiveCounter.incrementAndGet();
    }
}
 
Example 9
Source File: TupleTransform.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
/**
 * 将tuple转换为内部使用的tupleEvent
 * TODO 该方法为静态方法,和使用对象进行转换的性能哪个好还有待进一步验证
 */
public static TupleEvent tupeToEvent(Tuple input, IEventType inputTupleEventType)
{
    List<Object> value = input.getValues();
    return new TupleEvent(input.getSourceStreamId(), inputTupleEventType, value.toArray(new Object[value.size()]));
}
 
Example 10
Source File: StormBolt.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple input)
{
    LOG.debug("start to execute storm bolt");
    if (input == null)
    {
        LOG.error("Input tuple is null.");
        throw new RuntimeException("Input tuple is null.");
    }
    
    String sourceStreamName = input.getSourceStreamId();
    
    if (StringUtils.isEmpty(sourceStreamName))
    {
        LOG.error("sourceStreamName is null.");
        throw new RuntimeException("sourceStreamName is nul");
    }
    
    try
    {
        List<String> inStreams = functionStream.getInputStream();
        if(inStreams == null)
        {
            LOG.error("inStreams is null.");
            throw new RuntimeException("inStreams is nul");
        }
        
        for (String streamName : inStreams)
        {
            if (!sourceStreamName.equals(streamName))
            {
                continue;
            }
            
            TupleEvent event = TupleTransform.tupeToEvent(input, functionStream.getInputSchema().get(streamName));
            functionStream.execute(streamName, event);
        }
    }
    catch (StreamingException e)
    {
        LOG.error("Failed to execute tuple.");
        throw new RuntimeException("Failed to execute tuple.", e);
    }
}
 
Example 11
Source File: SpoutExecutors.java    From jstorm with Apache License 2.0 4 votes vote down vote up
private Runnable processTupleEvent(Tuple event) {
    Runnable runnable = null;
    Tuple tuple = event;
    if (event.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID)) {
        TopoMasterCtrlEvent ctrlEvent = (TopoMasterCtrlEvent) tuple.getValueByField("ctrlEvent");
        if (ctrlEvent.isTransactionEvent()) {
            if (spout instanceof ICtrlMsgSpout) {
                runnable = new CtrlMsgSpout((ICtrlMsgSpout) spout, ctrlEvent);
            }
        } else if (ctrlEvent.isFinishInitEvent()) {
            LOG.info("spout task-{} received topology finish init operation message", taskId);
            taskHbTrigger.updateExecutorStatus(TaskStatus.RUN);
            this.checkTopologyFinishInit = true;
        } else {
            LOG.warn("Received unexpected control event, {}", ctrlEvent);
        }
    } else if (event.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID)) {
        this.metricsReporter.updateMetricMeta((Map<String, Long>) tuple.getValue(0));
    } else {
        Object id = tuple.getValue(0);
        Object obj = pending.remove((Long) id);

        if (obj == null) {
            if (JStormDebugger.isDebug(id)) {
                LOG.info("Pending map no entry:" + id);
            }
            runnable = null;
        } else {
            TupleInfo tupleInfo = (TupleInfo) obj;

            String stream_id = tuple.getSourceStreamId();

            if (stream_id.equals(Acker.ACKER_ACK_STREAM_ID)) {
                runnable = new AckSpoutMsg(id, spout, tuple, tupleInfo, taskStats);
            } else if (stream_id.equals(Acker.ACKER_FAIL_STREAM_ID)) {
                runnable = new FailSpoutMsg(id, spout, tupleInfo, taskStats);
            } else {
                LOG.warn("Receive one unknown source Tuple " + idStr);
                runnable = null;
            }
        }

        taskStats.recv_tuple(tuple.getSourceComponent(), tuple.getSourceStreamId());
    }
    return runnable;
}