Guest User

Untitled

a guest
Jun 25th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package org.apache.flink.streaming.examples.windowing;
  2.  
  3. import org.apache.flink.api.java.tuple.Tuple2;
  4. import org.apache.flink.streaming.api.datastream.DataStream;
  5. import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
  6. import org.apache.flink.streaming.api.functions.source.SourceFunction;
  7. import org.apache.flink.streaming.api.windowing.helper.Time;
  8.  
  9. import java.util.concurrent.TimeUnit;
  10.  
  11. public class PerfExp {
  12.  
  13.     public static void main(String[] args) throws Exception {
  14.  
  15.         final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  16.         //env.setParallelism(1); ///
  17.  
  18.         DataStream<Tuple2<Long, Long>> ds;
  19.         ds = env.addSource(new InfSource());
  20.         DataStream<Tuple2<Long, Long>> ds2 = ds
  21.                 .window(Time.of(1l, TimeUnit.SECONDS))
  22.                 .every(Time.of(1l, TimeUnit.SECONDS))
  23.                 .sum(1)
  24.                 .flatten();
  25.         ds2.print();
  26.  
  27.         env.execute("PerfExp");
  28.     }
  29.  
  30.  
  31.     static class InfSource implements SourceFunction<Tuple2<Long, Long>> {
  32.  
  33.         private static final long serialVersionUID = 1L;
  34.  
  35.         public InfSource() {
  36.  
  37.         }
  38.  
  39.         @Override
  40.         public void run(SourceContext<Tuple2<Long, Long>> ctx) throws Exception {
  41.  
  42.             Tuple2<Long, Long> record = new Tuple2<Long, Long>(0l, 1l);
  43.             while (true) {
  44.                 //Thread.sleep(1);
  45.                 ctx.collect(record);
  46.             }
  47.         }
  48.  
  49.         @Override
  50.         public void cancel() {}
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment