Пример #1
0
		public Spacetime CreateSpacetime(IHEvent event_)
		{
			var st = new Spacetime(CreateHid(), event_, HIdFactory);
			ServiceManager.LocatingService.RegisterSpaceTime(st, event_);
			ServiceManager.SyncService.PullFromVmSt(st.ID);
			return st;
		}
Пример #2
0
		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;
		}
Пример #3
0
		public State(TStateId stateId, IHId spacetimeId, IHEvent expectingEvent, StatePatchMethod patchMethod)
		{
			StateId = stateId;
			SpacetimeID = spacetimeId;
			LatestUpdate = expectingEvent;
			m_patchMethod = patchMethod;
			Rev = 0;
		}
Пример #4
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 });
			}
		}
Пример #5
0
		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;
			}
		}
Пример #6
0
		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;
			}
		}
Пример #7
0
		internal void OnCommitting(IHEvent evtFinal)
		{
			LatestUpdate = evtFinal;
			Rev += 1;
		}
Пример #8
0
		public StateSnapshot Snapshot( IHEvent overridingEvent)
		{
			return Snapshot(HTSFactory.Make(SpacetimeID, overridingEvent));
		}
Пример #9
0
		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;
		}
Пример #10
0
		public bool PullRequest(IHId idPuller, IHId idRequester, IHEvent foreignExpectedEvent, ILookup<TStateId, StatePatch> affectedStates)
		{
			return m_spaceTimes[idPuller].PullRequest(idRequester, foreignExpectedEvent, affectedStates);
		}
Пример #11
0
		public PrePullRequestResult PrePullRequest(IHId idPuller, IHId idRequester, IHEvent evtOriginal, IEnumerable<TStateId> affectedStates)
		{
			return m_spaceTimes[idPuller].PrePullRequest(idRequester, evtOriginal, affectedStates);
		}
Пример #12
0
		public static IHTimestamp Make(IHId id, IHEvent event_)
		{
			return new ITCTimestamp(id as ITCIdentity, event_ as ITCEvent);
		}