public Spacetime CreateSpacetime(IHEvent event_) { var st = new Spacetime(CreateHid(), event_, HIdFactory); ServiceManager.LocatingService.RegisterSpaceTime(st, event_); ServiceManager.SyncService.PullFromVmSt(st.ID); return st; }
private bool Patch(IHEvent fromEvent, IHEvent toEvent, long toRev, Stream delta) { if (toEvent.KnownBy(LatestUpdate)) throw new ApplicationException(string.Format("Trying to update to an older revision. Current {0}, Applying {1}", Rev, toRev)); if (m_patchMethod == StatePatchMethod.Auto) { try { StatePatchUtils.PatchState(delta, this); } catch (Exception ex) { Console.WriteLine("Failed to auto-patch state ({0}) from {1} to {2} with exception:\n{3}", StateId, fromEvent.ToString(), toEvent.ToString(), ex.ToString()); return false; } } else { if (!DoPatch(delta)) return false; } Rev = toRev; return true; }
public State(TStateId stateId, IHId spacetimeId, IHEvent expectingEvent, StatePatchMethod patchMethod) { StateId = stateId; SpacetimeID = spacetimeId; LatestUpdate = expectingEvent; m_patchMethod = patchMethod; Rev = 0; }
public void RegisterSpaceTime(Spacetime st, IHEvent event_) { lock (m_lock) { m_spaceTimes.Add(st.ID, st); m_localStorages.Add(st.ID, new LocalStorageMeta() { LatestUpdate = event_, Storage = st.StorageComponent }); } }
public void UpdateLocalStorage(IHId hid, IHEvent event_) { var meta = m_localStorages[hid]; meta.LatestUpdate = event_; foreach (var state in meta.Storage.GetNativeStates()) { m_localStates[state.StateId] = hid; } }
public SpacetimeSnapshot? GetSpacetime(IHId id, IHEvent evtAck) { lock (m_lock) { Spacetime st; if (m_spaceTimes.TryGetValue(id, out st)) return st.Snapshot(evtAck); return null; } }
internal void OnCommitting(IHEvent evtFinal) { LatestUpdate = evtFinal; Rev += 1; }
public StateSnapshot Snapshot( IHEvent overridingEvent) { return Snapshot(HTSFactory.Make(SpacetimeID, overridingEvent)); }
public StatePatch Serialize(StateSnapshot oldSnapshot, IHEvent expectingEvent) { var ostream = new MemoryStream(); Serialize(ostream, oldSnapshot); ostream.Close(); var patch = new StatePatch( this.GetPatchFlag(), oldSnapshot.Timestamp.Event, expectingEvent, ostream.ToArray() ); return patch; }
public bool PullRequest(IHId idPuller, IHId idRequester, IHEvent foreignExpectedEvent, ILookup<TStateId, StatePatch> affectedStates) { return m_spaceTimes[idPuller].PullRequest(idRequester, foreignExpectedEvent, affectedStates); }
public PrePullRequestResult PrePullRequest(IHId idPuller, IHId idRequester, IHEvent evtOriginal, IEnumerable<TStateId> affectedStates) { return m_spaceTimes[idPuller].PrePullRequest(idRequester, evtOriginal, affectedStates); }
public static IHTimestamp Make(IHId id, IHEvent event_) { return new ITCTimestamp(id as ITCIdentity, event_ as ITCEvent); }