Пример #1
0
        public void SetOwner(DadTuple tuple, int ownerId)
        {
            Group.SetOwner(tuple, ownerId);

            if (ownerId == ReplicaID)
            {
                Console.WriteLine("[OWNERSHIP] Ownership acquired for {0}.", tuple);
                TupleProcessor.Post(tuple);
            }
        }
Пример #2
0
        public void Flow(DadTuple tuple)
        {
            Console.WriteLine("[IN] Received tuple {0}.", tuple);
            if (Group.HasShare(tuple))
            {
                Console.WriteLine("[IN] Tuple {0} had been received before. Ignoring.", tuple);
                return;
            }

            Group.RMSend(p => p.Share(tuple, ReplicaID));

            // Sleep for a certain interval (0 by default)
            System.Threading.Thread.Sleep(Interval);
        }
Пример #3
0
        public void SaveShare(DadTuple tuple, int interestedId)
        {
            Queue <int> interestedSet;

            if (Shared.TryGetValue(tuple, out interestedSet))
            {
                interestedSet.Enqueue(interestedId);
            }
            else
            {
                interestedSet = new Queue <int>();
                interestedSet.Enqueue(interestedId);
                Shared.Add(tuple, interestedSet);
            }
        }
Пример #4
0
        public void Share(DadTuple tuple, int senderId)
        {
            Console.WriteLine("[Share] Received share {0}.", tuple);

            if (Group.IsLeader(ReplicaID))
            {
                if (!Group.HasShare(tuple))
                {
                    Console.WriteLine("[LEADER] Setting the owner of tuple {0}.", tuple);
                    Group.RMSend(p => p.SetOwner(tuple, senderId));
                }
            }

            Group.SaveShare(tuple, senderId);
        }
Пример #5
0
        public bool Flow(DadTuple tuple, bool isLogging)
        {
            Console.WriteLine("[OUT] Sending tuple {0} to {1}", tuple, this);

            var sent = false;

            try
            {
                Proxy.Flow(tuple);
                sent = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("[OUT] Unable to send tuple to replica {0}. Reason: {1}.", this, e.Message);
            }

            return(sent);
        }
Пример #6
0
        public void Flow(DadTuple tuple, bool isLogging)
        {
            var sent = false;

            while (!sent && AliveReplicas.Count > 0)
            {
                var chosenReplicaIdx = Router.Route(tuple.Content, AliveReplicas.Count);
                var chosenReplica    = AliveReplicas[chosenReplicaIdx];

                sent = chosenReplica.Flow(tuple, isLogging);

                if (!sent)
                {
                    AliveReplicas.Remove(chosenReplica);
                }
            }

            if (!sent)
            {
                Console.WriteLine("[OUT] WARNING: Unable to send tuple to any replica of {0}.", Id);
            }
        }
Пример #7
0
        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()));
        }
Пример #8
0
 public void TupleWasProcessed(DadTuple upstreamTupleThatWasProcessed)
 {
     Kernel.TupleWasProcessed(upstreamTupleThatWasProcessed);
 }
Пример #9
0
 public async Task <bool> SendAsync(DadTuple tuple)
 {
     return(await TupleBuffer.SendAsync(tuple));
 }
Пример #10
0
 public bool Post(DadTuple tuple)
 {
     return(TupleBuffer.Post(tuple));
 }
Пример #11
0
 public override void TupleWasProcessed(DadTuple upstreamTupleThatWasProcessed)
 {
     history.Add(upstreamTupleThatWasProcessed.Content[fieldNum]);
 }
Пример #12
0
 public void SetOwner(DadTuple tuple, int ownerId)
 {
     Proxy.SetOwner(tuple, ownerId);
 }
Пример #13
0
 public bool HasShare(DadTuple tuple)
 {
     return(Shared.ContainsKey(tuple));
 }
Пример #14
0
 public void SetOwner(DadTuple tuple, int ownerId)
 {
     NoOwner.Remove(tuple);
     AllMembers[ownerId].AddOwnedTuple(tuple);
 }
Пример #15
0
 public void AddOwnedTuple(DadTuple tuple)
 {
     OwnedTuples.Add(tuple);
 }
Пример #16
0
 public virtual void TupleWasProcessed(DadTuple upstreamTupleThatWasProcessed)
 {
 }
Пример #17
0
 public void Share(DadTuple tuple, int senderId)
 {
     Proxy.Share(tuple, senderId);
 }