public override Tuple Take(Tuple tuple) { var request = new TakeRequest(ClientRequestSeqNumber, EndpointURL, tuple); Log("[SEQ:" + ClientRequestSeqNumber + "] Take: " + tuple); return(SendBlockingRequest(request)); }
public void VisitTake(Take take) { ClientResponse clientResponse; do { clientResponse = null; TakeRequest readRequest = new TakeRequest(this.client.Id, this.client.GetRequestNumber(), take.Tuple); while (clientResponse == null) { clientResponse = (ClientResponse)this.messageServiceClient.Request( readRequest, this.client.Leader, Timeout.TIMEOUT_SMR_CLIENT); if (clientResponse != null) { break; } this.client.DoHandShake(); } if (clientResponse.Result == null) { Thread.Sleep(Timeout.TIMEOUT_SMR_CLIENT_WAIT); } } while (clientResponse.Result == null); Console.WriteLine($"Take tuple = {clientResponse.Result}"); }
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}"); }
public override Tuple Take(Tuple tuple) { int timeStep = 250; // ms List <Message> messages = null; Message resultMessage = null; List <Tuple> intersection = new List <Tuple>(); Tuple selectedTuple = new Tuple(new List <object>()); // PHASE 1 var takeRequest = new TakeRequest(ClientRequestSeqNumber, EndpointURL, tuple); // wait for all responses MulticastMessageWaitAll(View.Nodes, takeRequest); WaitMessage(takeRequest, View.Nodes); ClientRequestSeqNumber++; lock (ReplyResultQueue) { ReplyResultQueue.TryGetValue(takeRequest, out var replyResult); messages = new List <Message>(replyResult?.GetAllResults()); } // get the intersection Response response; intersection = ((Response)messages.First()).Tuples; foreach (Message msg in messages) { response = (Response)msg; intersection = new List <Tuple>(intersection.Intersect(response.Tuples)); } // choose random tuple from intersection selectedTuple = intersection.ElementAt((new Random()).Next(0, intersection.Count)); // phase 2, issue a take remove and wait for all acks Message takeRemove = new TakeRemove(EndpointURL, selectedTuple, takeRequest.SeqNum); MulticastMessageWaitAll(View.Nodes, takeRemove); WaitMessage(takeRemove, View.Nodes); return(selectedTuple); }
public IResponse VisitTakeRequest(TakeRequest takeRequest) { if (!this.replicaState.IAmTheLeader()) { // I'm not the leader. return(null); } ProcessRequest runProcessRequestProtocol = this.RunProcessRequestProtocol(takeRequest); if (runProcessRequestProtocol == ProcessRequest.DROP) { return(null); } if (runProcessRequestProtocol == ProcessRequest.LAST_EXECUTION) { return(this.replicaState.ClientTable[takeRequest.ClientId].Item2); } return(null); }
public IResponse VisitTakeRequest(TakeRequest takeRequest) { return(this.WaitNormalState(takeRequest)); }
public JsonResult GetTake(TakeRequest request) { return(Json(bll.GetTake(request))); }
public IResponse VisitTakeRequest(TakeRequest takeRequest) { return(ExecuteRequest(takeRequest, new TakeExecutor(takeRequest))); }
/// <summary> /// 口味下拉框 /// </summary> /// <param name="request"></param> /// <returns></returns> public TakeResponse GetTake(TakeRequest request) { return(ApiRequestHelper.Post <TakeRequest, TakeResponse>(request)); }