public bool Equals(FileVersion fileVersion) { // If parameter is null return false: if ((object)fileVersion == null) { return false; } return ((this.clientId == fileVersion.clientId) && (this.clock == fileVersion.clock)); }
public bool CheckQuorum(FileVersion vote, FileVersion original) { if ((vote != null) && (quorum[vote].Count >= this.quorumSize)) { if ((semantics == Helper.Semantics.MONOTONIC) && (FileVersion.MostRecent(vote, original) < 0)) { return false; } return true; } return false; }
public void AddVote(FileVersion vote, string id) { if (vote != null) { if (!quorum.ContainsKey(vote)) { quorum[vote] = new List<string>(); } quorum[vote].Add(id); } totalVotes++; }
public LatestVersion(FileVersion version, List<string> dataServerIds) { this.Version = version; this.DataServerIds = dataServerIds; }
public List<string> DataServersIds(FileVersion vote) { return quorum[vote]; }
// Returns: // >0 - if v1 is more recent than v2 // 0 - if they are the same // <0 - if v2 is more recent than v1 public static int MostRecent(FileVersion v1, FileVersion v2) { int clockDiff = v1.clock - v2.clock; if (clockDiff == 0) return string.Compare(v2.clientId, v1.clientId); return clockDiff; }
public FileData(FileVersion version, byte[] contents) { this.version = version; this.contents = contents; }
public FileData() { this.version = new FileVersion(); this.contents = Helper.StringToBytes(string.Empty); }
public static FileData Latest(FileData f1, FileData f2) { return((FileVersion.MostRecent(f1.version, f2.version) >= 0) ? f1 : f2); }
public FileData(FileVersion version, byte[] contents) { this.version = version; this.contents = contents; }
public FileData() { this.version = new FileVersion(); this.contents = Helper.StringToBytes(string.Empty); }