Search in sources :

Example 1 with BaseComputeFunc

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));
}
Also used : BaseComputeFunc(edu.iu.dsc.tws.api.tset.fn.BaseComputeFunc) TSetContext(edu.iu.dsc.tws.api.tset.TSetContext) BatchChkPntEnvironment(edu.iu.dsc.tws.tset.env.BatchChkPntEnvironment) Iterator(java.util.Iterator) DataPartitionConsumer(edu.iu.dsc.tws.api.dataset.DataPartitionConsumer) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple)

Example 2 with BaseComputeFunc

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()));
}
Also used : TSetContext(edu.iu.dsc.tws.api.tset.TSetContext) BatchChkPntEnvironment(edu.iu.dsc.tws.tset.env.BatchChkPntEnvironment) BaseComputeFunc(edu.iu.dsc.tws.api.tset.fn.BaseComputeFunc) Iterator(java.util.Iterator) DataPartitionConsumer(edu.iu.dsc.tws.api.dataset.DataPartitionConsumer)

Aggregations

DataPartitionConsumer (edu.iu.dsc.tws.api.dataset.DataPartitionConsumer)2 TSetContext (edu.iu.dsc.tws.api.tset.TSetContext)2 BaseComputeFunc (edu.iu.dsc.tws.api.tset.fn.BaseComputeFunc)2 BatchChkPntEnvironment (edu.iu.dsc.tws.tset.env.BatchChkPntEnvironment)2 Iterator (java.util.Iterator)2 Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)1