コード例 #1
0
        private void ServerDescriptionChanged(object sender, ServerDescriptionChangedEventArgs args)
        {
            var oldClusterDescription = Description;
            ClusterDescription newClusterDescription = oldClusterDescription;

            var newServerDescription = args.NewServerDescription;

            if (newServerDescription.State == ServerState.Disconnected)
            {
                newClusterDescription = Description
                                        .WithServerDescription(newServerDescription);
            }
            else
            {
                var determinedClusterType = DetermineClusterType(newServerDescription);
                if (oldClusterDescription.Type == ClusterType.Unknown)
                {
                    newClusterDescription = newClusterDescription
                                            .WithType(determinedClusterType)
                                            .WithServerDescription(newServerDescription);
                }
                else if (determinedClusterType != oldClusterDescription.Type)
                {
                    newClusterDescription = newClusterDescription
                                            .WithoutServerDescription(newServerDescription.EndPoint);
                }
                else
                {
                    newClusterDescription = newClusterDescription
                                            .WithServerDescription(newServerDescription);
                }
            }

            UpdateClusterDescription(newClusterDescription);
        }
コード例 #2
0
ファイル: MultiServerCluster.cs プロジェクト: LJM74520/nice
        private ClusterDescription RemoveServer(ClusterDescription clusterDescription, EndPoint endPoint, string reason)
        {
            IClusterableServer server;
            var stopwatch = new Stopwatch();

            lock (_serversLock)
            {
                server = _servers.SingleOrDefault(x => EndPointHelper.Equals(x.EndPoint, endPoint));
                if (server == null)
                {
                    return(clusterDescription);
                }

                if (_removingServerEventHandler != null)
                {
                    _removingServerEventHandler(new ClusterRemovingServerEvent(server.ServerId, reason));
                }

                stopwatch.Start();
                _servers.Remove(server);
            }

            server.DescriptionChanged -= ServerDescriptionChangedHandler;
            server.Dispose();
            stopwatch.Stop();

            if (_removedServerEventHandler != null)
            {
                _removedServerEventHandler(new ClusterRemovedServerEvent(server.ServerId, reason, stopwatch.Elapsed));
            }

            return(clusterDescription.WithoutServerDescription(endPoint));
        }
コード例 #3
0
        private ClusterDescription RemoveServer(ClusterDescription clusterDescription, EndPoint endPoint, string reason)
        {
            IClusterableServer server;

            lock (_serversLock)
            {
                server = _servers.SingleOrDefault(x => x.EndPoint.Equals(endPoint));
                if (server == null)
                {
                    return(clusterDescription);
                }

                if (Listener != null)
                {
                    Listener.ClusterBeforeRemovingServer(server.ServerId, reason);
                }

                _servers.Remove(server);
            }

            var stopwatch = new Stopwatch();

            server.DescriptionChanged -= ServerDescriptionChangedHandler;
            server.Dispose();
            stopwatch.Stop();

            if (Listener != null)
            {
                Listener.ClusterAfterRemovingServer(server.ServerId, reason, stopwatch.Elapsed);
            }

            return(clusterDescription.WithoutServerDescription(endPoint));
        }