Java Code Examples for backtype.storm.task.TopologyContext#getSources()

The following examples show how to use backtype.storm.task.TopologyContext#getSources() . 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: BatchInputBolt.java    From StormCV with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
void prepare(Map conf, TopologyContext context) {
	// use TTL and maxSize from config if they were not set explicitly using the constructor (implicit way of doing this...)
	if(TTL == 29) TTL = conf.get(StormCVConfig.STORMCV_CACHES_TIMEOUT_SEC) == null ? TTL : ((Long)conf.get(StormCVConfig.STORMCV_CACHES_TIMEOUT_SEC)).intValue();
	if(maxSize == 256) maxSize = conf.get(StormCVConfig.STORMCV_CACHES_MAX_SIZE) == null ? maxSize : ((Long)conf.get(StormCVConfig.STORMCV_CACHES_MAX_SIZE)).intValue();
	history = new History(this);
	
	// IF NO grouping was set THEN select the first grouping registered for the spout as the grouping used within the Spout (usually a good guess)
	if(groupBy == null){
		Map<GlobalStreamId, Grouping> sources = context.getSources(context.getThisComponentId());
		for(GlobalStreamId id : sources.keySet()){
			Grouping grouping = sources.get(id);
			this.groupBy = new Fields(grouping.get_fields());
			break;
		}
	}
	
	// prepare the selector and operation
	try {
		batcher.prepare(conf);
		operation.prepare(conf, context);
	} catch (Exception e) {
		logger.error("Unable to preapre the Selector or Operation", e);
	}
}
 
Example 2
Source File: KvStatefulBoltExecutor.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    createState(context);
    prepare(stormConf, context, collector, keyRangeState);
    
    Map<GlobalStreamId, Grouping> sources = context.getSources(context.getThisComponentId());
    for (Map.Entry<GlobalStreamId, Grouping> entry : sources.entrySet()) {
        GlobalStreamId stream = entry.getKey();
        Grouping grouping = entry.getValue();
        Grouping._Fields groupingFields = Thrift.groupingType(grouping);
        if (Grouping._Fields.FIELDS.equals(groupingFields)) {
            Fields fields = new Fields(Thrift.fieldGrouping(grouping));
            fieldGrouping.put(stream.get_streamId(), fields);
        }
    }
    LOG.info("Source fieldgrouping streams: {}", fieldGrouping);
}