当前位置: 首页>>代码示例>>Java>>正文


Java TopologyBuilder.createTopology方法代码示例

本文整理汇总了Java中backtype.storm.topology.TopologyBuilder.createTopology方法的典型用法代码示例。如果您正苦于以下问题:Java TopologyBuilder.createTopology方法的具体用法?Java TopologyBuilder.createTopology怎么用?Java TopologyBuilder.createTopology使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backtype.storm.topology.TopologyBuilder的用法示例。


在下文中一共展示了TopologyBuilder.createTopology方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
public static StormTopology build() {

        String json1 = "{\"reason\" : \"business\",\"airport\" : \"SFO\"}";
        String json2 = "{\"participants\" : 5,\"airport\" : \"OTP\"}";

        Map<String, Object> conf = new HashMap<>();
        /*
         * Configuration: https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html
         */
        conf.put("es.nodes", "192.168.1.101");
        conf.put("es.port", 9200);
        conf.put("es.input.json", "true");
        conf.put("es.batch.size.entries", "100");

        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("json-spout", new StringSpout(json1, json2));
        builder.setBolt("es-bolt", new EsBolt("storm/json-trips", conf)).shuffleGrouping("json-spout");

        return builder.createTopology();
    }
 
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:21,代码来源:CreditCardTopologyBuilder.java

示例2: build

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
public StormTopology build(StreamingApp app) throws Exception {
  SpringSpout eventsimSpout = new SpringSpout("eventsimSpout", spoutFields);
  SpringBolt collectionPerTimeFrameSolrBolt = new SpringBolt("collectionPerTimeFrameSolrBoltAction",
      app.tickRate("collectionPerTimeFrameSolrBoltAction"));

  // Send all docs for the same hash range to the same bolt instance,
  // which allows us to use a streaming approach to send docs to the leader
  int numShards = Integer.parseInt(String.valueOf(app.getStormConfig().get("spring.eventsimNumShards")));
  HashRangeGrouping hashRangeGrouping = new HashRangeGrouping(app.getStormConfig(), numShards);
  int tasksPerShard = hashRangeGrouping.getNumShards()*2;

  TopologyBuilder builder = new TopologyBuilder();
  builder.setSpout("eventsimSpout", eventsimSpout, app.parallelism("eventsimSpout"));
  builder.setBolt("collectionPerTimeFrameSolrBolt", collectionPerTimeFrameSolrBolt, tasksPerShard)
         .customGrouping("eventsimSpout", hashRangeGrouping);

  return builder.createTopology();
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:19,代码来源:EventsimTopology.java

示例3: buildTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
public static StormTopology buildTopology(String redisIp, String redisPort) {
	// topology to build
	TopologyBuilder topology = new TopologyBuilder();

	// create a spout
	WikiCrawlerSpout wikiSpout = new WikiCrawlerSpout(redisIp, redisPort);

	// create a bolt
	WikiCrawlerExplorerBolt wikiBolt = new WikiCrawlerExplorerBolt(redisIp, redisPort);

	// set up the DAG
	// this spout always takes 1 task, it is light
	topology.setSpout("wikiSpout", wikiSpout, 1)
			.setNumTasks(2)
			.setMaxSpoutPending(5);
	// this bolt uses as many executors(threads) as the cores available
	topology.setBolt("wikiBolt", wikiBolt, numCores)
			.setNumTasks(numCores * 4) // 4 task per thread
			.shuffleGrouping("wikiSpout");

	return topology.createTopology();
}
 
开发者ID:sunil3590,项目名称:spiderz,代码行数:23,代码来源:WikiCrawlerTopology.java

示例4: main

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
public static void main(String[] args) {
	final Config conf = new Config();
	conf.setDebug(false);
	conf.setNumWorkers(2);
	conf.setMaxSpoutPending(1);
	conf.setFallBackOnJavaSerialization(false);
	conf.setSkipMissingKryoRegistrations(false);
	final LocalCluster cluster = new LocalCluster();
	final TopologyBuilder builder = new TopologyBuilder();
	builder.setSpout("randomSpout1", new RandomFieldSpout(2, 0, 0, 1)); // (nfields,seed,min,max)
	builder.setSpout("randomSpout2", new RandomFieldSpout(2, 10, 0, 1)); // (nfields,seed,min,max)
	JoinBolt.connectNewBolt(builder);
	final StormTopology topology = builder.createTopology();
	cluster.submitTopology("playTopology", conf, topology);
	Utils.sleep(10000);
	cluster.killTopology("playTopology");
	cluster.shutdown();

}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:20,代码来源:StormPlayground.java

示例5: buildProducerTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
/**
 * A topology that produces random sentences using {@link RandomSentenceSpout} and
 * publishes the sentences using a KafkaBolt to kafka "test" topic.
 *
 * @return the storm topology
 */
public StormTopology buildProducerTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new RandomSentenceSpout(), 2);
    /**
     * The output field of the RandomSentenceSpout ("word") is provided as the boltMessageField
     * so that this gets written out as the message in the kafka topic.
     */
    KafkaBolt bolt = new KafkaBolt()
            .withTopicSelector(new DefaultTopicSelector(KAFKA_TOPIC))
            .withTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper("key", "word"));
    builder.setBolt("forwardToKafka", bolt, 1).shuffleGrouping("spout");
    return builder.createTopology();
}
 
