public override Responses SetValue() { Responses res = new Responses(Status.success); GCPayload pl = new GCPayload(uid, (int)Config.numReplicas, (int)Config.replicaId); pl.valueVector[pl.replicaid] = this.parameters.GetParam <int>(0); this.payload = pl; res.AddResponse(Dest.client); Parameters syncPm = new Parameters(1); syncPm.AddParam(0, this.payload.valueVector); string broadcast = Parser.BuildCommand(this.typecode, "y", this.uid, syncPm); res.AddResponse(Dest.broadcast, broadcast, false); return(res); }
public override Responses GetValue() { Responses res; if (this.payload is null) { res = new Responses(Status.fail); res.AddResponse(Dest.client, "Gcounter with id {0} cannot be found"); } var observed = new HashSet <(string value, string tag)>(this.payload.addSet); observed.ExceptWith(this.payload.removeSet); // construct a list of string StringBuilder sb = new StringBuilder(); foreach (var item in observed) { sb.Append(item.value + ","); } res = new Responses(Status.success); res.AddResponse(Dest.client, sb.ToString()); noSideEffect = true; return(res); }
public override Responses SetValue() { Responses res = new Responses(Status.success); RCounterPayload pl = new RCounterPayload(uid, (int)Config.numReplicas, (int)Config.replicaId); RCounterPayload oldstate = pl.CloneValues(); int value = this.parameters.GetParam <int>(0); if (value >= 0) { pl.PVector[pl.replicaid] = value; } else { pl.NVector[pl.replicaid] = -value; } this.payload = pl; string opid = this.history.AddNewEntry(oldstate, this.payload, RCounterPayload.PayloadToStr); GenerateSyncRes(ref res, opid); res.AddResponse(Dest.client, opid); return(res); }
public Responses Increment() { this.payload.valueVector[this.payload.replicaid] += this.parameters.GetParam <int>(0); Responses res = new Responses(Status.success); Parameters syncPm = new Parameters(1); syncPm.AddParam(0, this.payload.valueVector); string broadcast = Parser.BuildCommand(this.typecode, "y", this.uid, syncPm); res.AddResponse(Dest.client); res.AddResponse(Dest.broadcast, broadcast, false); return(res); }
public override Responses GetValue() { // to set up responses Responses res; res = new Responses(Status.success); // to add client response res.AddResponse(Dest.client, "response string here"); // to make a broadcast for synchronization res.AddResponse(Dest.broadcast, "broad cast string here", false); throw new NotImplementedException(); // return response at the end return(res); }
public override Responses SetValue() { this.payload = new ORSetPayload(uid); Responses res = new Responses(Status.success); res.AddResponse(Dest.client); GenerateSyncRes(ref res); return(res); }
public override Responses GetValue() { // 1. calculate initial value // 2. go to tombstone and retract everything Responses res; if (this.payload is null) { res = new Responses(Status.fail); res.AddResponse(Dest.client, "Rcounter with id {0} cannot be found"); } else { int pos = payload.PVector.Sum(); int neg = payload.NVector.Sum(); int compensate = 0; // calculated ones been reversed foreach (var tombed in this.history.tombstone) { string starttime; string endtime; history.GetEntry(tombed, out starttime, out endtime, out _); List <String> toReversed = history.CasualSearch(starttime, endtime); foreach (var ops in toReversed) { RCounterPayload newstate; RCounterPayload oldstate; history.GetEntry(ops, RCounterPayload.StrToPayload, out oldstate, out newstate, out _); int diff = (newstate.PVector.Sum() - newstate.NVector.Sum()) - (oldstate.PVector.Sum() - oldstate.NVector.Sum()); RCounterPayload pl = this.payload; compensate -= diff; } } DEBUG("actual value: " + (pos - neg).ToString() + " compensate: " + compensate); res = new Responses(Status.success); res.AddResponse(Dest.client, (pos - neg + compensate).ToString()); } noSideEffect = true; return(res); }
private void GenerateSyncRes(ref Responses res, string newop) { Parameters syncPm = new Parameters(2); syncPm.AddParam(0, this.payload.PVector); syncPm.AddParam(1, this.payload.NVector); string broadcast = Parser.BuildCommand(this.typecode, "y", this.uid, syncPm); res.AddResponse(Dest.broadcast, broadcast, false); }
public IActionResult Reply(Guest guest) { if (ModelState.IsValid) { Responses.AddResponse(guest); return(View("Thanks", guest)); } else { return(View()); } }
public Responses Add() { string tag = UniqueTag(); this.payload.addSet.Add((this.parameters.GetParam <string>(0), tag)); Responses res = new Responses(Status.success); res.AddResponse(Dest.client); GenerateSyncRes(ref res); return(res); }
public void Sync(string newop, int status = 0) { DEBUG("Syncing new op " + newop); Responses res = new Responses(Status.success); Parameters syncPm = new Parameters(2); syncPm.AddParam(0, newop); syncPm.AddParam(1, status); string broadcast = Parser.BuildCommand("h", "y", this.uid, syncPm); res.AddResponse(Dest.broadcast, broadcast, false); Global.server.StageResponse(res); }
public Responses Increment() { RCounterPayload oldstate = this.payload.CloneValues(); this.payload.PVector[this.payload.replicaid] += this.parameters.GetParam <int>(0); string opid = this.history.AddNewEntry(oldstate, this.payload, RCounterPayload.PayloadToStr); Responses res = new Responses(Status.success); res.AddResponse(Dest.client, opid); GenerateSyncRes(ref res, opid); return(res); }
/// <summary> /// Called on every update of CRDT OP to /// synchronize the history /// </summary> /// <param name="newop"></param> /// <param name="status">0 = op, 1 = tombstone, 2 = related</param> public void Sync(StateHisotryEntry newop, int status = 0) { DEBUG("Syncing new op " + newop.opid); string json = JsonConvert.SerializeObject(newop, Formatting.Indented); Responses res = new Responses(Status.success); Parameters syncPm = new Parameters(2); syncPm.AddParam(0, json); syncPm.AddParam(1, status); string broadcast = Parser.BuildCommand("h", "y", this.uid, syncPm); res.AddResponse(Dest.broadcast, broadcast, false); Global.server.StageResponse(res); }
public Responses Reverse() { Responses res = new Responses(Status.success); string opid = this.parameters.GetParam <String>(0); string startime = this.history.log[opid].time; string curTime = this.history.curTime.ToString(); string reverseop = this.history.AddNewEntry(startime, curTime, true); DEBUG("reversed until: " + reverseop); this.history.addTombstone(reverseop); res.AddResponse(Dest.client); return(res); }
public override Responses GetValue() { Responses res; if (this.payload is null) { res = new Responses(Status.fail); res.AddResponse(Dest.client, "Gcounter with id {0} cannot be found"); } else { res = new Responses(Status.success); res.AddResponse(Dest.client, payload.valueVector.Sum().ToString()); } noSideEffect = true; return(res); }
public override Responses GetValue() { Responses res; if (this.payload is null) { res = new Responses(Status.fail); res.AddResponse(Dest.client, "Rcounter with id {0} cannot be found"); } else { int pos = payload.PVector.Sum(); int neg = payload.NVector.Sum(); res = new Responses(Status.success); res.AddResponse(Dest.client, (pos - neg).ToString()); } return(res); }
// human readable version public override Responses GetValue() { long mem = Global.profiler.GetCurrentMemUsage(); long peakmem = Profiler.peakMemUsage; int totalops = Profiler.clientOpsTotal; int succeedOps = Profiler.clientOpsSuccess; var res = new Responses(Status.success); var report = string.Format( @"===Performance Report=== Current Memory Usage: {0} Peak Memory Usage: {1} Total Operation Succeeded: {2} Total Operation Executed: {3}" , mem / 1000000, peakmem / 1000000, succeedOps, totalops); res.AddResponse(Dest.client, report); return(res); }
public override Responses SetValue() { Responses res = new Responses(Status.success); PNCPayload pl = new PNCPayload(uid, (int)Config.numReplicas, (int)Config.replicaId); int value = this.parameters.GetParam <int>(0); if (value >= 0) { pl.PVector[pl.replicaid] = value; } else { pl.NVector[pl.replicaid] = -value; } this.payload = pl; GenerateSyncRes(ref res, ""); res.AddResponse(Dest.client); return(res); }