use of edu.iu.dsc.tws.tset.links.batch.ReplicateTLink in project twister2 by DSC-SPIDAL.
the class BroadcastExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
SourceTSet<Integer> src = dummySource(env, COUNT, 1);
ReplicateTLink<Integer> replicate = src.replicate(PARALLELISM);
LOG.info("test foreach");
replicate.forEach(i -> LOG.info("foreach: " + i));
LOG.info("test map");
replicate.map(i -> i.toString() + "$$").direct().forEach(s -> LOG.info("map: " + s));
LOG.info("test flat map");
replicate.flatmap((i, c) -> c.collect(i.toString() + "##")).direct().forEach(s -> LOG.info("flat:" + s));
LOG.info("test compute");
replicate.compute((ComputeFunc<Iterator<Integer>, String>) input -> {
int sum = 0;
while (input.hasNext()) {
sum += input.next();
}
return "sum" + sum;
}).direct().forEach(i -> LOG.info("comp: " + i));
LOG.info("test computec");
replicate.compute((ComputeCollectorFunc<Iterator<Integer>, String>) (input, output) -> {
int sum = 0;
while (input.hasNext()) {
sum += input.next();
}
output.collect("sum" + sum);
}).direct().forEach(s -> LOG.info("computec: " + s));
LOG.info("test sink");
SinkTSet<Iterator<Integer>> sink = replicate.sink((SinkFunc<Iterator<Integer>>) value -> {
while (value.hasNext()) {
LOG.info("val =" + value.next());
}
return true;
});
env.run(sink);
}
Aggregations