开发者ID:desp0916,项目名称:LearnStorm,代码行数:20,代码来源:TridentKafkaWordCount.java

示例6: buildTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
/**
 * WordCountTopology with Kafka
 *
 * @return      StormTopology Object
 */
public StormTopology buildTopology(String TOPIC) {

    SpoutConfig kafkaConf = new SpoutConfig(brokerHosts, TOPIC, "", "storm");
    kafkaConf.scheme = new SchemeAsMultiScheme(new StringScheme());

    TopologyBuilder builder = new TopologyBuilder();

    builder.setSpout(KAFKA_SPOUT_ID, new KafkaSpout(kafkaConf));
    builder.setBolt(SPLITTER_BOLT_ID, new SplitterBolt(), 4).shuffleGrouping(KAFKA_SPOUT_ID);
    builder.setBolt(COUNTER_BOLT_ID, new CounterBolt(), 4).fieldsGrouping(SPLITTER_BOLT_ID, new Fields("word"));
    builder.setBolt(RANKER_BOLT_ID, new RankerBolt()).globalGrouping(COUNTER_BOLT_ID);

    return builder.createTopology();
}
 
开发者ID:wipatrick,项目名称:docker-kafka-storm,代码行数:20,代码来源:WordCountTopology.java

示例7: constructTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
@Override
public StormTopology constructTopology() {
	TopologyBuilder b = new TopologyBuilder();
	b.setSpout("twitterKestrelSpout", new UnreliableKestrelThriftSpout(kestrelSpecList, new StringScheme("tweet"), inputQueue));
	TweetPreprocessingBolt bolt = new TweetPreprocessingBolt(outputQueue, kestrelHosts, twitterOptions.split(" "));
	bolt.setExpireTime(this.expire);
	b.setBolt("preprocessing", bolt).shuffleGrouping("twitterKestrelSpout");
	return b.createTopology();
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:10,代码来源:TwitterStormToolOptions.java

示例8: buildTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
/**
 * Return the object creating our moving average topology.
 */
private static StormTopology buildTopology() {

  TopologyBuilder builder = new TopologyBuilder();

  builder.setSpout("stock-ticks-spout", new StockTicksSpout());

  builder.setBolt("hdfs-persister-bolt", createHdfsBolt())
    .shuffleGrouping("stock-ticks-spout");

  builder.setBolt("parse-ticks", new ParseTicksBolt())
    .shuffleGrouping("stock-ticks-spout");

  builder.setBolt("calc-moving-avg", new CalcMovingAvgBolt(), 2)
    .fieldsGrouping("parse-ticks", new Fields("ticker"));

  return builder.createTopology();
}
 
开发者ID:amitchmca,项目名称:hadooparchitecturebook,代码行数:21,代码来源:MovingAvgLocalTopologyRunner.java

示例9: createTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
private static StormTopology createTopology() {
    TopologyBuilder topology = new TopologyBuilder();

    topology.setSpout("twitter_spout", new TwitterSpout());

    /*topology.setBolt("print", new PrinterBolt(), 4)
            .shuffleGrouping("twitter_spout");*/


    //topology.setSpout("twitter_spout", createKafkaSpout(), 4);

    topology.setBolt("twitter_filter", new TwitterFilterBolt(), 4)
            .shuffleGrouping("twitter_spout");

    topology.setBolt("text_filter", new TextFilterBolt(), 4)
            .shuffleGrouping("twitter_filter");

    topology.setBolt("stemming", new StemmingBolt(), 4)
            .shuffleGrouping("text_filter");

    topology.setBolt("positive", new PositiveSentimentBolt(), 4)
            .shuffleGrouping("stemming");
    topology.setBolt("negative", new NegativeSentimentBolt(), 4)
            .shuffleGrouping("stemming");

    topology.setBolt("join", new JoinSentimentsBolt(), 4)
            .fieldsGrouping("positive", new Fields("tweet_id"))
            .fieldsGrouping("negative", new Fields("tweet_id"));

    topology.setBolt("score", new SentimentScoringBolt(), 4)
            .shuffleGrouping("join");

    topology.setBolt("print", new PrinterBolt(), 4)
            .shuffleGrouping("score");

    topology.setBolt("csv", new CsvBolt(), 4)
            .shuffleGrouping("score");

    /*topology.setBolt("hdfs", createHdfsBolt(), 4)
            .shuffleGrouping("score");
    topology.setBolt("nodejs", new NodeNotifierBolt(), 4)
            .shuffleGrouping("score");*/

    return topology.createTopology();
}
 
开发者ID:mayconbordin,项目名称:erad2016-streamprocessing,代码行数:46,代码来源:SentimentAnalysisTopology.java

示例10: buildTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
public StormTopology buildTopology()
{
	Config conf = getConf();
	TopologyBuilder builder = new TopologyBuilder();

	int spout_Parallelism_hint = JStormUtils.parseInt(
			conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1);
	int bolt_Parallelism_hint = JStormUtils.parseInt(
			conf.get(TOPOLOGY_BOLT_PARALLELISM_HINT), 2);

	builder.setSpout(SequenceTopologyDef.SEQUENCE_SPOUT_NAME,
			new SequenceSpout(), spout_Parallelism_hint);

	boolean isEnableSplit = JStormUtils.parseBoolean(
			conf.get("enable.split"), false);

	if (isEnableSplit == false) {
		builder.setBolt(SequenceTopologyDef.TOTAL_BOLT_NAME,
				new TotalCount(), bolt_Parallelism_hint).localFirstGrouping(
				SequenceTopologyDef.SEQUENCE_SPOUT_NAME);
	} else {

		builder.setBolt(SequenceTopologyDef.SPLIT_BOLT_NAME,
				new SplitRecord(), bolt_Parallelism_hint)
				.localOrShuffleGrouping(
						SequenceTopologyDef.SEQUENCE_SPOUT_NAME);

		builder.setBolt(SequenceTopologyDef.TRADE_BOLT_NAME,
				new PairCount(), bolt_Parallelism_hint).shuffleGrouping(
				SequenceTopologyDef.SPLIT_BOLT_NAME,
				SequenceTopologyDef.TRADE_STREAM_ID);
		builder.setBolt(SequenceTopologyDef.CUSTOMER_BOLT_NAME,
				new PairCount(), bolt_Parallelism_hint).shuffleGrouping(
				SequenceTopologyDef.SPLIT_BOLT_NAME,
				SequenceTopologyDef.CUSTOMER_STREAM_ID);

		builder.setBolt(SequenceTopologyDef.MERGE_BOLT_NAME,
				new MergeRecord(), bolt_Parallelism_hint)
				.fieldsGrouping(SequenceTopologyDef.TRADE_BOLT_NAME,
						new Fields("ID"))
				.fieldsGrouping(SequenceTopologyDef.CUSTOMER_BOLT_NAME,
						new Fields("ID"));

		builder.setBolt(SequenceTopologyDef.TOTAL_BOLT_NAME,
				new TotalCount(), bolt_Parallelism_hint).noneGrouping(
				SequenceTopologyDef.MERGE_BOLT_NAME);
	}

	boolean kryoEnable = JStormUtils.parseBoolean(conf.get("kryo.enable"),
			false);
	if (kryoEnable == true) {
		System.out.println("Use Kryo ");
		boolean useJavaSer = JStormUtils.parseBoolean(
				conf.get("fall.back.on.java.serialization"), true);

		Config.setFallBackOnJavaSerialization(conf, useJavaSer);

		Config.registerSerialization(conf, TradeCustomer.class);
		Config.registerSerialization(conf, Pair.class);
	}
	int ackerNum = JStormUtils.parseInt(
			conf.get(Config.TOPOLOGY_ACKER_EXECUTORS), 1);
	Config.setNumAckers(conf, ackerNum);

	int workerNum = JStormUtils.parseInt(conf.get(Config.TOPOLOGY_WORKERS),
			20);
	conf.put(Config.TOPOLOGY_WORKERS, workerNum);

	return  builder.createTopology();	
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:71,代码来源:SequenceTopologyTool.java

示例11: createTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
private StormTopology createTopology(DRPCSpout spout) {
	final String SPOUT_ID = "spout";
	final String PREPARE_ID = "prepare-request";

	TopologyBuilder builder = new TopologyBuilder();
	builder.setSpout(SPOUT_ID, spout);
	builder.setBolt(PREPARE_ID, new PrepareRequest())
			.noneGrouping(SPOUT_ID);
	int i = 0;
	for (; i < _components.size(); i++) {
		Component component = _components.get(i);

		Map<String, SourceArgs> source = new HashMap<String, SourceArgs>();
		if (i == 1) {
			source.put(boltId(i - 1), SourceArgs.single());
		} else if (i >= 2) {
			source.put(boltId(i - 1), SourceArgs.all());
		}
		IdStreamSpec idSpec = null;
		if (i == _components.size() - 1
				&& component.bolt instanceof FinishedCallback) {
			idSpec = IdStreamSpec.makeDetectSpec(PREPARE_ID,
					PrepareRequest.ID_STREAM);
		}
		BoltDeclarer declarer = builder.setBolt(boltId(i),
				new CoordinatedBolt(component.bolt, source, idSpec),
				component.parallelism);

		for (Map conf : component.componentConfs) {
			declarer.addConfigurations(conf);
		}

		if (idSpec != null) {
			declarer.fieldsGrouping(idSpec.getGlobalStreamId()
					.get_componentId(), PrepareRequest.ID_STREAM,
					new Fields("request"));
		}
		if (i == 0 && component.declarations.isEmpty()) {
			declarer.noneGrouping(PREPARE_ID, PrepareRequest.ARGS_STREAM);
		} else {
			String prevId;
			if (i == 0) {
				prevId = PREPARE_ID;
			} else {
				prevId = boltId(i - 1);
			}
			for (InputDeclaration declaration : component.declarations) {
				declaration.declare(prevId, declarer);
			}
		}
		if (i > 0) {
			declarer.directGrouping(boltId(i - 1),
					Constants.COORDINATED_STREAM_ID);
		}
	}

	IRichBolt lastBolt = _components.get(_components.size() - 1).bolt;
	OutputFieldsGetter getter = new OutputFieldsGetter();
	lastBolt.declareOutputFields(getter);
	Map<String, StreamInfo> streams = getter.getFieldsDeclaration();
	if (streams.size() != 1) {
		throw new RuntimeException(
				"Must declare exactly one stream from last bolt in LinearDRPCTopology");
	}
	String outputStream = streams.keySet().iterator().next();
	List<String> fields = streams.get(outputStream).get_output_fields();
	if (fields.size() != 2) {
		throw new RuntimeException(
				"Output stream of last component in LinearDRPCTopology must contain exactly two fields. The first should be the request id, and the second should be the result.");
	}

	builder.setBolt(boltId(i), new JoinResult(PREPARE_ID))
			.fieldsGrouping(boltId(i - 1), outputStream,
					new Fields(fields.get(0)))
			.fieldsGrouping(PREPARE_ID, PrepareRequest.RETURN_STREAM,
					new Fields("request"));
	i++;
	builder.setBolt(boltId(i), new ReturnResults()).noneGrouping(
			boltId(i - 1));
	return builder.createTopology();
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:82,代码来源:LinearDRPCTopologyBuilder.java

示例12: main

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
public static void main(String[] args) {
        String consumerKey = "42NRnxnkuqrghnolDWSqbiFyv"; 
        String consumerSecret = "zmwC0g6z1FOBBQigW8w2lrnLYncuH4p3QX25RUCNa8aU1QSCC5"; 
        String accessToken = "2809571326-fyBz1ITFXf4yjuqZvHKgGyy0QcQfNVr8y2OGYq6"; 
        String accessTokenSecret = "MAnEtUccHXheXf0z2pauV75oj2XOm6ag4hiLvbUOh6n6B";
        int interval = 2000;
        
        String[] keyWords = new String[]{"cat", "car", "Stockholm", "snow", "data", "system", "Trump", "Palantir", "blue", "badger",
        		"NFL", "apple", "google", "facebook", "perks", "spg", "cajun", "banana", "taco", "whatever", "weareone", "packers", "green",
        		"NBA", "mlb", "dog", "kitten", "blueberry", "romance", "princess", "phone", "nuts", "sheldon", "mad", "talk", "nasty",
        		"procrastination", "cook", "college", "patriots", "dumnass", "dough", "winter", "game", "thrones", "halloween", "warcraft",
        		"hiking", "intern", "park", "sweater", "epic", "dota", "year", "wrath", "waste", "Blake", "street", "toyota", "arrow", 
        		"warning", "travel", "flight", "reject", "karaoke", "bless", "empire", "survivor", "bank", "dating", "restaurant", "tinder",
        		"shopping", "win", "cold", "recap", "cop", "astronaut", "crime", "book", "http", "injured", "china", "awards", "join", 
        		"ugly", "birthday", "friend", "weather", "shirt", "student", "mail", "sleep", "pet", "sea", "dream", "chritmas", "thanksgiving",
        		"vacation", "california", "church", "love", "fuck", "vote", "election", "bernie", "parade", "disney", "today", "city",
        		"marathon", "trade", "cash", "miles", "fun", "work", "free", "photo", "hard", "water", "god", "speech", "gang", "bear", 
        		"stop", "luck", "vegas", "shame", "food", "fool", "weight", "football", "tennis", "concert", "cancer", "stock", "crazy",
        		"ticket", "play", "project", "russia", "cast", "star", "trailer", "yelp", "video", "hawaii", "law", "rage", "comic", "meme",
        		"swag", "snack", "drink", "alcohol", "peace", "swift", "maroon", "xbox", "surface", "flower", "sport", "music", "traffic", "family",
        		"autograph", "selfie", "fans"}; 
        
        TopologyBuilder builder = new TopologyBuilder();
        
        builder.setSpout("friendsCount", new Q2RandomFriendsCountSpout(interval));
        builder.setSpout("hashtags", new Q2RandomHashtagSpout(interval, 100));
        builder.setSpout("tweets", new Q2SeqTwitterSpout(consumerKey, consumerSecret, accessToken, accessTokenSecret, keyWords));
        builder.setBolt("join1", new SingleJoinBolt(new Fields("seq", "friendsCount", "hashtags")))
        	.fieldsGrouping("friendsCount", new Fields("seq"))
        	.fieldsGrouping("hashtags", new Fields("seq"));
        builder.setBolt("join", new SingleJoinBolt(new Fields("friendsCount", "hashtags", "tweetinfolist")))
        	.fieldsGrouping("join1", new Fields("seq"))
        	.fieldsGrouping("tweets", new Fields("seq"));
        builder.setBolt("filter", new Q2FilterTweetBolt())
        	.shuffleGrouping("join");
//        builder.setBolt("printFiltered", new Q2PrintTweetBolt())
//    		.shuffleGrouping("filter");
//        builder.setBolt("cleanWord", new CleanWordsBolt())
//        	.shuffleGrouping("filter", "filterStream");
        builder.setBolt("splitWord", new SplitWordBolt())
        	.shuffleGrouping("filter");
        builder.setBolt("wordCount", new WordCountBolt(), 12)
        	.fieldsGrouping("splitWord", new Fields("word"));
        builder.setBolt("intermediateRanking", new IntermediateRankingsBolt())
        	.shuffleGrouping("wordCount");
        builder.setBolt("totalRanking",  new TotalRankingsBolt())
        	.globalGrouping("intermediateRanking");
        builder.setBolt("printFinal", new Q2PrintTweetBolt())
        	.shuffleGrouping("totalRanking");

                
        Config conf = new Config();
        conf.setDebug(true);
        
        final LocalCluster cluster = new LocalCluster();
        StormTopology topo = builder.createTopology();
        cluster.submitTopology("Q2", conf, topo);
        
        //Utils.sleep(interval * 100);
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				cluster.killTopology("Q2");
				cluster.shutdown();
			}
		});
        //cluster.shutdown();
    }
 
