public VMSpacetime(IHId hid, IHIdFactory idFactory) : base(hid, HTSFactory.CreateZeroEvent(), idFactory) { VMStateId = m_vm.StateId; m_storageComponent.AddNativeState(m_vm); ServiceManager.LocatingService.RegisterObject(VMStateId, m_vm.GetType().FullName, m_vm); }
public static void Migrate([State] SpacetimeStorage arriving, [State] SpacetimeStorage departuring, TStateId immigrant) { if (!departuring.HasNativeState(immigrant)) throw new RuntimeException("Failed to migrate `{0}` from `{1}` to `{2}`: no such state in storage", immigrant, departuring, arriving); departuring.RemoveNativeState(immigrant); arriving.AddNativeState(immigrant); }
public State(TStateId stateId, IHId spacetimeId, IHEvent expectingEvent, StatePatchMethod patchMethod) { StateId = stateId; SpacetimeID = spacetimeId; LatestUpdate = expectingEvent; m_patchMethod = patchMethod; Rev = 0; }
public void Reset() { lock (m_lock) { m_vmST = null; m_vmStateId = new TStateId(); m_spaceTimes.Clear(); } }
internal State GetOrCreate(TStateId id, Func<State> constructor) { var retval = GetState(id); if (retval != null) return retval; retval = constructor(); if (retval == null) throw new ArgumentException("The provided constructor doesn't always provide a State object"); CacheAdd(retval.StateId, retval); return retval; }
public StateSnapshot AggregateDistributedDelta(TStateId state) { return DoAggregateDistributedDelta(m_spaceTimes.Values, state); }
internal State GetState(TStateId id) { return CacheTouch(id); }
private State CacheTouch(TStateId id) { StateCacheEntry entry; if (!m_stateCache.TryGetValue(id, out entry)) return null; entry.lastTouch = DateTime.Now; return entry.ref_; }
private void CacheAdd(TStateId id, State ref_) { var newState = ref_; StateCacheEntry entry; if (!m_stateCache.TryGetValue(newState.StateId, out entry)) { entry = new StateCacheEntry(); m_stateCache.Add(newState.StateId, entry); } entry.ref_ = newState; entry.lastTouch = DateTime.Now; ++entry.refCount; }
internal void AddNativeState(TStateId id) { StateCacheEntry s; if (!m_stateCache.TryGetValue(id, out s)) throw new ApplicationException(string.Format("Can't promote/immigrate state `{0}` to a native state, can't find it in `{1}`" , id, SpacetimeID)); s.ref_.OnMigratingTo(this.SpacetimeID); m_nativeStates.Add(id, s.ref_); s.refCount += 1; }
protected override bool DoPatch(Stream delta) { var reader = new BinaryReader(delta); while (reader.PeekChar() != -1) { if (reader.PeekChar() != MAGICBYTE) return false; reader.ReadChar(); var stateid = new TStateId(reader.ReadUInt64()); var refType = reader.ReadString(); var state = Dereference(stateid, refType); m_nativeStates.Add(stateid, state); CacheAdd(stateid, state); } return true; }
public State Dereference(TStateId sid) { return GetState(sid); }
private StateSnapshot DoAggregateDistributedDelta(IEnumerable<Spacetime> spacetimes, TStateId stateId) { // find first ST that contains the state StateSnapshot seed = StateSnapshot.CreateNull(stateId); int skipCount = 0; foreach (var st in spacetimes) { seed = st.ExportStateSnapshot(stateId); ++skipCount; if (!string.IsNullOrEmpty(seed.TypeName)) break; } // cleanup all non-CommutativeDelta in seed foreach (var f in seed.Fields) { if (0 == (f.Attrib.PatchKind & FieldPatchCompatibility.CommutativeDelta)) f.Value = null; } return DoAggregateDistributedDelta(spacetimes.Skip(skipCount), stateId, seed); }
public IHId GetObjectSpaceTimeID(TStateId sid) { return m_naming.GetObjectSpaceTimeID(sid.ToString()); }
public State GetObject(TStateId sid, string objType) { return (State)m_naming.GetObject(sid.ToString(), objType); }
public bool RegisterObject(TStateId sid, string objType, State ptr) { return m_naming.RegisterObject(sid.ToString(), objType, ptr); }
public void Initialize(VMSpacetime vmST) { m_vmST = vmST; m_vmStateId = vmST.VMStateId; }
private StateSnapshot DoAggregateDistributedDelta(IEnumerable<Spacetime> spacetimes, TStateId stateId, StateSnapshot seed) { foreach (var spacetime in spacetimes.Skip(1)) { var state = spacetime.ExportStateSnapshot(stateId); seed.Aggregate(state); } return seed; }
public Account(TStateId sid, IHTimestamp stamp) : base(sid, stamp.ID, stamp.Event, StatePatchMethod.Auto) { }
public RecorderQuery Logic(TStateId stateName) { CheckNext(new StateEvent(stateName, StateAction.LOGIC)); return(this); }
public State Dereference(TStateId sid, string refType) { var state = GetState(sid); if (state.GetType().ToString() != refType) throw new RuntimeException(string.Format("Type check failed when dereferencing state `{0}`: expecting `{1}` got `{2}`" , sid, refType, state.GetType().ToString())); return state; }
public RecorderQuery Exit(TStateId stateName) { CheckNext(new StateEvent(stateName, StateAction.EXIT)); return(this); }
internal bool HasNativeState(TStateId id) { return m_nativeStates.ContainsKey(id); }
public RecorderQuery TransitionEnter(TStateId from, TStateId to) { CheckNext(new TransitionEvent(from, to, TransitionAction.ENTER)); return(this); }
internal void RemoveNativeState(TStateId id) { m_nativeStates.Remove(id); CacheRemove(id); }
public RecorderQuery ShouldTransition(TStateId from, TStateId to) { CheckNext(new TransitionEvent(from, to, TransitionAction.SHOULD_TRANSITION)); return(this); }
private void CacheRemove(TStateId id) { var entry = m_stateCache[id]; if (--entry.refCount <= 0) m_stateCache.Remove(id); }
public StateEvent(TStateId state, StateAction action) { this.state = state; this.action = action; }
internal bool HasState(TStateId id) { return null != GetState(id); }
public TransitionEvent(TStateId from, TStateId to, TransitionAction action) { this.from = from; this.to = to; this.action = action; }
public RecorderQuery Enter(TStateId stateName) { CheckNext(new StateEvent(stateName, StateAction.ENTER)); return(this); }
public StateSnapshot AggregateDistributedDelta(IEnumerable<IHId> STIDs, TStateId state) { return DoAggregateDistributedDelta(m_spaceTimes.Where(kv => STIDs.Contains(kv.Key)).Select(kv => kv.Value), state); }