/* Parse given input file into tupleBuffer */ private static void readTuplesFromFile(string filepath, TupleIdGenerator tupleIdGenerator) { TextReader freader; string line; try { freader = File.OpenText(filepath); } catch (Exception e) { Console.WriteLine("[ERROR] Unable to Open the file: \"{0}\". Proceding without it. {1}", filepath, e.Message); return; } Console.WriteLine("[Operator] Reading from file: {0}", filepath); while ((line = freader.ReadLine()) != null) { if (line.StartsWith("%")) // ignore comments { continue; } var tuple = line.Split(',').ToList(); for (int i = 0; i < tuple.Count; i++) { tuple[i] = tuple[i].Trim(' '); // strip whitespaces } thisReplica.Flow(new DadTuple(tupleIdGenerator.NextTupleId(), tuple)); } }
private void Process(DadTuple inputTuple) { Console.WriteLine("[CONSUMER] Starting computation of {0}.", inputTuple); // Process the tuple var computedTuples = Kernel.execute(inputTuple.Content); if (computedTuples.Count == 0) { return; } var outTuples = computedTuples.Select(t => new DadTuple(TupleIdGenerator.NextTupleId(), t)).ToList(); Console.WriteLine("[CONSUMER] Sharing results of computation of {0} to group.", inputTuple); Group.RMSend(p => p.SaveProcessedTuples(inputTuple.Id, outTuples)); //Group.LocalReplica.SaveProcessedTuples(inputTuple.Id, outTuples); // Is the last operator in the acyclic graph if (DownstreamOperators.Count == 0) { // Output to a file (if we are the leader) OutputToFile(outTuples); } else { // Send the tuples SendOutputTuples(outTuples); } // Log LogToPuppetMaster(outTuples); Group.RMSend(p => p.DeliveredTuples(inputTuple.Id, outTuples.Select(ot => ot.Id).ToList())); }