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; }
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); }
public NodeInstanceContainer BuildContainer(NodeUri nodeUri, INodeLocator nodeLocator) { return new NodeInstanceContainer(nodeUri, _nodeFactory(nodeUri, nodeLocator)); }
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(); }
/// <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(); } }
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); }
public LinkedAsyncNodeLocator(INodeLocator nodeLocator, Task<INodeLocator> linkedNodeLocatorTask) { _nodeLocator = nodeLocator; _linkedNodeLocatorTask = linkedNodeLocatorTask; }
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)); }
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>(); }
public ClientManagerRedirector(ILogger <ClientManagerRedirector> logger, INodeProvider nodeProvider, INodeLocator nodeLocator) { _logger = logger; _nodeProvider = nodeProvider; _nodeLocator = nodeLocator; _clients = new HashSet <ClientRedirector>(); }
public static async ValueTask <bool> ExistsAsync(this INodeLocator nodeLocator, string gameCode) { return(await nodeLocator.FindAsync(gameCode) != null); }