private MemcachedClientApiConfiguration(
			IEnumerable<IPEndPoint> servers,
			ISocketPoolConfiguration socketPoolConfiguration,
			IMemcachedKeyTransformer keyTransformer, 
			IMemcachedNodeLocator nodeLocator, 
			Func<IMemcachedNodeLocator> nodeLocatorFactory, 
			ITranscoder transcoder, 
			IAuthenticationConfiguration authentication, 
			MemcachedProtocol protocol, 
			IPerformanceMonitor performanceMonitor)
        {
            Condition.Requires(socketPoolConfiguration, "socket pool configuration").IsNotNull();
            Condition.Requires(keyTransformer, "key transformer").IsNotNull();
            Condition.Requires(transcoder, "transcoder").IsNotNull();
            Condition.Requires(authentication, "authentication").IsNotNull();
            Condition.Requires(nodeLocator, "node locator")
                .Evaluate(!(nodeLocator == null && nodeLocatorFactory == null),
                "Both node locator and node locator factory are not set. Requires only one to be set.");
            Condition.Requires(nodeLocator, "node locator")
                .Evaluate(!(nodeLocator == null && nodeLocatorFactory == null),
                "Both node locator and node locator are set. Requires only one to be set.");
            Condition.Requires(servers, "servers").IsNotNull();

            _socketPoolConfiguration = socketPoolConfiguration;
            _keyTransformer = keyTransformer;
            _nodeLocator = nodeLocator;
            _nodeLocatorFactory = nodeLocatorFactory;
            _transcoder = transcoder;
            _authentication = authentication;
            PerformanceMonitor = performanceMonitor;
            Protocol = protocol;
            _servers = servers.ToList();
        }
Exemple #2
0
        void IServerPool.Start()
        {
            _allNodes = _configuration.Servers.
                        Select(ip =>
            {
                var node     = CreateNode(ip);
                node.Failed += NodeFail;

                return(node);
            }).
                        ToArray();

            // initialize the locator
            var locator = _configuration.CreateNodeLocator();

            locator.Initialize(_allNodes);

            NodeLocator = locator;

            var config = (ElastiCacheClusterConfig)_configuration;

            if (config.Setup.ClusterPoller.IntervalDelay < 0)
            {
                config.DiscoveryNode.StartPoller();
            }
            else
            {
                config.DiscoveryNode.StartPoller(config.Setup.ClusterPoller.IntervalDelay);
            }

            LogNodes();
        }
Exemple #3
0
        void IServerPool.Start()
        {
            this.allNodes = this.configuration.Servers.
                            Select(ip =>
            {
                var node     = this.CreateNode(ip, logger);
                node.Failed += this.NodeFail;

                return(node);
            }).
                            ToArray();

            // initialize the locator
            var locator = this.configuration.CreateNodeLocator();

            locator.Initialize(allNodes);

            this.nodeLocator = locator;

            var config = this.configuration as ElastiCacheClusterConfig;

            if (config.setup.ClusterPoller.IntervalDelay < 0)
            {
                config.DiscoveryNode.StartPoller();
            }
            else
            {
                config.DiscoveryNode.StartPoller(config.setup.ClusterPoller.IntervalDelay);
            }
        }
        void IDisposable.Dispose()
        {
            ReaderWriterLock rwl = serverAccessLock;

            if (rwl == null)
            {
                return;
            }

            GC.SuppressFinalize(this);

            serverAccessLock = null;

            try
            {
                rwl.UpgradeToWriterLock(Timeout.Infinite);

                deadServers.ForEach(node => node.Dispose());
                workingServers.ForEach(node => node.Dispose());

                deadServers.Clear();
                workingServers.Clear();
                nodeLocator = null;

                isAliveTimer.Dispose();
                isAliveTimer = null;
            }
            finally
            {
                rwl.ReleaseLock();
            }
        }
