Esempio n. 1
0
        public void VisitTake(Take take)
        {
            string tupleToTake;

            // First phase: Lock and choose a tuple from intersection
            while (true)
            {
                IResponse[] responses = this.GetAndLock(take);

                List <List <string> > intersection = new List <List <string> >();
                foreach (IResponse response in responses)
                {
                    if (response != null && ((GetAndLockResponse)response).Tuples.Count > 0)
                    {
                        intersection.Add(((GetAndLockResponse)response).Tuples);
                    }
                }
                List <string> intersectTuples = ListUtils.IntersectLists(intersection);

                if (intersectTuples.Count <= 0)
                {
                    UnlockRequest unlockRequest = new UnlockRequest(
                        this.client.ViewNumber,
                        this.client.Id,
                        this.client.GetRequestNumber());
                    this.messageServiceClient.RequestMulticast(
                        unlockRequest,
                        this.client.ViewServers,
                        this.client.ViewServers.Length,
                        -1,
                        false);
                    Log.Debug("Take intersection is empty. Needs to be requested again.");
                    Thread.Sleep(Timeout.TIMEOUT_XL_CLIENT_WAIT);
                }
                else
                {
                    tupleToTake = intersectTuples[0];
                    break;
                }
            }

            // Second phase: Take
            TakeRequest takeRequest = new TakeRequest(
                this.client.ViewNumber,
                this.client.Id,
                this.client.GetRequestNumber(),
                tupleToTake);

            this.RequestMulticast(takeRequest);
            Console.WriteLine($"Take tuple = {tupleToTake}");
        }