// TODO: should run a separate thread to receive replies // only the coordinator should call this internal void prepare() { lock (_participantURLs) { Console.WriteLine("I'm the coordinator: " + MY_URL); if (_participantURLs.Count > 0) { foreach (String url in _participantURLs.Keys) { // TODO: A thread per participant // after all thread are sent, create one main thread responsible // for receiving votes (yes or no) - Assync callback (ver exemplo da aula 4) // and another one to run the timer Console.WriteLine("URL: " + url); IParticipant participant = (IParticipant)Activator.GetObject(typeof(IParticipant), url); //participant.canCommit(TX.TXID, MY_URL); // Create delegate to remote method RemoteAsyncDelegate RemoteDel = new RemoteAsyncDelegate(participant.canCommit); // Call delegate to remote method IAsyncResult RemAr = RemoteDel.BeginInvoke(TX.TXID, MY_URL, null, null); // Wait for the end of the call and then explictly call EndInvoke //RemAr.AsyncWaitHandle.WaitOne(); //Console.WriteLine(RemoteDel.EndInvoke(RemAr)); } timer(10000); MY_DECISION = waitParticipantsResponse(); evaluateMyDecision(); } else { // Coordinator decision // Default commit MY_DECISION = TransactionDecision.COMMIT; Console.WriteLine("AFTER MY_DECISION is commit and there are no participants"); // Send an update to the replica if there is one Replica.updateSucessor(TX.WRITTENOBJECTS); } // First phase of commit, temporary write to disk //writeAheadLog(); // if (MY_DECISION.Equals(TransactionDecision.COMMIT)) //writePermanentLog(); } }
internal static void doCommit(int txID, string coordURL) { TentativeTx tx = _tentativeTransactions[txID]; tx.PARTICIPANT.doCommit(txID, coordURL); // Send an update to the replica if there is one Console.WriteLine("MY OBJECTS ARE : "); //replaceValue(tx.WRITTENOBJECTS); addValues(tx.WRITTENOBJECTS); /* * foreach (ServerObject o in SERVEROBJECTS) * { * Console.WriteLine("\t UID= " + o.UID + " VALUE=" + o.VALUE); * } */ Replica.updateSucessor(tx.WRITTENOBJECTS); }
// The master ID of the worker server to replace public void setReplica(string sucessor, string predecessor) { Console.WriteLine("NOW MY SUCESSOR IS = " + sucessor + " PREDECESSOR IS = " + predecessor); Replica.setReplica(sucessor, predecessor); }
// Receive update from unknown server and update the replica list with the new values public void update(List <ServerObject> writtenObjects) { Console.WriteLine("Precessing update..."); Replica.update(writtenObjects); }