Exemple #5
0
        void IDisposable.Dispose()
        {
            ReaderWriterLock rwl = this.serverAccessLock;

            if (rwl == null)
            {
                return;
            }

            GC.SuppressFinalize(this);

            this.serverAccessLock = null;

            try
            {
                rwl.UpgradeToWriterLock(Timeout.Infinite);

                this.deadServers.ForEach(delegate(MemcachedNode node) { node.Dispose(); });
                this.workingServers.ForEach(delegate(MemcachedNode node) { node.Dispose(); });

                this.deadServers.Clear();
                this.workingServers.Clear();
                this.nodeLocator = null;

                this.isAliveTimer.Dispose();
                this.isAliveTimer = null;
            }
            finally
            {
                rwl.ReleaseLock();
            }
        }
        private MemcachedClientApiConfiguration(
            IEnumerable <IPEndPoint> servers,
            ISocketPoolConfiguration socketPoolConfiguration,
            IMemcachedKeyTransformer keyTransformer,
            IMemcachedNodeLocator nodeLocator,
            Func <IMemcachedNodeLocator> nodeLocatorFactory,
            ITranscoder transcoder,
            IAuthenticationConfiguration authentication,
            MemcachedProtocol protocol,
            IPerformanceMonitor performanceMonitor)
        {
            Condition.Requires(socketPoolConfiguration, "socket pool configuration").IsNotNull();
            Condition.Requires(keyTransformer, "key transformer").IsNotNull();
            Condition.Requires(transcoder, "transcoder").IsNotNull();
            Condition.Requires(authentication, "authentication").IsNotNull();
            Condition.Requires(nodeLocator, "node locator")
            .Evaluate(!(nodeLocator == null && nodeLocatorFactory == null),
                      "Both node locator and node locator factory are not set. Requires only one to be set.");
            Condition.Requires(nodeLocator, "node locator")
            .Evaluate(!(nodeLocator == null && nodeLocatorFactory == null),
                      "Both node locator and node locator are set. Requires only one to be set.");
            Condition.Requires(servers, "servers").IsNotNull();

            _socketPoolConfiguration = socketPoolConfiguration;
            _keyTransformer          = keyTransformer;
            _nodeLocator             = nodeLocator;
            _nodeLocatorFactory      = nodeLocatorFactory;
            _transcoder        = transcoder;
            _authentication    = authentication;
            PerformanceMonitor = performanceMonitor;
            Protocol           = protocol;
            _servers           = servers.ToList();
        }
        void IDisposable.Dispose()
        {
            GC.SuppressFinalize(this);

            lock (this.DeadSync)
                if (this.allNodes != null)
                {
                    // dispose the locator first, maybe it wants to access
                    // the nodes one last time
                    var nd = this.nodeLocator as IDisposable;
                    if (nd != null)
                        try { nd.Dispose(); }
                        catch { }

                    this.nodeLocator = null;

                    for (var i = 0; i < this.allNodes.Length; i++)
                        try { this.allNodes[i].Dispose(); }
                        catch { }

                    this.allNodes = null;

                    // stop the timer
                    if (this.resurrectTimer != null)
                        using (this.resurrectTimer)
                            this.resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);

                    this.resurrectTimer = null;
                }
        }
        void IDisposable.Dispose()
        {
            GC.SuppressFinalize(this);

            lock (this.DeadSync)
            {
                if (this.isDisposed) return;

                this.isDisposed = true;

                // dispose the locator first, maybe it wants to access
                // the nodes one last time
                var nd = this.nodeLocator as IDisposable;
                if (nd != null)
                    try { nd.Dispose(); }
                    catch (Exception e) { if (log.IsErrorEnabled) log.Error(e); }

                this.nodeLocator = null;

                for (var i = 0; i < this.allNodes.Length; i++)
                    try { this.allNodes[i].Dispose(); }
                    catch (Exception e) { if (log.IsErrorEnabled) log.Error(e); }

                // stop the timer
                if (this.resurrectTimer != null)
                    using (this.resurrectTimer)
                        this.resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);

                this.allNodes = null;
                this.resurrectTimer = null;
            }
        }
        private bool ExecuteWithRedirect(IMemcachedNode startNode, ISingleItemOperation op)
        {
            if (startNode.Execute(op))
            {
                return(true);
            }

            var iows = op as IOperationWithState;

            // different op factory, we do not know how to retry
            if (iows == null)
            {
                return(false);
            }

#if HAS_FORWARD_MAP
            // node responded with invalid vbucket
            // this should happen only when a node is in a transitioning state
            if (iows.State == OpState.InvalidVBucket)
            {
                // check if we have a forward-locator
                // (whihc supposedly reflects the state of the cluster when all vbuckets have been migrated succesfully)
                IMemcachedNodeLocator fl = this.nsPool.ForwardLocator;
                if (fl != null)
                {
                    var nextNode = fl.Locate(op.Key);
                    if (nextNode != null)
                    {
                        // the node accepted the requesta
                        if (nextNode.Execute(op))
                        {
                            return(true);
                        }
                    }
                }
            }
#endif
            // still invalid vbucket, try all nodes in sequence
            if (iows.State == OperationState.InvalidVBucket)
            {
                var nodes = this.Pool.GetWorkingNodes();

                foreach (var node in nodes)
                {
                    if (node.Execute(op))
                    {
                        return(true);
                    }

                    // the node accepted our request so quit
                    if (iows.State != OperationState.InvalidVBucket)
                    {
                        break;
                    }
                }
            }

            return(false);
        }
