Ejemplo n.º 1
0
        public MemcachedClient CreateNewMemcachedClient(Action<string, MemcachedCommand> onRecoverableError, Action<string, IEnumerable<MemcachedCommand>, IEnumerable<MemcachedCommand>> onDisconnected)
        {
            MemcachedClient client = new MemcachedClient(this.Id, this.HostName, this.MemcachedPort);
            client.OnRecoverableError += onRecoverableError;
            client.OnDisconnected += onDisconnected;
            client.Connect();

            return client;
        }
Ejemplo n.º 2
0
        private AsyncPatternResult<TcpClient, ReconnectAttempt> OnMemcacachedReconnectionCompleted(IAsyncResult result, ReconnectAttempt reconnectAttempt)
        {
            TcpClient tcpClient = reconnectAttempt.TcpClient;
            tcpClient.EndConnect(result);

            lock (_gate)
            {
                var cluster = _cluster;

                //Update the cluster after we have successfully reconnected.
                var newCluster = cluster.Clone();

                var serverInLatestCluster = newCluster.GetServerById(reconnectAttempt.Server.Id);

                if (_hasQuit ||
                    serverInLatestCluster == null ||
                    reconnectAttempt.HasBeenCanceled)
                {
                    _currentlyUnderwayMemcachedReconnectAttempts.Remove(reconnectAttempt);
                    reconnectAttempt.Cancel();
                }
                else
                {
                    MemcachedClient newMemcachedClient = new MemcachedClient(serverInLatestCluster.Id, serverInLatestCluster.HostName, serverInLatestCluster.MemcachedPort);

                    newMemcachedClient.OnDisconnected += OnMemcachedDisconnection;
                    newMemcachedClient.OnRecoverableError += OnPossiblyRecoverableMemcachedError;
                    newMemcachedClient.Connect(tcpClient);

                    serverInLatestCluster.MemcachedClient = newMemcachedClient;

                    _currentlyUnderwayMemcachedReconnectAttempts.Remove(reconnectAttempt);
                    _cluster = newCluster;
                }

                return _reconnectMemcachedAsync.Stop();
            }
        }