コード例 #1
0
        public Contracts.DynamicHostID Spawn(string hostPath, string id)
        {
            var zone = App.GetThisHostMetabaseSection().ParentZone;

            if (!Running || m_DynamicHostSlots == null)
            {
                return(new Contracts.DynamicHostID(null, zone.RegionPath));
            }

            // TODO: Check zone
            var host = App.Metabase.CatalogReg.NavigateHost(hostPath) as Metabank.SectionHost;

            if (!host.Dynamic)
            {
                throw new AZGOVException("TODO: Host '0' is not dynamic".Args(hostPath));
            }

            if (id == null)
            {
                id = App.GdidProvider.GenerateOneGdid(SysConsts.GDID_NS_DYNAMIC_HOST, SysConsts.GDID_NAME_DYNAMIC_HOST).ToString();
            }

            var hid = new Contracts.DynamicHostID(id, zone.RegionPath);

            var dhi = m_DynamicHostSlots[id];

            if (dhi == null)
            {
                var stamp = App.TimeSource.UTCNow;

                dhi       = new Contracts.DynamicHostInfo(id);
                dhi.Stamp = stamp;
                dhi.Owner = App.HostName;
                dhi.Votes = 1;
                m_DynamicHostSlots.Register(dhi);

                var hosts = zone.ZoneGovernorHosts.Where(hh => !App.HostName.IsSameRegionPath(hh.RegionPath));
                foreach (var h in hosts)
                {
                    using (var cl = App.GetServiceClientHub().MakeNew <Contracts.IZoneHostReplicatorClient>(h))
                        cl.Async_PostDynamicHostInfo(hid, dhi.Stamp, dhi.Owner, dhi.Votes);
                }
            }
            return(hid);
        }
コード例 #2
0
        public void PostDynamicHostInfo(Contracts.DynamicHostID hid, DateTime stamp, string owner, int votes)
        {
            if (!Running || m_DynamicHostSlots == null)
            {
                return;
            }
            var zone = App.GetThisHostMetabaseSection().ParentZone;

            // TODO: Check zone
            var dhi  = m_DynamicHostSlots[hid.ID];
            var post = false;

            if (dhi == null)
            {
                dhi  = new Contracts.DynamicHostInfo(hid.ID);
                post = true;
                m_DynamicHostSlots.Register(dhi);
            }

            if (dhi.Stamp > stamp || post)
            {
                dhi.Stamp = stamp;
                dhi.Owner = owner;
                dhi.Votes = votes;
                post      = true;
            }

            if (dhi.Stamp == stamp)
            {
                dhi.Votes += 1;
            }

            if (post)
            {
                var hosts = zone.ZoneGovernorHosts.Where(hh => !App.HostName.IsSameRegionPath(hh.RegionPath));
                foreach (var h in hosts)
                {
                    using (var cl = App.GetServiceClientHub().MakeNew <Contracts.IZoneHostReplicatorClient>(h))
                        cl.Async_PostDynamicHostInfo(hid, dhi.Stamp, dhi.Owner, dhi.Votes);
                }
            }
        }