Suzy Tros
Suzy Tros

Reputation: 373

how to emit and collect an arraylist in storm?

I have an arrayList that I want to emit and receive it in another bolt. So as suggested on another post here I used: the first bolt:

collector.emit(new Values(listI));

the next bolt:

public void execute(Tuple tuple) {
ArrayList<Integer> i = (ArrayList<Integer>)tuple.getValue(0);
....
}

but instead of a size 4 list, I am getting a list with size 0. Any thoughts?

Upvotes: 3

Views: 1288

Answers (1)

Kit Menke
Kit Menke

Reputation: 7056

Not sure what type listI is (I'm assuming an ArrayList). If so, your first bolt might have this:

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    List<Integer> listI = getSomeListOfIntegers();
    collector.emit(new Values(listI));
}

Make sure you also declare it in bolt 1:

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declare(new Fields("listI"));
}

Then in your second bolt:

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    List<Integer> listOfInts = (List<Integer>)tuple.getValue(0);
}

Upvotes: 2

Related Questions