예제 #1
0
        public void Stop()
        {
            if (InPipe != null)
            {
                if (InPipe.IsConnected)
                {
                    InPipe.Disconnect();
                }
                InPipe.Close();
                InPipe.Dispose();
                InPipe = null;
            }

            if (OutPipe != null)
            {
                if (OutPipe.IsConnected)
                {
                    OutPipe.Disconnect();
                }
                OutPipe.Close();
                OutPipe.Dispose();
                OutPipe = null;
            }

            Status = ConnStatus.Disconnected;
        }
예제 #2
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (InPipe != null && InPipe.HasMesage)
     {
         var   order       = InPipe.GetMessage();
         Order transfromed = order;
         if (IsForMe(order))
         {
             transfromed = Transform(order);
         }
         OutPipe.PutMessage(transfromed);
     }
 }
예제 #3
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (InPipe != null && InPipe.HasMessage)
            {
                var inOrder = InPipe.Get();

                var outOrder = Transform(inOrder);

                if (outOrder != null && OutPipe != null)
                {
                    OutPipe.Put(outOrder);
                }
            }
        }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
        /// <summary>
        /// Fetch an input parameter from the input pipe by its name. A command will be sent to the control pipe to
        /// feed the parameter to the input pipe, which will be read and mapped to the specific type T.
        /// </summary>
        /// <param name="name">The name of the input parameter to search for</param>
        /// <typeparam name="T">The type of the parameter to map to, which needs to be a Thrift generated type</typeparam>
        /// <returns>Returns an instance of type T created from the parameter</returns>
        /// <exception cref="AccessParameterException">If there is an error reading the parameter</exception>
        protected T GetParameter <T>(string name) where T : TBase
        {
            Log(LogLevel.Debug, $"Requesting Parameter {name}");

            Order getParam = new Order
            {
                Command = Command.GET_PARAMATER,
                Value   = name
            };

            try
            {
                CtrlPipe.Store(getParam);
                T param = InPipe.Read(Activator.CreateInstance <T>());
                Log(LogLevel.Debug, $"Received: {param}");
                return(param);
            }
            catch (Exception e)
            {
                throw new AccessParameterException(e);
            }
        }