public static VersionedObject FromJson(JToken token) { JToken value = token["value"]; DottedVersionVector dvv = DottedVersionVector.FromJson(token["clock"]); return(new VersionedObject(value, dvv)); }
public VersionedObject(JToken value, DottedVersionVector clock) { Ensure.That(value, "value").IsNotNull(); Ensure.That(clock, "clock").IsNotNull(); Value = value; Clock = clock; }
internal async Task PutAsync(string key, JToken value, VersionVector context = null) { Ensure.That(key, "key").IsNotNullOrWhiteSpace(); context = context ?? new VersionVector(); string coordinatingNode = _ring.Node(key); if (_ring.PreferenceList(key, N).Contains(_name)) { Log.DebugFormat("put k={0}", key); BigInteger hash = _ring.Hash(key); Siblings siblings = _data.GetValueOrDefault(hash); if (siblings != null) { // discard obsolete versions siblings = _kernel.Discard(siblings, context); } else { siblings = new Siblings(); } DottedVersionVector dvv = _kernel.Event(context, siblings, _name); var versionedObject = new VersionedObject(value, dvv); siblings.Add(versionedObject); _data[hash] = siblings; await ReplicatePutAsync(key, siblings); } else { Log.DebugFormat("forward to coordinating node {0}", coordinatingNode); await _remote.PutAsync(coordinatingNode, key, value, context); } }
public void Add(JToken value, string version) { Add(value, DottedVersionVector.Parse(version)); }
public void Add(JToken value, DottedVersionVector clock) { Add(new VersionedObject(value, clock)); }