Database Reference
In-Depth Information
SpoutOutputCollector collector) {
this .collector = collector;
}
Like a bolt, a spout also defines output streams. There is the usual default
stream, defined by calling declare . Additionally, named streams can be
defined by calling declareStream , the same as bolts:
public void declareOutputFields(OutputFieldsDeclarer
declarer) {
declarer.declare( new
Fields("first","second","third"));
declarer.declareStream("errors", new Fields("error"));
}
Spouts are, by definition, pull-based polling interfaces. The Storm
infrastructure repeatedly calls the nextTuple method, which is similar to
the execute method in a Bolt:
public void nextTuple() {
Utils. sleep (100);
collector.emit( new Values("one","two","three"));
}
Because Storm does use a polling interface, it is recommended that a small
sleep command be added when there is no data to emit. This helps reduce
the system load when the topology is idle. In the simple example here, a
small delay serves much the same purpose.
In addition to being started, topologies can also be stopped, as well as
paused and resumed. This mostly affects the processing of the spout, which
has methods that can be used to start and stop the polling process.
Additionally, there is a close method when the topology shuts down to allow
for the clean shutdown of consumer interfaces:
public void close() {
}
public void activate() {
}
Search WWH ::




Custom Search