[
https://issues.apache.org/jira/browse/STORM-2490?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Xin Wang updated STORM-2490:
----------------------------
Description:
In the past, If we want print tuples, we need to write the following code:
{code}
class PritingBolt extends BaseBasicBolt{
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
System.out.println(input);
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
// nothing
}
}
builder.setBolt("bolt2", new PritingBolt());
{code}
Now, with this patch:
{code}
builder.setBolt("bolt2", tuple -> System.out.println(tuple));
{code}
The above is just an simplest demo. This patch provides some new methods in
TopologyBuilder to allow you to use Java8 lambda expression:
{code}
setSpout(String id, SerializableSupplier<?> supplier)
setSpout(String id, SerializableSupplier<?> supplier, Number parallelism_hint)
// receiving tuple, and emitting to downstream
setBolt(String id, SerializableBiConsumer<Tuple,BasicOutputCollector>
biConsumer, String... fields)
setBolt(String id, SerializableBiConsumer<Tuple,BasicOutputCollector>
biConsumer, Number parallelism_hint, String... fields)
// receiving tuple, and never emitting to downstream
setBolt(String id, SerializableConsumer<Tuple> consumer)
setBolt(String id, SerializableConsumer<Tuple> consumer, Number
parallelism_hint)
{code}
Here is another example including the three interface usage:
{code}
// example. spout1: generate random strings
// bolt1: get the first part of a string
// bolt2: output the tuple
builder.setSpout("spout1", () -> UUID.randomUUID().toString());
builder.setBolt("bolt1", (tuple, collector) -> {
String[] parts = tuple.getStringByField("lambda").split("\\-");
collector.emit(new Values(parts[0]));
}, "field").shuffleGrouping("spout1");
builder.setBolt("bolt2", tuple ->
System.out.println(tuple)).shuffleGrouping("bolt1");
{code}
was:
In the past, If we want print tuples, we need to write the following code:
{code}
class PritingBolt extends BaseBasicBolt{
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
System.out.println(input);
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
// nothing
}
}
builder.setBolt("bolt2", new PritingBolt());
{code}
Now, with this patch:
{code}
builder.setBolt("bolt2", tuple -> System.out.println(tuple));
{code}
The above is just an simplest demo. This patch provides some new methods in
TopologyBuilder to allow you to use Java8 lambda expression:
{code}
setSpout(String id, SerializableSupplier<Object> supplier)
setSpout(String id, SerializableSupplier<Object> supplier, Number
parallelism_hint)
// receiving tuple, and user can decide to emit tuple to downstream or not
setBolt(String id, SerializableBiConsumer<Tuple,BasicOutputCollector>
biConsumer)
setBolt(String id, SerializableBiConsumer<Tuple,BasicOutputCollector>
biConsumer, Number parallelism_hint)
// receiving tuple, and never emitting to downstream
setBolt(String id, SerializableConsumer<Tuple> consumer)
setBolt(String id, SerializableConsumer<Tuple> consumer, Number
parallelism_hint)
{code}
Here is another example including the three interface usage:
{code}
// example. spout1: generate random strings
// bolt1: get the first part of a string
// bolt2: output the tuple
builder.setSpout("spout1", () -> UUID.randomUUID().toString());
builder.setBolt("bolt1", (tuple, collector) -> {
String[] parts = tuple.getStringByField("lambda").split("\\-");
collector.emit(new Values(parts[0]));
}).shuffleGrouping("spout1");
builder.setBolt("bolt2", tuple ->
System.out.println(tuple)).shuffleGrouping("bolt1");
{code}
> Lambda support
> --------------
>
> Key: STORM-2490
> URL: https://issues.apache.org/jira/browse/STORM-2490
> Project: Apache Storm
> Issue Type: New Feature
> Components: storm-client
> Reporter: Xin Wang
> Assignee: Xin Wang
> Time Spent: 3h
> Remaining Estimate: 0h
>
> In the past, If we want print tuples, we need to write the following code:
> {code}
> class PritingBolt extends BaseBasicBolt{
> @Override
> public void execute(Tuple input, BasicOutputCollector collector) {
> System.out.println(input);
> }
> @Override
> public void declareOutputFields(OutputFieldsDeclarer declarer) {
> // nothing
> }
> }
> builder.setBolt("bolt2", new PritingBolt());
> {code}
> Now, with this patch:
> {code}
> builder.setBolt("bolt2", tuple -> System.out.println(tuple));
> {code}
> The above is just an simplest demo. This patch provides some new methods in
> TopologyBuilder to allow you to use Java8 lambda expression:
> {code}
> setSpout(String id, SerializableSupplier<?> supplier)
> setSpout(String id, SerializableSupplier<?> supplier, Number parallelism_hint)
> // receiving tuple, and emitting to downstream
> setBolt(String id, SerializableBiConsumer<Tuple,BasicOutputCollector>
> biConsumer, String... fields)
> setBolt(String id, SerializableBiConsumer<Tuple,BasicOutputCollector>
> biConsumer, Number parallelism_hint, String... fields)
> // receiving tuple, and never emitting to downstream
> setBolt(String id, SerializableConsumer<Tuple> consumer)
> setBolt(String id, SerializableConsumer<Tuple> consumer, Number
> parallelism_hint)
> {code}
> Here is another example including the three interface usage:
> {code}
> // example. spout1: generate random strings
> // bolt1: get the first part of a string
> // bolt2: output the tuple
> builder.setSpout("spout1", () -> UUID.randomUUID().toString());
> builder.setBolt("bolt1", (tuple, collector) -> {
> String[] parts = tuple.getStringByField("lambda").split("\\-");
> collector.emit(new Values(parts[0]));
> }, "field").shuffleGrouping("spout1");
> builder.setBolt("bolt2", tuple ->
> System.out.println(tuple)).shuffleGrouping("bolt1");
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)