Esempio n. 1
0
        /// <summary>
        ///     Creates a new server manager.
        /// </summary>
        /// <param name="serverSettings">The server's main configuration.</param>
        /// <param name="serverRegistrySettings">The server's registry configuration.</param>
        /// <param name="clusterSpawnData">The cluster configuration</param>
        /// <param name="networkListenerManager">The server's network listener manager.</param>
        /// <param name="threadHelper">The server's thread helper.</param>
        /// <param name="serverRegistryConnectorManager">The server's registry connector manager.</param>
        /// <param name="logManager">The server's log manager.</param>
        /// <param name="logger">The logger to use.</param>
        /// <param name="metricsManager">The server's metrics manager.</param>
        internal RemoteServerManager(ServerSpawnData.ServerSettings serverSettings, ServerSpawnData.ServerRegistrySettings serverRegistrySettings, ClusterSpawnData clusterSpawnData, NetworkListenerManager networkListenerManager, DarkRiftThreadHelper threadHelper, ServerRegistryConnectorManager serverRegistryConnectorManager, LogManager logManager, Logger logger, MetricsManager metricsManager)
        {
            this.AdvertisedHost = serverRegistrySettings.AdvertisedHost;
            this.AdvertisedPort = serverRegistrySettings.AdvertisedPort;


            this.networkListenerManager         = networkListenerManager;
            this.serverRegistryConnectorManager = serverRegistryConnectorManager;
            this.logger = logger;
            this.Group  = serverSettings.ServerGroup;

            if (!string.IsNullOrEmpty(serverSettings.ServerGroup))
            {
                if (serverRegistrySettings.AdvertisedHost == null || serverRegistrySettings.AdvertisedPort == 0)
                {
                    throw new ArgumentException("Cannot start server clustering without an advertised host and port. Consider setting the 'advertisedHost' and 'advertisedPort' properties in configuration.");
                }

                // Find our group
                ClusterSpawnData.GroupsSettings.GroupSettings ourGroup = null;
                foreach (ClusterSpawnData.GroupsSettings.GroupSettings groupSettings in clusterSpawnData.Groups.Groups)
                {
                    if (groupSettings.Name == serverSettings.ServerGroup)
                    {
                        ourGroup = groupSettings;
                        break;
                    }
                }

                if (ourGroup == null)
                {
                    throw new ArgumentException($"The group specified to own this server '{serverSettings.ServerGroup}' is not present in the cluster configuration. Consider adding this group to the cluster configuration or moving the server to an existing group.");
                }

                this.Visibility = ourGroup.Visibility;

                // Build relationships to other groups
                foreach (ClusterSpawnData.GroupsSettings.GroupSettings groupSettings in clusterSpawnData.Groups.Groups)
                {
                    ClusterSpawnData.GroupsSettings.GroupSettings.ConnectsToSettings ourGroupConnectsTo = ourGroup.ConnectsTo.FirstOrDefault(c => c.Name == groupSettings.Name);
                    ClusterSpawnData.GroupsSettings.GroupSettings.ConnectsToSettings connectsToOurGroup = groupSettings.ConnectsTo.FirstOrDefault(c => c.Name == ourGroup.Name);

                    IModifiableServerGroup serverGroup;
                    if (ourGroupConnectsTo != null)
                    {
                        serverGroup = new UpstreamServerGroup(groupSettings.Name, groupSettings.Visibility, threadHelper, serverRegistryConnectorManager, this, serverSettings.ReconnectAttempts, logManager.GetLoggerFor(nameof(UpstreamServerGroup)), logManager.GetLoggerFor(nameof(UpstreamRemoteServer)), metricsManager.GetMetricsCollectorFor(nameof(UpstreamServerGroup)), metricsManager.GetMetricsCollectorFor(nameof(UpstreamRemoteServer)));
                    }
                    else if (connectsToOurGroup != null)
                    {
                        serverGroup = new DownstreamServerGroup(groupSettings.Name, groupSettings.Visibility, threadHelper, logManager.GetLoggerFor(nameof(DownstreamServerGroup)), logManager.GetLoggerFor(nameof(DownstreamRemoteServer)), metricsManager.GetMetricsCollectorFor(nameof(DownstreamServerGroup)), metricsManager.GetMetricsCollectorFor(nameof(DownstreamRemoteServer)));
                    }
                    else
                    {
                        continue;
                    }

                    groups.Add(groupSettings.Name, serverGroup);
                }
            }
        }
 /// <summary>
 ///     Creates a new upstream connected server group
 /// </summary>
 /// <param name="name">The name of the group.</param>
 /// <param name="visibility">The groups visibility.</param>
 /// <param name="threadHelper">The server's thread helper.</param>
 /// <param name="serverRegistryConnectorManager">The server's registry connector manager</param>
 /// <param name="remoteServerManager">The remote server manager for the server.</param>
 /// <param name="reconnectAttempts">The number of times to attempt to reconnect to a server before considering it unconnectable.</param>
 /// <param name="logger">The logger to use.</param>
 /// <param name="remoteServerLogger">The logger to pass to created remote servers.</param>
 /// <param name="metricsCollector">The metrics collector to use.</param>
 /// <param name="remoteServerMetricsCollector">The metrics collector to pass to created remote servers.</param>
 internal UpstreamServerGroup(string name, ServerVisibility visibility, DarkRiftThreadHelper threadHelper, ServerRegistryConnectorManager serverRegistryConnectorManager, RemoteServerManager remoteServerManager, int reconnectAttempts, Logger logger, Logger remoteServerLogger, MetricsCollector metricsCollector, MetricsCollector remoteServerMetricsCollector)
     : base(name, visibility, threadHelper, logger, metricsCollector)
 {
     this.threadHelper = threadHelper;
     this.serverRegistryConnectorManager = serverRegistryConnectorManager;
     this.remoteServerManager            = remoteServerManager;
     this.reconnectAttempts            = reconnectAttempts;
     this.logger                       = logger;
     this.remoteServerLogger           = remoteServerLogger;
     this.remoteServerMetricsCollector = remoteServerMetricsCollector;
 }