Java Code Examples for backtype.storm.generated.GlobalStreamId#get_componentId()

The following examples show how to use backtype.storm.generated.GlobalStreamId#get_componentId() . 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: TransactionCommon.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static Set<String> getDownstreamComponents(String componentId, StormTopology topology) {
    Set<String> components = new HashSet<>();

    Map<String, Bolt> bolts = topology.get_bolts();
    for (Entry<String, Bolt> entry : bolts.entrySet()) {
        String downstreamComponentId = entry.getKey();
        Bolt bolt = entry.getValue();
        Set<GlobalStreamId> input = bolt.get_common().get_inputs().keySet();
        for (GlobalStreamId stream : input) {
            String upstreamComponentId = stream.get_componentId();
            if (upstreamComponentId.equals(componentId)) {
                components.add(downstreamComponentId);
                break;
            }
        }
    }

    return components;
}
 
Example 2
Source File: TransactionCommon.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static Set<String> getAllDownstreamComponents(String componentId, StormTopology topology,
                                                     Set<String> traversedComponents) {
    Set<String> components = new HashSet<>();
    traversedComponents.add(componentId);

    Map<String, Bolt> bolts = topology.get_bolts();
    for (Entry<String, Bolt> entry : bolts.entrySet()) {
        String downstreamComponentId = entry.getKey();
        Bolt bolt = entry.getValue();
        Set<GlobalStreamId> input = bolt.get_common().get_inputs().keySet();
        for (GlobalStreamId stream : input) {
            String upstreamComponentId = stream.get_componentId();
            if (upstreamComponentId.equals(componentId) && !traversedComponents.contains(downstreamComponentId)) {
                components.add(downstreamComponentId);
                components.addAll(getAllDownstreamComponents(downstreamComponentId, topology, traversedComponents));
                break;
            }
        }
    }

    return components;
}
 
Example 3
Source File: TransactionCommon.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static Set<Integer> getDownstreamTasks(String componentId, TopologyContext context) {
    Set<Integer> tasks = new HashSet<>();
    StormTopology topology = context.getRawTopology();

    Map<String, Bolt> bolts = topology.get_bolts();
    for (Entry<String, Bolt> entry : bolts.entrySet()) {
        String downstreamComponentId = entry.getKey();
        Bolt bolt = entry.getValue();
        Set<GlobalStreamId> input = bolt.get_common().get_inputs().keySet();
        for (GlobalStreamId stream : input) {
            String upstreamComponentId = stream.get_componentId();
            if (upstreamComponentId.equals(componentId)) {
                tasks.addAll(context.getComponentTasks(downstreamComponentId));
                break;
            }
        }
    }

    return tasks;
}
 
Example 4
Source File: TopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * For bolts that has incoming streams from spouts (the root bolts),
 * add checkpoint stream from checkpoint spout to its input. For other bolts,
 * add checkpoint stream from the previous bolt to its input.
 */
private void addCheckPointInputs(ComponentCommon component) {
    Set<GlobalStreamId> checkPointInputs = new HashSet<>();
    for (GlobalStreamId inputStream : component.get_inputs().keySet()) {
        String sourceId = inputStream.get_componentId();
        if (_spouts.containsKey(sourceId)) {
            checkPointInputs.add(new GlobalStreamId(CheckpointSpout.CHECKPOINT_COMPONENT_ID, CheckpointSpout.CHECKPOINT_STREAM_ID));
        } else {
            checkPointInputs.add(new GlobalStreamId(sourceId, CheckpointSpout.CHECKPOINT_STREAM_ID));
        }
    }
    for (GlobalStreamId streamId : checkPointInputs) {
        component.put_to_inputs(streamId, Grouping.all(new NullStruct()));
    }
}