コード例 #1
0
		public MemcachedCluster(IEnumerable<IPEndPoint> endpoints, IBufferAllocator allocator,
			INodeLocator locator, IReconnectPolicy reconnectPolicy, IFailurePolicy failurePolicy,
			Func<ISocket> socketFactory)
			: base(endpoints, locator, reconnectPolicy)
		{
			this.allocator = allocator;
			this.failurePolicy = failurePolicy;
			this.socketFactory = socketFactory;
		}
コード例 #2
0
		private NodeQueue ioQueue; // the nodes that has IO pending

		protected ClusterBase(IEnumerable<IPEndPoint> endpoints, INodeLocator locator, IReconnectPolicy reconnectPolicy)
		{
			this.endpoints = endpoints.ToArray();
			this.locator = locator;
			this.reconnectPolicy = reconnectPolicy;
			this.ReconnectLock = new Object();

			this.worker = new Thread(Worker) { Name = "IO Thread {" + String.Join(", ", endpoints.Select(ep => ep.ToString())) + "}" };

			this.shutdownToken = new CancellationTokenSource();
			this.workerIsDone = new ManualResetEventSlim(false);
		}
コード例 #3
0
 public NodeInstanceContainer BuildContainer(NodeUri nodeUri, INodeLocator nodeLocator)
 {
   return new NodeInstanceContainer(nodeUri, _nodeFactory(nodeUri, nodeLocator));
 }
コード例 #4
0
        public CouchbaseCluster(MemcacheClientConfiguration configuration, string bucket, IPEndPoint[] configurationHosts)
        {
            if (configurationHosts.Length == 0)
                throw new ArgumentException("There should be at least one value in the list", "configurationHosts");

            _isInitialized = false;

            _linesStreamReader = null;
            _webResponse = null;

            _configuration = configuration;
            if (_configuration.Authenticator == null)
                _configuration.Authenticator = MemcacheClientConfiguration.SaslPlainAuthenticatorFactory(string.Empty, bucket, string.Empty);

            _bucket = bucket;

            _currentConfigurationHost = 0;
            _configurationHosts = configurationHosts;

            _memcacheNodes = new Dictionary<string, IMemcacheNode>();

            _locator = null;

            _connectionTimer = new Timer(_ => ConnectToConfigurationStream(), null, Timeout.Infinite, Timeout.Infinite);
            _receivedInitialConfigurationBarrier = new ManualResetEventSlim();
        }
コード例 #5
0
        /// <summary>
        /// Handles chunks of data, by parsing them as JSON and updating the current cluster state.
        /// </summary>
        /// <param name="chunk">Chunk of data</param>
        internal void HandleConfigurationUpdate(string chunk)
        {
            try
            {
                var bucket = JsonSerializer.DeserializeFromString<JsonBucket>(chunk);
                if (bucket == null)
                    throw new ConfigurationException("Received an empty bucket configuration from Couchbase for bucket " + _bucket);

                // Serialize configuration updates to avoid trouble
                lock (this)
                {
                    IList<string> nodesEndPoint;

                    switch (bucket.NodeLocator)
                    {
                        case "vbucket":
                            {
                                if (bucket.VBucketServerMap == null || bucket.VBucketServerMap.VBucketMap == null || bucket.VBucketServerMap.ServerList == null)
                                    throw new ConfigurationException("Received an empty vbucket map from Couchbase for bucket " + _bucket);

                                nodesEndPoint = bucket.VBucketServerMap.ServerList;
                                var updatedNodes = GenerateUpdatedNodeList(nodesEndPoint);
                                // Atomic update to the latest cluster state
                                _locator = new VBucketServerMapLocator(updatedNodes, bucket.VBucketServerMap.VBucketMap);
                                break;
                            }
                        case "ketama":
                            {
                                if (_locator == null)
                                    _locator = new KetamaLocator();

                                // create new nodes
                                nodesEndPoint = GetNodesFromConfiguration(bucket);
                                var updatedNodes = GenerateUpdatedNodeList(nodesEndPoint);
                                _locator.Initialize(updatedNodes);
                                break;
                            }
                        default:
                            throw new ConfigurationException("Unhandled locator type: " + bucket.NodeLocator);
                    }

                    // Dispose of the unused nodes after updating the current state
                    CleanupDeletedNodes(nodesEndPoint);
                }
            }
            catch (Exception e)
            {
                if (OnError != null)
                    OnError(e);
            }
            finally
            {
                _receivedInitialConfigurationBarrier.Set();

                if (OnConfig != null)
                    OnConfig();
            }
        }
