Search in sources :

Example 6 with DataPartitionConsumer

use of edu.iu.dsc.tws.api.dataset.DataPartitionConsumer 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)6 Iterator (java.util.Iterator)5 TSetContext (edu.iu.dsc.tws.api.tset.TSetContext)4 BatchEnvironment (edu.iu.dsc.tws.tset.env.BatchEnvironment)3 Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)2 BaseComputeFunc (edu.iu.dsc.tws.api.tset.fn.BaseComputeFunc)2 BatchChkPntEnvironment (edu.iu.dsc.tws.tset.env.BatchChkPntEnvironment)2 Path (edu.iu.dsc.tws.api.data.Path)1 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)1 BaseComputeCollectorFunc (edu.iu.dsc.tws.api.tset.fn.BaseComputeCollectorFunc)1 RecordCollector (edu.iu.dsc.tws.api.tset.fn.RecordCollector)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Queue (java.util.Queue)1