use of edu.iu.dsc.tws.api.tset.fn.ComputeFunc 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);
}
use of edu.iu.dsc.tws.api.tset.fn.ComputeFunc in project twister2 by DSC-SPIDAL.
the class ComputeExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
int start = env.getWorkerID() * 100;
SourceTSet<Integer> src = dummySource(env, start, COUNT, PARALLELISM).setName("src").withSchema(PrimitiveSchemas.INTEGER);
ComputeTSet<Integer> sum = src.direct().compute((ComputeFunc<Iterator<Integer>, Integer>) input -> {
int s = 0;
while (input.hasNext()) {
s += input.next();
}
return s;
}).withSchema(PrimitiveSchemas.INTEGER).setName("sum");
sum.direct().forEach(data -> LOG.info("val: " + data));
sum.reduce(Integer::sum).forEach(i -> LOG.info("red: " + i));
}
Aggregations