开发者ID:luozhaoyu,项目名称:big-data-system,代码行数:69,代码来源:Q2Stream.java

示例13: createTopology

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
private StormTopology createTopology(DRPCSpout spout) {
    final String SPOUT_ID = "spout";
    final String PREPARE_ID = "prepare-request";

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, spout);
    builder.setBolt(PREPARE_ID, new PrepareRequest()).noneGrouping(SPOUT_ID);
    int i = 0;
    for (; i < _components.size(); i++) {
        Component component = _components.get(i);

        Map<String, SourceArgs> source = new HashMap<String, SourceArgs>();
        if (i == 1) {
            source.put(boltId(i - 1), SourceArgs.single());
        } else if (i >= 2) {
            source.put(boltId(i - 1), SourceArgs.all());
        }
        IdStreamSpec idSpec = null;
        if (i == _components.size() - 1 && component.bolt instanceof FinishedCallback) {
            idSpec = IdStreamSpec.makeDetectSpec(PREPARE_ID, PrepareRequest.ID_STREAM);
        }
        BoltDeclarer declarer = builder.setBolt(boltId(i), new CoordinatedBolt(component.bolt, source, idSpec), component.parallelism);

        for (Map conf : component.componentConfs) {
            declarer.addConfigurations(conf);
        }

        if (idSpec != null) {
            declarer.fieldsGrouping(idSpec.getGlobalStreamId().get_componentId(), PrepareRequest.ID_STREAM, new Fields("request"));
        }
        if (i == 0 && component.declarations.isEmpty()) {
            declarer.noneGrouping(PREPARE_ID, PrepareRequest.ARGS_STREAM);
        } else {
            String prevId;
            if (i == 0) {
                prevId = PREPARE_ID;
            } else {
                prevId = boltId(i - 1);
            }
            for (InputDeclaration declaration : component.declarations) {
                declaration.declare(prevId, declarer);
            }
        }
        if (i > 0) {
            declarer.directGrouping(boltId(i - 1), Constants.COORDINATED_STREAM_ID);
        }
    }

    IRichBolt lastBolt = _components.get(_components.size() - 1).bolt;
    OutputFieldsGetter getter = new OutputFieldsGetter();
    lastBolt.declareOutputFields(getter);
    Map<String, StreamInfo> streams = getter.getFieldsDeclaration();
    if (streams.size() != 1) {
        throw new RuntimeException("Must declare exactly one stream from last bolt in LinearDRPCTopology");
    }
    String outputStream = streams.keySet().iterator().next();
    List<String> fields = streams.get(outputStream).get_output_fields();
    if (fields.size() != 2) {
        throw new RuntimeException(
                "Output stream of last component in LinearDRPCTopology must contain exactly two fields. The first should be the request id, and the second should be the result.");
    }

    builder.setBolt("JoinResult", new JoinResult(PREPARE_ID)).fieldsGrouping(boltId(i - 1), outputStream, new Fields(fields.get(0)))
            .fieldsGrouping(PREPARE_ID, PrepareRequest.RETURN_STREAM, new Fields("request"));
    i++;
    builder.setBolt("ReturnResults", new ReturnResults()).noneGrouping("JoinResult");
    return builder.createTopology();
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:69,代码来源:LinearDRPCTopologyBuilder.java

