Search in sources :

Example 21 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project jstorm by alibaba.

the class SingleJoinBolt method prepare.

@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
    _fieldLocations = new HashMap<String, GlobalStreamId>();
    _collector = collector;
    int timeout = ((Number) conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS)).intValue();
    _pending = new TimeCacheMap<List<Object>, Map<GlobalStreamId, Tuple>>(timeout, new ExpireCallback());
    _numSources = context.getThisSources().size();
    Set<String> idFields = null;
    for (GlobalStreamId source : context.getThisSources().keySet()) {
        Fields fields = context.getComponentOutputFields(source.get_componentId(), source.get_streamId());
        Set<String> setFields = new HashSet<String>(fields.toList());
        if (idFields == null)
            idFields = setFields;
        else
            idFields.retainAll(setFields);
        for (String outfield : _outFields) {
            for (String sourcefield : fields) {
                if (outfield.equals(sourcefield)) {
                    _fieldLocations.put(outfield, source);
                }
            }
        }
    }
    _idFields = new Fields(new ArrayList<String>(idFields));
    if (_fieldLocations.size() != _outFields.size()) {
        throw new RuntimeException("Cannot find all outfields among sources");
    }
}
Also used : ArrayList(java.util.ArrayList) Fields(backtype.storm.tuple.Fields) GlobalStreamId(backtype.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) HashSet(java.util.HashSet)

Example 22 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project storm by nathanmarz.

the class TridentTopologyBuilder method getBoltBatchToComponentSubscriptions.

Map<String, Set<String>> getBoltBatchToComponentSubscriptions(String id) {
    Map<String, Set<String>> ret = new HashMap();
    for (GlobalStreamId s : getBoltSubscriptionStreams(id)) {
        String b = _batchIds.get(s);
        if (!ret.containsKey(b))
            ret.put(b, new HashSet());
        ret.get(b).add(s.get_componentId());
    }
    return ret;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) GlobalStreamId(backtype.storm.generated.GlobalStreamId) HashSet(java.util.HashSet)

Example 23 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project storm by nathanmarz.

the class TopologyBuilder method initCommon.

private void initCommon(String id, IComponent component, Number parallelism) {
    ComponentCommon common = new ComponentCommon();
    common.set_inputs(new HashMap<GlobalStreamId, Grouping>());
    if (parallelism != null)
        common.set_parallelism_hint(parallelism.intValue());
    Map conf = component.getComponentConfiguration();
    if (conf != null)
        common.set_json_conf(JSONValue.toJSONString(conf));
    _commons.put(id, common);
}
Also used : ComponentCommon(backtype.storm.generated.ComponentCommon) GlobalStreamId(backtype.storm.generated.GlobalStreamId) Grouping(backtype.storm.generated.Grouping) CustomStreamGrouping(backtype.storm.grouping.CustomStreamGrouping) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project storm by nathanmarz.

the class GeneralTopologyContext method getTargets.

/**
     * Gets information about who is consuming the outputs of the specified component,
     * and how.
     *
     * @return Map from stream id to component id to the Grouping used.
     */
public Map<String, Map<String, Grouping>> getTargets(String componentId) {
    Map<String, Map<String, Grouping>> ret = new HashMap<String, Map<String, Grouping>>();
    for (String otherComponentId : getComponentIds()) {
        Map<GlobalStreamId, Grouping> inputs = getComponentCommon(otherComponentId).get_inputs();
        for (GlobalStreamId id : inputs.keySet()) {
            if (id.get_componentId().equals(componentId)) {
                Map<String, Grouping> curr = ret.get(id.get_streamId());
                if (curr == null)
                    curr = new HashMap<String, Grouping>();
                curr.put(otherComponentId, inputs.get(id));
                ret.put(id.get_streamId(), curr);
            }
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) GlobalStreamId(backtype.storm.generated.GlobalStreamId) Grouping(backtype.storm.generated.Grouping) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

GlobalStreamId (backtype.storm.generated.GlobalStreamId)24 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 HashSet (java.util.HashSet)7 Grouping (backtype.storm.generated.Grouping)6 Set (java.util.Set)4 CustomStreamGrouping (backtype.storm.grouping.CustomStreamGrouping)3 BoltDeclarer (backtype.storm.topology.BoltDeclarer)3 Fields (backtype.storm.tuple.Fields)3 List (java.util.List)3 ITridentSpout (storm.trident.spout.ITridentSpout)3 ComponentCommon (backtype.storm.generated.ComponentCommon)2 Tuple (backtype.storm.tuple.Tuple)2 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)2 GraphGrouper (storm.trident.graph.GraphGrouper)2 Group (storm.trident.graph.Group)2 Node (storm.trident.planner.Node)2 PartitionNode (storm.trident.planner.PartitionNode)2 ProcessorNode (storm.trident.planner.ProcessorNode)2