Database Reference
In-Depth Information
require the transient keyword, they can often be initialized and serialized
unintentionally, leading to bugs that are difficult to track down. The
following code implements a bolt that captures the output collector:
public class RichEmptyBolt extends BaseRichBolt {
private static final long serialVersionUID = 0L;
private transient OutputCollector collector;
public void prepare(Map stormConf, TopologyContext
context,
OutputCollector collector) {
this .collector = collector;
}
Most bolts produce one or more streams of output. A stream is a collection
of Tuple objects that Storm serializes and passes to other bolt
implementations as defined within the topology. These Tuple objects do
not have a formal schema; all elements of the tuple are considered to be
generic Objects , but the elements are named. These names are used both
in the bolt's execute method and by certain grouping classes, such as
fieldGrouping . The order of these named fields is defined in the bolt's
declareOutputFields method. By default, the bolt has a single stream
that is defined by calling declare on the OutputFieldsDeclarer that is
passed into the method:
public void declareOutputFields(OutputFieldsDeclarer
declarer) {
declarer.declare( new
Fields("first","second","third"));
}
In addition to the default stream, a bolt can define other named streams
for output. Using the declareStream method, give the stream a name and
define the fields of the tuple. For example, to take the default stream and
split it into two parts, declare two output streams:
declarer.declareStream("car", new Fields("first"));
declarer.declareStream("cdr", new
Fields("second","third"));
Search WWH ::




Custom Search