//Enters reader mode and if it found same valid tuple it enters write mode to remove it public TupleClass takeLeader(TupleClass tuple, int term) { tupleSpaceLock.EnterUpgradeableReadLock(); try { TupleClass res = new TupleClass(); foreach (TupleClass el in tupleSpace) { if (el.Matches(tuple)) { tupleSpaceLock.EnterWriteLock(); try { TakeEntry entry = new TakeEntry(tuple, term, getLogIndex(), "take"); addEntrytoLog(entry); res = el; tupleSpace.Remove(el); Console.WriteLine("Operation: Took " + res.ToString() + "\n"); return(res); } finally { tupleSpaceLock.ExitWriteLock(); } } } Console.WriteLine("Operation: Took " + res.ToString() + "\n"); return(res); //no match } finally { tupleSpaceLock.ExitUpgradeableReadLock(); } }
public override TupleClass take(TupleClass tuple, string url, long nonce) { TupleClass realTuple = _server.readLeader(tuple, false)[0]; TakeEntry entry = new TakeEntry(tuple, _term, _server.getLogIndex(), "take"); //arranjar lock para o log e tuplespace(?) _server.addEntrytoLog(entry); timer.Interval = wait; pulseAppendEntry(); return(_server.takeLeader(tuple)); }