You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@storm.apache.org by "Xin Wang (JIRA)" <ji...@apache.org> on 2017/04/27 01:38:04 UTC

[jira] [Resolved] (STORM-2490) Lambda support

     [ https://issues.apache.org/jira/browse/STORM-2490?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Xin Wang resolved STORM-2490.
-----------------------------
       Resolution: Fixed
    Fix Version/s: 2.0.0

Merged into master.

> 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
>             Fix For: 2.0.0
>
>          Time Spent: 3.5h
>  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)