Example #1
0
        /// <summary>
        /// Sends tuples to the next Operator in the channel.
        /// </summary>
        /// <param name="t">Tuple to be sent.</param>
        public void SendTuple(Tuple t, bool resend)
        {
            bool      last = true;
            ArrayList urls;


            foreach (string opx in OpsIds.ToArray())
            {
                if (opx != null)
                {
                    repInfo.SendInfoUrls.TryGetValue(opx, out urls);
                    if (urls.Count >= 1)
                    {
                        last = false;
                        sendTuplePolicy value;//Delegate that will use the policy of the replica to calculate the outgoing replica for this tuple t
                        policies.TryGetValue(this.repInfo.Next_routing, out value);
                        //Getting the OperatorServices object
                        try
                        {
                            OperatorServices obj = (OperatorServices)Activator.GetObject(typeof(OperatorServices), value(urls, t));
                            if (Comments)
                            {
                                obj.ping("PING!");
                            }

                            if (!resend && !RepInfo.Semantics.Equals("at-most-once"))
                            {
                                AddTupleToReceiveAck(t, resend);                        //Save tuple to receive ack stating if it is a resend or not
                                foreach (string url2 in RepInfo.SiblingsUrls.ToArray()) //share the acks that need to be received with its siblings
                                {
                                    if (url2 != null && !url2.Equals(RepInfo.MyUrl))
                                    {
                                        OperatorServices obj2 = (OperatorServices)Activator.GetObject(typeof(OperatorServices), url2);
                                        obj2.AddTupleToReceiveAck(t, resend);
                                        Console.WriteLine("Added receive ack of tuple: " + t.toString() + " to the sibling: " + url2);
                                    }
                                }
                            }
                            if (!RepInfo.Semantics.Equals("at-most-once"))
                            {
                                obj.AddTupleToBeAcked(t, RepInfo.MyUrl);//Added tuple to be acked in the receiving replica
                            }
                            obj.AddTupleToBuffer(t);
                        }
                        catch (System.Net.Sockets.SocketException e)
                        {// if the other replica rejects the connection the tuple is not send and the timer will make this replica resend the tuple to one of the possible sending replicas
                        }
                    }
                }
            }
            if (last)
            {
                if (comments)
                {
                    Console.WriteLine("I am one of the last operator's replica");
                }
                return;
            }
        }
Example #2
0
        /// <summary>
        /// Response to a Start command.
        /// Sending read tuples from files to the buffer.
        /// </summary>
        public void Start(RepInfo info)
        {
            this.repInfo   = info;
            this.repStatus = "Initialized";
            this.repStatus = "starting";
            IList <Tuple> tupleList    = new List <Tuple>();
            IList <Tuple> subTupleList = new List <Tuple>();

            SiblingsTimer = new Timer(AlivesParents.Method, this, ALIVE_TIMEOUT, ALIVE_TIMEOUT);
            ParentsTimer  = new Timer(AlivesSiblings.Method, this, ALIVE_TIMEOUT, ALIVE_TIMEOUT);
            startChildrenList();
            OperatorName = RepInfo.OperatorId + RepInfo.SiblingsUrls.IndexOf(info.MyUrl);
            foreach (string opx in repInfo.SendInfoUrls.Keys)
            {
                OpsIds.Add(opx);
            }

            foreach (string s in repInfo.Input)
            {
                if (s.Contains(".dat"))
                {
                    OpParser parser = new OpParser(s, OperatorName);
                    tupleList = parser.processFile();
                    if (info.SiblingsUrls.Count == 1)
                    {
                        subTupleList = tupleList;
                        //In this case all tuples are read by the replica
                    }
                    else
                    {
                        //In this case only a part of the tuples are read by the replica
                        int index         = info.SiblingsUrls.IndexOf(info.MyUrl);
                        int tupleListSize = tupleList.Count;
                        int parts         = tupleListSize / (info.SiblingsUrls.Count);
                        if (index == info.SiblingsUrls.Count - 1)
                        {
                            for (int i = index * parts; i < tupleListSize; i++)
                            {
                                subTupleList.Add(tupleList[i]);
                            }
                        }
                        else
                        {
                            for (int i = index * parts; i < (index + 1) * parts; i++)
                            {
                                subTupleList.Add(tupleList[i]);
                            }
                        }
                    }

                    foreach (Tuple t in subTupleList)
                    {
                        threadPool.AssyncInvoke(t);//Tuples from file dont need to be acked
                    }
                }
            }
            this.repStatus = "working";
        }