internal LockSession(ILockManagerImplementation manager, string path, object shardingID, string description = null, int?maxAgeSec = null) { if (path.IsNullOrWhiteSpace()) { throw new LockingException(StringConsts.ARGUMENT_ERROR + "LockSession.ctor(path==null|empty)"); } if (shardingID == null) { throw new LockingException(StringConsts.ARGUMENT_ERROR + "LockSession.ctor(shardingID==null)"); } Data = new Server.LockSessionData(new LockSessionID(null), description, maxAgeSec); Manager = manager; Path = path; ShardingID = shardingID; try { var shardingHash = shardingID.GetHashCode(); var zone = manager.App.GetMetabase().CatalogReg.NavigateZone(Path); var primaryZgovs = zone .FindNearestParentZoneGovernors(iAmZoneGovernor: false, filter: (host) => !host.IsZGovLockFailover, transcendNOC: true) .OrderBy(host => host.Name) .ToArray(); if (primaryZgovs.Length < 1) { throw new LockingException(StringConsts.LOCK_SESSION_PATH_LEVEL_NO_ZGOVS_ERROR.Args(Path)); } var failoverZgovs = zone .FindNearestParentZoneGovernors(iAmZoneGovernor: false, filter: (host) => host.IsZGovLockFailover, transcendNOC: true) .OrderBy(host => host.Name) .ToArray(); if (failoverZgovs.Length > 0 && (primaryZgovs.Length != failoverZgovs.Length || !primaryZgovs[0].ParentZone.IsLogicallyTheSame(failoverZgovs[0].ParentZone)) ) { throw new LockingException(StringConsts.LOCK_SESSION_ZGOV_SETUP_ERROR.Args(primaryZgovs[0].ParentZone.RegionPath)); } var idx = (shardingHash & CoreConsts.ABS_HASH_MASK) % primaryZgovs.Length; ServerHostPrimary = primaryZgovs[idx].RegionPath; if (failoverZgovs.Length > 0) { ServerHostSecondary = failoverZgovs[idx].RegionPath; } } catch (Exception error) { throw new LockingException(StringConsts.LOCK_SESSION_PATH_ERROR.Args(Path, error.ToMessageWithType()), error); } }
protected override void DoInitApplication() { base.DoInitApplication(); var FROM = GetType().FullName + ".DoInitApplication()"; var metabase = m_BootLoader.Metabase; try { m_GDIDProvider = new GdidGenerator(this, "Sky"); foreach (var ah in metabase.GDIDAuthorities) { m_GDIDProvider.AuthorityHosts.Register(ah); WriteLog(MessageType.Info, FROM + "{GDIDProvider init}", "Registered GDID authority host: " + ah.ToString()); } WriteLog(MessageType.Info, FROM, "GDIProvider made"); } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{GDIDProvider init}", error.ToMessageWithType()); try { m_GDIDProvider.Dispose(); } catch { } m_GDIDProvider = null; } var wmSection = ConfigRoot[CONFIG_WEB_MANAGER_SECTION]; if (wmSection.Exists && wmSection.AttrByName(CONFIG_ENABLED_ATTR).ValueAsBool(false)) { try { m_WebManagerServer = new WaveServer(this); m_WebManagerServer.Configure(wmSection); m_WebManagerServer.Start(); } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{WebManagerServer start}", error.ToMessageWithType()); try { m_WebManagerServer.Dispose(); } catch {} m_WebManagerServer = null; } } var lockSection = ConfigRoot[CONFIG_LOCK_MANAGER_SECTION]; try { m_LockManager = FactoryUtils.MakeAndConfigure <ILockManagerImplementation>(lockSection, typeof(LockManager)); WriteLog(MessageType.Info, FROM, "Lock Manager made"); if (m_LockManager is Daemon) { ((Daemon)m_LockManager).Start(); WriteLog(MessageType.Info, FROM, "Lock Manager STARTED"); } } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{LockManager start}", error.ToMessageWithType()); try { m_LockManager.Dispose(); } catch {} m_LockManager = null; } var procSection = ConfigRoot[CONFIG_PROCESS_MANAGER_SECTION]; try { m_ProcessManager = FactoryUtils.MakeAndConfigure <IProcessManagerImplementation>(procSection, typeof(ProcessManager), new object[] { this }); WriteLog(MessageType.Info, FROM, "Process Manager made"); if (m_ProcessManager is Daemon) { ((Daemon)m_ProcessManager).Start(); WriteLog(MessageType.Info, FROM, "Process Manager STARTED"); } } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{ProcessManager start}", error.ToMessageWithType()); try { m_ProcessManager.Dispose(); } catch {} m_ProcessManager = null; } var hostSection = ConfigRoot[CONFIG_HOST_MANAGER_SECTION]; try { m_DynamicHostManager = FactoryUtils.MakeAndConfigure <IHostManagerImplementation>(procSection, typeof(HostManager), new object[] { this }); WriteLog(MessageType.Info, FROM, "Dynamic Host Manager made"); if (m_DynamicHostManager is Daemon) { ((Daemon)m_DynamicHostManager).Start(); WriteLog(MessageType.Info, FROM, "Dynamic Host Manager STARTED"); } } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{HostManager start}", error.ToMessageWithType()); try { m_DynamicHostManager.Dispose(); } catch {} m_DynamicHostManager = null; } }