Exemple #10
0
 public void Start()
 {
     nodeLocator = configuration.CreateNodeLocator();
     nodes       = new Dictionary <string, IMemcachedNode>();
     nodeLocator.Initialize(new List <IMemcachedNode>());
     Poll(null); // seed it once before returning from Start()
     pollingTimer = new Timer(Poll, null, pollingInterval, pollingInterval);
 }
Exemple #11
0
        void IDisposable.Dispose()
        {
            GC.SuppressFinalize(this);

            lock (this.DeadSync)
            {
                if (this.isDisposed)
                {
                    return;
                }

                this.isDisposed = true;

                // dispose the locator first, maybe it wants to access
                // the nodes one last time
                var nd = this.nodeLocator as IDisposable;
                if (nd != null)
                {
                    try { nd.Dispose(); }
                    catch (Exception e) { if (log.IsErrorEnabled)
                                          {
                                              log.Error(e);
                                          }
                    }
                }

                this.nodeLocator = null;

                for (var i = 0; i < this.allNodes.Length; i++)
                {
                    try { this.allNodes[i].Dispose(); }
                    catch (Exception e) { if (log.IsErrorEnabled)
                                          {
                                              log.Error(e);
                                          }
                    }
                }

                // stop the timer
                if (this.resurrectTimer != null)
                {
                    using (this.resurrectTimer)
                        this.resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                this.allNodes       = null;
                this.resurrectTimer = null;
            }
        }
Exemple #12
0
        // Largely taken from DefaultNodeLocator
        void IDisposable.Dispose()
        {
            GC.SuppressFinalize(this);

            lock (PollSync)
            {
                if (isDisposed)
                {
                    return;
                }

                isDisposed = true;

                var nd = nodeLocator as IDisposable;
                if (nd != null)
                {
                    try { nd.Dispose(); }
                    catch (Exception e) { if (log.IsErrorEnabled)
                                          {
                                              log.Error(e);
                                          }
                    }
                }

                nodeLocator = null;

                foreach (var node in nodes.Values)
                {
                    try { node.Dispose(); }
                    catch (Exception e) { if (log.IsErrorEnabled)
                                          {
                                              log.Error(e);
                                          }
                    }
                }

                // stop the timer
                if (pollingTimer != null)
                {
                    using (pollingTimer)
                        pollingTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                nodes        = null;
                pollingTimer = null;
            }
        }
        void IServerPool.Start()
        {
            this.allNodes = this.configuration.Servers.
                            Select(ip =>
            {
                var node     = this.CreateNode(ip);
                node.Failed += this.NodeFail;

                return(node);
            }).
                            ToArray();

            // initialize the locator
            var locator = this.configuration.CreateNodeLocator();

            locator.Initialize(allNodes);

            this.nodeLocator = locator;
        }
Exemple #14
0
		private void RebuildIndexes()
		{
			this.serverAccessLock.UpgradeToWriterLock(Timeout.Infinite);

			try
			{
				Type ltype = this.configuration.NodeLocator;

				IMemcachedNodeLocator l =  ltype == null ? new DefaultNodeLocator() : (IMemcachedNodeLocator)Enyim.Reflection.FastActivator.CreateInstance(ltype);
				l.Initialize(this.workingServers);

				this.nodeLocator = l;

				this.publicWorkingServers = null;
			}
			finally
			{
				this.serverAccessLock.ReleaseLock();
			}
		}
Exemple #15
0
        private void RebuildIndexes()
        {
            this.serverAccessLock.UpgradeToWriterLock(Timeout.Infinite);

            try
            {
                Type ltype = this.configuration.NodeLocator;

                IMemcachedNodeLocator l = ltype == null ? new DefaultNodeLocator() : (IMemcachedNodeLocator)Enyim.Reflection.FastActivator.CreateInstance(ltype);
                l.Initialize(this.workingServers);

                this.nodeLocator = l;

                this.publicWorkingServers = null;
            }
            finally
            {
                this.serverAccessLock.ReleaseLock();
            }
        }
Exemple #16
0
        void IDisposable.Dispose()
        {
            GC.SuppressFinalize(this);

            lock (_deadSync)
            {
                if (_isDisposed)
                {
                    return;
                }

                _isDisposed = true;

                // dispose the locator first, maybe it wants to access
                // the nodes one last time
                var nd = NodeLocator as IDisposable;
                if (nd != null)
                {
                    try { nd.Dispose(); }
                    catch (Exception e) { _log.LogError(e, "Error on disposing a node locator"); }
                }

                NodeLocator = null;

                for (var i = 0; i < _allNodes.Length; i++)
                {
                    try { _allNodes[i].Dispose(); }
                    catch (Exception e) { _log.LogError(e, "Error on disposing the nodes in pool."); }
                }

                // stop the timer
                if (_resurrectTimer != null)
                {
                    using (_resurrectTimer)
                        _resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                _allNodes       = null;
                _resurrectTimer = null;
            }
        }
        void IDisposable.Dispose()
        {
            GC.SuppressFinalize(this);

            lock (this.DeadSync)
                if (this.allNodes != null)
                {
                    // dispose the locator first, maybe it wants to access
                    // the nodes one last time
                    var nd = this.nodeLocator as IDisposable;
                    if (nd != null)
                    {
                        try { nd.Dispose(); }
                        catch { }
                    }

                    this.nodeLocator = null;

                    for (var i = 0; i < this.allNodes.Length; i++)
                    {
                        try { this.allNodes[i].Dispose(); }
                        catch { }
                    }

                    this.allNodes = null;

                    // stop the timer
                    if (this.resurrectTimer != null)
                    {
                        using (this.resurrectTimer)
                            this.resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    }

                    this.resurrectTimer = null;
                }
        }
		void IServerPool.Start()
		{
			this.allNodes = this.configuration.Servers.
								Select(ip =>
								{
									var node = this.CreateNode(ip);
									node.Failed += this.NodeFail;

									return node;
								}).
								ToArray();

			// initialize the locator
			var locator = this.configuration.CreateNodeLocator();
			locator.Initialize(allNodes);

			this.nodeLocator = locator;
		}
        void IServerPool.Start()
        {
            this.allNodes = this.configuration.ServerNodes.
                                Select(nodeConfig => {
                                    IMemcachedNode node = this.CreateNode(nodeConfig);
                                    node.Failed += this.NodeFail;

                                    return node;
                                }).
                                ToArray();

            // initialize the locator
            var locator = this.configuration.NodeLocator;
            locator.Initialize(allNodes);

            this.nodeLocator = locator;
        }
        void IDisposable.Dispose()
        {
            ReaderWriterLock rwl = this.serverAccessLock;

            if (rwl == null)
                return;

            GC.SuppressFinalize(this);

            this.serverAccessLock = null;

            try
            {
                rwl.UpgradeToWriterLock(Timeout.Infinite);

                //this.deadServers.ForEach(delegate(MemcachedNode node) { node.Dispose(); });
                //this.workingServers.ForEach(delegate(MemcachedNode node) { node.Dispose(); });

                this.deadServers.Clear();
                this.workingServers.Clear();
                this.nodeLocator = null;

                this.isAliveTimer.Dispose();
                this.isAliveTimer = null;
            }
            finally
            {
                rwl.ReleaseLock();
            }
        }
    // Largely taken from DefaultNodeLocator
    void IDisposable.Dispose()
    {
        GC.SuppressFinalize(this);

        lock (PollSync)
        {
            if (isDisposed) return;

            isDisposed = true;

            var nd = nodeLocator as IDisposable;
            if (nd != null)
            {
                try { nd.Dispose(); }
                catch (Exception e) { if (log.IsErrorEnabled) log.Error(e); }
            }

            nodeLocator = null;

            foreach (var node in nodes.Values)
            {
                try { node.Dispose(); }
                catch (Exception e) { if (log.IsErrorEnabled) log.Error(e); }
            }

            // stop the timer
            if (pollingTimer != null)
                using (pollingTimer)
                    pollingTimer.Change(Timeout.Infinite, Timeout.Infinite);

            nodes = null;
            pollingTimer = null;
        }
    }
 public void Start()
 {
     nodeLocator = configuration.CreateNodeLocator();
     nodes = new Dictionary<string, IMemcachedNode>();
     nodeLocator.Initialize(new List<IMemcachedNode>());
     Poll(null); // seed it once before returning from Start()
     pollingTimer = new Timer(Poll, null, pollingInterval, pollingInterval);
 }
        void IDisposable.Dispose()
        {
            ReaderWriterLock rwl = serverAccessLock;

            if (rwl == null)
                return;

            GC.SuppressFinalize(this);

            serverAccessLock = null;

            try
            {
                rwl.UpgradeToWriterLock(Timeout.Infinite);

                deadServers.ForEach(node => node.Dispose());
                workingServers.ForEach(node => node.Dispose());

                deadServers.Clear();
                workingServers.Clear();
                nodeLocator = null;

                isAliveTimer.Dispose();
                isAliveTimer = null;
            }
            finally
            {
                rwl.ReleaseLock();
            }
        }