use of edu.iu.dsc.tws.tset.links.streaming.SDirectTLink in project twister2 by DSC-SPIDAL.
the class SReduceWindowExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
StreamingEnvironment env = TSetEnvironment.initStreaming(workerEnv);
SSourceTSet<Integer> src = dummySource(env, ELEMENTS_IN_STREAM, PARALLELISM);
SDirectTLink<Integer> link = src.direct();
if (COUNT_WINDOWS) {
if (PROCESS_WINDOW) {
WindowComputeTSet<Iterator<Integer>> winTSet = link.countWindow(2);
WindowComputeTSet<Iterator<Integer>> processedTSet = winTSet.process((WindowComputeFunc<Iterator<Integer>, Iterator<Integer>>) input -> {
List<Integer> list = new ArrayList<>();
while (input.hasNext()) {
list.add(input.next());
}
return list.iterator();
});
processedTSet.direct().forEach((ApplyFunc<Iterator<Integer>>) data -> {
while (data.hasNext()) {
System.out.println(data.next());
}
});
}
if (REDUCE_WINDOW) {
WindowComputeTSet<Integer> winTSet = link.countWindow(2);
WindowComputeTSet<Integer> localReducedTSet = winTSet.aggregate((AggregateFunc<Integer>) Integer::sum);
localReducedTSet.direct().forEach(x -> System.out.println(x));
}
}
if (DURATION_WINDOWS) {
if (PROCESS_WINDOW) {
System.out.println("DURATION PROCESS WINDOW");
WindowComputeTSet<Iterator<Integer>> winTSet = link.timeWindow(2, TimeUnit.MILLISECONDS);
WindowComputeTSet<Iterator<Integer>> processedTSet = winTSet.process((WindowComputeFunc<Iterator<Integer>, Iterator<Integer>>) input -> {
List<Integer> list = new ArrayList<>();
while (input.hasNext()) {
list.add(input.next());
}
return list.iterator();
});
processedTSet.direct().forEach((ApplyFunc<Iterator<Integer>>) data -> {
while (data.hasNext()) {
System.out.println(data.next());
}
});
}
if (REDUCE_WINDOW) {
WindowComputeTSet<Integer> winTSet = link.timeWindow(2, TimeUnit.MILLISECONDS);
WindowComputeTSet<Integer> localReducedTSet = winTSet.aggregate((AggregateFunc<Integer>) Integer::sum);
localReducedTSet.direct().forEach(x -> System.out.println(x));
// link.countWindow().reduce(a,b-> a + b)
}
}
// Runs the entire TSet graph
env.run();
}
use of edu.iu.dsc.tws.tset.links.streaming.SDirectTLink in project twister2 by DSC-SPIDAL.
the class SDirectExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
StreamingEnvironment env = TSetEnvironment.initStreaming(workerEnv);
SSourceTSet<Integer> src = dummySource(env, COUNT, PARALLELISM).setName("src");
SDirectTLink<Integer> link = src.direct().setName("dir");
link.map(i -> i * 2).setName("map").direct().forEach(i -> LOG.info("m" + i.toString()));
link.flatmap((i, c) -> c.collect("fm" + i)).setName("flatmap").direct().forEach(i -> LOG.info(i.toString()));
link.compute(i -> i + "C").setName("compute").direct().forEach(i -> LOG.info(i));
link.mapToTuple(i -> new Tuple<>(i, i.toString())).keyedDirect().forEach(i -> LOG.info("mapToTuple: " + i.toString()));
link.compute((input, output) -> output.collect(input + "DD")).setName("computec").direct().forEach(s -> LOG.info(s.toString()));
// Runs the entire TSet graph
env.run();
}
Aggregations