コード例 #6
0
ファイル: ClientTests.cs プロジェクト: mindis/memcache-driver
        public void Setup()
        {
            var nodeMock = new Mock<IMemcacheNode>();
            nodeMock.Setup(n => n.EndPoint).Returns(new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 11211));
            nodeMock.Setup(n => n.IsDead).Returns(false);
            nodeMock.Setup(n => n.TrySend(It.IsAny<IMemcacheRequest>(), It.IsAny<int>()))
                .Callback((IMemcacheRequest req, int timeout) => req.HandleResponse(_responseHeader, _key, _extra, _message))
                .Returns(true);
            _nodeMock = nodeMock.Object;

            var locatorMoq = new Mock<INodeLocator>();
            locatorMoq.Setup(l => l.Locate(It.IsAny<IMemcacheRequest>())).Returns(Enumerable.Repeat(_nodeMock, 1));
            _locatorMock = locatorMoq.Object;

            var clusterMoq = new Mock<IMemcacheCluster>();
            clusterMoq.Setup(c => c.Locator).Returns(_locatorMock);
            clusterMoq.Setup(c => c.Nodes).Returns(Enumerable.Repeat(_nodeMock, 1));
            _clusterMock = clusterMoq.Object;

            _key = null;
            _extra = null;
            _message = null;
            _responseHeader = default(MemcacheResponseHeader);
        }
コード例 #7
0
 public LinkedAsyncNodeLocator(INodeLocator nodeLocator, Task<INodeLocator> linkedNodeLocatorTask)
 {
   _nodeLocator = nodeLocator;
   _linkedNodeLocatorTask = linkedNodeLocatorTask;
 }
コード例 #8
0
        private EslintBridgeProcess CreateTestSubject(string startupScriptPath = null, INodeLocator nodeLocator = null, IFileSystem fileSystem = null, ILogger logger = null)
        {
            startupScriptPath ??= "somefile.txt";
            nodeLocator ??= SetupNodeLocator("some path").Object;
            fileSystem ??= SetupStartupScriptFile(startupScriptPath, true).Object;
            logger ??= Mock.Of <ILogger>();

            return(new EslintBridgeProcess(startupScriptPath, nodeLocator, fileSystem, logger));
        }
コード例 #9
0
ファイル: GameManager.cs プロジェクト: MaxtorCoder/Impostor
 public GameManager(ILogger <GameManager> logger, IOptions <ServerConfig> config, INodeLocator nodeLocator, IServiceProvider serviceProvider, IEventManager eventManager, IGameCodeFactory gameCodeFactory)
 {
     _logger          = logger;
     _nodeLocator     = nodeLocator;
     _serviceProvider = serviceProvider;
     _eventManager    = eventManager;
     _gameCodeFactory = gameCodeFactory;
     _publicIp        = new IPEndPoint(IPAddress.Parse(config.Value.ResolvePublicIp()), config.Value.PublicPort);
     _games           = new ConcurrentDictionary <int, Game>();
 }
コード例 #10
0
 public ClientManagerRedirector(ILogger <ClientManagerRedirector> logger, INodeProvider nodeProvider, INodeLocator nodeLocator)
 {
     _logger       = logger;
     _nodeProvider = nodeProvider;
     _nodeLocator  = nodeLocator;
     _clients      = new HashSet <ClientRedirector>();
 }
コード例 #11
0
 public static async ValueTask <bool> ExistsAsync(this INodeLocator nodeLocator, string gameCode)
 {
     return(await nodeLocator.FindAsync(gameCode) != null);
 }