Exemple #1
0
        /// <summary>
        /// ConsumeRead gets tuple from bufferRead and processes it.
        /// </summary>
        public void ConsumeRead()
        {
            while (true)
            {
                while (operatorService.RepStatus.Equals("Unitialized"))
                {
                }
                //Get tuple from bufferRead
                Tuple  t = bufferRead.Consume();
                string log;

                if (operatorService.Comments)
                {
                    Console.WriteLine("Consumed tuple " + t.toString() + " from buffer of Read Tuples");
                }

                //Processing tuple
                IList <Tuple> tuplesToProcess = operatorService.processTuple(t);
                if (tuplesToProcess != null)
                {
                    foreach (Tuple tuple in tuplesToProcess)
                    {
                        //Mark tuple as read
                        tuplesRead.Add(tuple);

                        if (!operatorService.RepInfo.Semantics.Equals("at-most-once"))
                        {//If the routing of this replica is primary we want to share the readtuples array
                         //in order to have consistency while counting or check if a tuple is unique
                            if (operatorService.RepInfo.Routing.Equals("primary"))
                            {
                                foreach (string url in operatorService.RepInfo.SiblingsUrls.ToArray())
                                {
                                    if (url != null && !url.Equals(operatorService.RepInfo.MyUrl))
                                    {
                                        try
                                        {
                                            OperatorServices obj = (OperatorServices)Activator.GetObject(typeof(OperatorServices), url);
                                            obj.addTupleRead(tuple);
                                        }
                                        catch (System.Net.Sockets.SocketException e)
                                        {// if the other replica rejects the connection the tuple is not send to the sibling but there is no problem because it is dead
                                        }
                                    }
                                }
                            }
                        }

                        //Send log to PM
                        bufferProcessed.Produce(tuple);
                        Console.WriteLine("Processed tuple " + tuple.toString() + " and accepted.");
                        log = tuple.toString();
                        operatorService.NotifyPM("Tuple replica_URL: " + operatorService.RepInfo.MyUrl + ", " + "<" + log + ">");

                        //Checks availability to process a new tuple
                        while (operatorService.RepFreeze)
                        {
                        }
                        if (operatorService.RepCrash)
                        {
                            Console.WriteLine("HELP ME I AM GOING TO CRASH!! NOOOOO!!");
                            return;
                        }
                        Thread.Sleep(operatorService.RepInterval);
                    }
                }
                else
                {
                    Console.WriteLine("Processed tuple " + t.toString() + " and rejected.");
                }
            }
        }