protected override State AccountFactory(Spacetime st, IHTimestamp stamp, int index) { var firstId = TStateId.DebugCreate(111ul); var secondId = TStateId.DebugCreate(222ul); var ret = new MonitoredAccount(TStateId.DebugCreate(111ul * ((ulong)index + 1)), stamp); if (index == 0) { ret.RegisterInlineTrigger((s) => { StateRef from = new ScopedStateRef(firstId, typeof(MonitoredAccount).Name), to = new ScopedStateRef(secondId, typeof(MonitoredAccount).Name); WithIn.GetWithin().DeferExecute("Transfer", Utils.MakeArgList("fromAcc", from, "toAcc", to), 100.0f); }, (s) => (s as MonitoredAccount).Balance > 100 ); } else { ret.RegisterInlineTrigger((s) => { StateRef from = new ScopedStateRef(secondId, typeof(MonitoredAccount).Name), to = new ScopedStateRef(firstId, typeof(MonitoredAccount).Name); WithIn.GetWithin().DeferExecute("Transfer", Utils.MakeArgList("fromAcc", from, "toAcc", to), 100.0f); }, (s) => (s as MonitoredAccount).Balance > 100 ); } return ret; }
public Spacetime CreateSpacetime(IHEvent event_) { var st = new Spacetime(CreateHid(), event_, HIdFactory); ServiceManager.LocatingService.RegisterSpaceTime(st, event_); ServiceManager.SyncService.PullFromVmSt(st.ID); return st; }
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 Reset() { lock (m_lock) { m_vmST = null; m_vmStateId = new TStateId(); m_spaceTimes.Clear(); } }
public override void Init(AABB worldBox) { m_worldBox = worldBox; if (!m_vmST.VMExist(typeof(IAccounting))) throw new ApplicationException("Accounting functions are not declared in VM yet"); // --- init demo objects --- { var idFactory = ServiceManager.ComputeNode.HIdFactory; var initialST = new Spacetime(idFactory.CreateFromRoot(), ITCEvent.CreateZero(), idFactory); var secondST = new Spacetime(idFactory.CreateFromRoot(), ITCEvent.CreateZero(), idFactory); m_spacetimes.AddRange(new[] { initialST, secondST }); } // fake the globally existing SyncManager foreach (var ST in m_spacetimes) ServiceManager.LocatingService.RegisterSpaceTime(ST, null); // must pull new VM to use IAccounting foreach (var ST in m_spacetimes) ServiceManager.SyncService.PullFromVmSt(ST.ID); // create 2 accounts for (int ii = 0; ii < 2; ++ii) { // firstly create into same ST then we migrate one to another ST var newAccount = m_spacetimes[0].CreateState((st, stamp) => AccountFactory(st, stamp, ii)); //m_namingSvc.RegisterObject(newAccount.StateId.ToString(), newAccount.GetType().ToString(), newAccount); m_accountStates.Add(newAccount); m_accounts.Add(new ScopedStateRef(newAccount.StateId, newAccount.GetType().ToString())); } m_spacetimes[1].Immigrate(m_accounts[1].StateId, m_spacetimes[0].ID); // deposit some initial money using (new WithIn(m_spacetimes[0])) { foreach (var acc in m_accounts) m_accountingInvoker.Deposit(acc, 900.0f); } // initial chronon SyncSpacetimes(); }
protected override State AccountFactory(Spacetime st, IHTimestamp stamp, int index) { return new Account(TStateId.DebugCreate(111ul * ((ulong)index + 1)), stamp); }
protected abstract State AccountFactory(Spacetime st, IHTimestamp stamp, int index);
public WithIn(Spacetime st) { m_localStack = ms_tls.Value; m_localStack.Add(st); }
public void Initialize(VMSpacetime vmST) { m_vmST = vmST; m_vmStateId = vmST.VMStateId; }