示例14: testStackImpl

import backtype.storm.topology.TopologyBuilder; //导入方法依赖的package包/类
/**
 * Tests the entire stack. Please note that the test fails, if the initial enactment is not working
 * correctly, e.g., due to the Reasoner.
 * 
 * @param defaultInit initialize the algorithm implementations by default (false requires adaptation layer 
 *     and rt-VIL)
 * @param initMode the configuration initialization mode
 * @throws IOException shall not occur
 */
public void testStackImpl(boolean defaultInit, InitializationMode initMode) throws IOException {
    InitializationMode iMode = configure(initMode); 
    int demo = MonitoringManager.setDemoMessageState(MonitoringManager.DEMO_MSG_INFRASTRUCTURE 
        | MonitoringManager.DEMO_MSG_PIPELINE | MonitoringManager.DEMO_MSG_PROCESSING_ALGORITHM 
        | MonitoringManager.DEMO_MSG_PROCESSING_ELEMENT); // required for monitoring msg
    TestDispatcher dispatcher = new TestDispatcher();
    endpoint = new ClientEndpoint(dispatcher, InetAddress.getLocalHost(), 
        AdaptationConfiguration.getAdaptationPort());
    dispatcher.registerForResponse(TestAuthenticationSupport.authenticate(endpoint, "JohnDoe"));
    LocalStormEnvironment env = new LocalStormEnvironment();
    AdaptationEventHandler adaptationEventHandler = new AdaptationEventHandler();
    EventManager.register(adaptationEventHandler);
    
    TopologyBuilder builder = new TopologyBuilder();
    Topology.createTopology(builder);
    StormTopology topology = builder.createTopology();
    Map<String, TopologyTestInfo> topologies = new HashMap<String, TopologyTestInfo>();
    // assign the topology data including its logging-enabled configuration (for this test)
    @SuppressWarnings("rawtypes")
    Map topoCfg = Naming.setDefaultInitializeAlgorithms(QmLogging.enable(createTopologyConfiguration()), 
        defaultInit);
    topologies.put(Naming.PIPELINE_NAME, new TopologyTestInfo(topology, 
        new File(Utils.getTestdataDir(), "pipeline.xml"), topoCfg));
    env.setTopologies(topologies);
    clear();
    
    EventManager.send(new PipelineCommand(Naming.PIPELINE_NAME, PipelineCommand.Status.START));
    // broken reasoner may prevent proper startup
    getPipelineStatusTracker().waitFor(Naming.PIPELINE_NAME, Status.STARTED, 30000); 
    clear();
    sleep(3000);

    sleep(1000);
    CoordinationCommand cmd = new ParameterChangeCommand<Integer>(Naming.PIPELINE_NAME, Naming.NODE_SOURCE, 
        "param", 5);
    EventManager.send(cmd);
    waitForExecution(1, 0);
    clear();

    sleep(4000); // let Storm run for a while
    // this is a command send by the adaptation layer itself
    cmd = new AlgorithmChangeCommand(Naming.PIPELINE_NAME, Naming.NODE_PROCESS, Naming.NODE_PROCESS_ALG2);
    EventManager.send(cmd);
    waitForExecution(1, 0);
    clear();
    sleep(1000);
    // this is a command sent via the client
    SwitchAlgorithmRequest saReq = new SwitchAlgorithmRequest(Naming.PIPELINE_NAME, Naming.NODE_PROCESS, 
        Naming.NODE_PROCESS_ALG1);
    endpoint.schedule(saReq);
    dispatcher.registerForResponse(saReq);
    sleep(2000); // let Storm run for a while

    EventManager.send(new PipelineCommand(Naming.PIPELINE_NAME, PipelineCommand.Status.STOP));
    waitForExecution(1, 0);
    clear();

    EventManager.unregister(adaptationEventHandler);
    env.shutdown();
    ThriftConnection.setLocalCluster(null);
    StormUtils.forTesting(null, null);
    EventManager.cleanup();
    env.cleanup();
    asserts(dispatcher);
    //Assert.assertTrue(adaptationEventHandler.recordedConstraintViolations());
    MonitoringManager.setDemoMessageState(demo);
    configure(iMode); 
}
 
开发者ID:QualiMaster,项目名称:Infrastructure,代码行数:78,代码来源:TopLevelStormTest.java


注:本文中的backtype.storm.topology.TopologyBuilder.createTopology方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。