我有以下代码用于风暴拓扑,我在群集上运行:
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word-reader", new WordReader());
builder.setBolt("word-normalizer", new WordNormalizer())
.shuffleGrouping("word-reader");
builder.setBolt("word-counter", new WordCounter()).fieldsGrouping(
"word-normalizer", new Fields("word"));
Config conf = new Config();
conf.put("wordsFile", args[0]);
conf.setDebug(false);
conf.put(Config.TOPOLOGY_MAX_SPOUT_PENDING, 1);
try {
StormSubmitter.submitTopology("Test-topology", conf,
builder.createTopology());
} catch (AlreadyAliveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidTopologyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
当我调试它时,以下cleanup()
方法不会在类WordCounter
中运行...
@Override
public void cleanup() {
System.out.println("-- Word Counter --");
}
...拓扑没有完成运行。
答案 0 :(得分:3)
<强>清理()强>
当您shutdown()
localcluster
时,以本地模式调用。但是当执行storm kill
或从nimbus服务器中删除时,不会在生产集群上(从不在生产集群上调用清理,仅在本地模式下调用)
// Keep commented if submitting to production cluster, since no
// automatic shutdown is required on production cluster
try {
// Runs for specified number of ms after submitting topology on
// local cluster and then resumes itself and shutdowns the
// local cluster
Thread.sleep(10000);
objOfLocalCluster.shutdown();
} catch (InterruptedException e) {
// Prints a stack trace for this Throwable object on the error
// output stream..
e.printStackTrace();
}
有关详情:请转到此docs
close()
(也适用于鲸鱼喷水)也会发生同样的事情here
答案 1 :(得分:0)