Example #1
0
        /// <inheritdoc />
        protected override void RunRoutine()
        {
            try
            {
                LinkedList <Result> results = new LinkedList <Result>();

                Log(LogLevel.Debug, "Try to receive from PartitionRoutine");
                // fetch nr of tuples
                int tuples = InPipe.ReadInt();
                Log(LogLevel.Debug, $"{tuples} Tuples to process.");

                for (int i = 0; i < tuples; i++)
                {
                    // receive partition-id, key and value from in stream
                    string partition = InPipe.ReadString();
                    string key       = InPipe.ReadString();
                    int    size      = InPipe.ReadInt();
                    byte[] data      = InPipe.ReadBytes(size);

                    // store key value pair
                    Result result = Store(partition, key, data, i);
                    results.AddLast(result);
                    Log(LogLevel.Debug,
                        $"Stored {i + 1}/{tuples}: key {key} and {size} data bytes to partition {partition}");
                }

                // send ResultInfos to RoutineCommunicator (Worker)
                Log(LogLevel.Debug, $"Send {tuples} StoreResult object to RoutinesCommunicator (Worker)");
                Order order = new Order
                {
                    Command = Command.SEND_RESULT,
                    Value   = tuples.ToString()
                };
                CtrlPipe.Store(order);
                foreach (Result result in results)
                {
                    CtrlPipe.Store(result);
                }
            }
            catch (Exception e) when(e is TException || e is IOException)
            {
                Log(LogLevel.Error, $"Error while running StoreRoutine: {e.Message}");
                throw new RoutineException(e);
            }
        }
Example #2
0
        /// <inheritdoc />
        protected override void RunRoutine()
        {
            try
            {
                Log(LogLevel.Debug, "Try to receive result from ObjectiveRoutine");
                // Receive object from inPipe
                InPipe.ReadInt();
                T t = InPipe.Read(Activator.CreateInstance <T>());
                Log(LogLevel.Debug, $"Received from ObjectiveRoutine: {t.ToString()}");

                // Map function
                List <Tuple <string, TV> > tuples = Map(t);
                Log(LogLevel.Debug, $"Mapping done, created {tuples.Count} tuples");

                // Tell Receiver the number of tuples
                Log(LogLevel.Debug, "Storing number of tuples");
                OutPipe.Store(tuples.Count);

                // Store tuples to outPipe
                int i = 1;
                foreach (Tuple <string, TV> tuple in tuples)
                {
                    // Write key
                    Log(LogLevel.Debug, $"Write key {i}: {tuple.Item1}");
                    OutPipe.Store(tuple.Item1);
                    // Write value (size & data)
                    Log(LogLevel.Debug, $"Write value {i}: {tuple.Item2.ToString()}");
                    byte[] data = ThriftSerializer.Serialize(tuple.Item2);
                    OutPipe.Store(data.Length); // size
                    OutPipe.Store(data);
                    i++;
                }
            }
            catch (Exception e)
            {
                Log(LogLevel.Error, $"Error while running map routine: {e.Message}");
                throw new RoutineException(e);
            }
        }