internal void SendTotalOrder(string clientId, int requestId) { bool goingNewView = false; mIdTable[clientId] = requestId; TotalOrderData totalorderData = new TotalOrderData(requestId, sg); sg += 1; List <ServerData> replicasList = viewManager.GetKnownReplicas(); foreach (ServerData serverData in replicasList) { string serverProxyURL = $"tcp://{serverData.ServerURL}/{serverData.ServerName}"; try { ISMRServerService serverProxy = (ISMRServerService)Activator.GetObject(typeof(ISMRServerService), serverProxyURL); serverProxy.ReceiveTotalOrder(totalorderData); } catch (RemotingException) { goingNewView = true; break; } catch (SocketException) { goingNewView = true; break; } } if (goingNewView) { viewManager.TryViewChange(viewManager.GetKnownReplicas()); } Utils.Print("[*] SMR Server Sequencer: Sent TotalOrderData."); CheckHoldbackSequencerQueue(); //Checks if there are any messages than can be attributed now. }
internal ReplyData Take(RequestData requestData) { ViewManager viewM = viewManager; View view = viewM.GetView(); ServerData leaderData = view.Find(view.ManagerUId); if (leaderData.Equals(ServerData)) // As the View Leader. { receiveTakeTupleFromLeader.Reset(); List <List <DIDATuple> > serversMatchingTuples = new List <List <DIDATuple> >(); List <ServerData> replicasList = viewManager.GetKnownReplicas(); Utils.Print($" [*] SMR Server Leader: Calling {replicasList.Count()} servers.", verbose: Verbose); foreach (ServerData serverData in replicasList) { if (!serverData.Equals(leaderData)) { string serverProxyURL = $"tcp://{serverData.ServerURL}/{serverData.ServerName}"; ISMRServerService serverProxy = (ISMRServerService)Activator.GetObject(typeof(ISMRServerService), serverProxyURL); try { List <DIDATuple> matchingTuples = serverProxy.SendMatchingTuples(requestData.TupleData); serversMatchingTuples.Add(matchingTuples); } catch (SocketException) { viewManager.TryViewChange(viewManager.GetKnownReplicas()); } } } serversMatchingTuples.Add(GetMatchingTuples(requestData.TupleData)); PrintTuplesListsList(serversMatchingTuples); DIDATuple takeTuple = GetRandomIntersectedTuple(serversMatchingTuples); if (takeTuple == null) { return(new NoTupleFoundReply(requestData.RequestId)); } Utils.Print($" [*] SMR Server Leader: Taking {takeTuple}.", verbose: Verbose); // Removed tuple from all replicas. foreach (ServerData serverData in replicasList) { string serverProxyURL = $"tcp://{serverData.ServerURL}/{serverData.ServerName}"; ISMRServerService serverProxy = (ISMRServerService)Activator.GetObject(typeof(ISMRServerService), serverProxyURL); RequestData leaderTakeRequestData = new RequestData(0, 0, "", "", takeTuple, EOperationType.Take); try { serverProxy.ReceiveTakeTuple(leaderTakeRequestData); } catch (SocketException) { viewManager.TryViewChange(viewManager.GetKnownReplicas()); } } object toRemove = takeTuple; if (tupleSpace.TryTake(out toRemove)) { return(new TupleReply(requestData.RequestId, takeTuple)); } else { return(new NoTupleFoundReply(requestData.RequestId)); // Should be impossible to execute this else. } } // As a follower. else { receiveTakeTupleFromLeader.WaitOne(); // Waits for the signal of when the Take Tuple arrives. // After receiving the Tuple from the Leader, for the Take Operation. DIDATuple takeTuple = takeTupleFromLeader.TupleData; Utils.Print($" [*] SMR Server: Taking {takeTuple}.", verbose: Verbose); if (takeTuple == null) { return(new NoTupleFoundReply(requestData.RequestId)); } object toRemove = takeTuple; if (tupleSpace.TryTake(out toRemove)) { return(new TupleReply(requestData.RequestId, takeTuple)); } else { return(new NoTupleFoundReply(requestData.RequestId)); // Should be impossible to execute this else. } // Add send Leader an Ack. } }