use of edu.iu.dsc.tws.api.tset.fn.BaseComputeFunc in project twister2 by DSC-SPIDAL.
the class KeyedCheckpointingExample method execute.
@Override
public void execute(WorkerEnvironment workerEnvironment) {
BatchChkPntEnvironment env = TSetEnvironment.initCheckpointing(workerEnvironment);
int count = 5;
KeyedSourceTSet<String, Integer> src = dummySource(env, count, 0);
KeyedPersistedTSet<String, Integer> persist = src.keyedDirect().persist();
persist.keyedDirect().forEach(i -> LOG.info(i.toString()));
KeyedSourceTSet<String, Integer> src1 = dummySource(env, count, 10);
src1.keyedDirect().compute(new BaseComputeFunc<Iterator<Tuple<String, Integer>>, String>() {
private DataPartitionConsumer<Tuple<String, Integer>> in;
@Override
public void prepare(TSetContext ctx) {
super.prepare(ctx);
in = (DataPartitionConsumer<Tuple<String, Integer>>) ctx.getInput("in").getConsumer();
}
@Override
public String compute(Iterator<Tuple<String, Integer>> input) {
StringBuilder out = new StringBuilder();
while (input.hasNext() && in.hasNext()) {
Tuple<String, Integer> t = input.next();
Tuple<String, Integer> next = in.next();
out.append("(").append(t).append(",").append(next).append(") ");
}
return out.toString();
}
}).addInput("in", persist).direct().forEach(i -> LOG.info(i));
}
use of edu.iu.dsc.tws.api.tset.fn.BaseComputeFunc in project twister2 by DSC-SPIDAL.
the class CheckpointingExample method execute.
@Override
public void execute(WorkerEnvironment workerEnvironment) {
BatchChkPntEnvironment env = TSetEnvironment.initCheckpointing(workerEnvironment);
int count = 5;
SourceTSet<Integer> src = dummySource(env, count, 100 * env.getWorkerID());
PersistedTSet<Integer> persist = src.direct().persist();
SourceTSet<Integer> src1 = dummySource(env, count, 100 * env.getWorkerID() + 10);
src1.direct().compute(new BaseComputeFunc<Iterator<Integer>, String>() {
private DataPartitionConsumer<Integer> in;
@Override
public void prepare(TSetContext ctx) {
super.prepare(ctx);
in = (DataPartitionConsumer<Integer>) ctx.getInput("in").getConsumer();
}
@Override
public String compute(Iterator<Integer> input) {
StringBuilder out = new StringBuilder();
while (input.hasNext() && in.hasNext()) {
out.append("(").append(input.next()).append(",").append(in.next()).append(") ");
}
return out.toString();
}
}).addInput("in", persist).direct().forEach(i -> LOG.info(i));
persist.direct().forEach(i -> LOG.info(i.toString()));
}
Aggregations