public void Start() { lock (StateLock) { if (IsStarted) { throw new InvalidOperationException("Cluster is already started"); } if (IsDisposed) { throw new ObjectDisposedException("Cluster is already disposed"); } OnStarting(); allNodes = endpoints.Select(CreateNode).ToArray(); ioQueue = new NodeQueue(allNodes); workingNodes = allNodes.ToArray(); allNodes.IntoDictionary(reconnectPolicies, n => n, reconnectPolicyFactory.Create); locator.Initialize(allNodes); worker.Start(); OnStarted(); } }
public virtual void Start() { allNodes = endpoints.Select(CreateNode).ToArray(); ioQueue = new NodeQueue(allNodes); workingNodes = allNodes.ToArray(); locator.Initialize(allNodes); worker.Start(); }
public virtual void Start() { lock (StateLock) { if (isDisposed) { throw new ObjectDisposedException("Cluster is already disposed"); } if (allNodes != null) { throw new InvalidOperationException("Cluster is already initialized"); } allNodes = endpoints.Select(CreateNode).ToArray(); ioQueue = new NodeQueue(allNodes); workingNodes = allNodes.ToArray(); locator.Initialize(allNodes); worker.Start(); } }
/// <summary> /// The constructor, see @MemcacheClientConfiguration for details /// </summary> /// <param name="configuration"></param> public MemcacheClient(MemcacheClientConfiguration configuration) { if (configuration == null) { throw new ArgumentException("Client config should not be null"); } OngoingDispose = false; _configuration = configuration; _locator = configuration.NodeLocator ?? MemcacheClientConfiguration.DefaultLocatorFactory(); _nodes = new List <IMemcacheNode>(configuration.NodesEndPoints.Count); foreach (var nodeEndPoint in configuration.NodesEndPoints) { var node = (configuration.NodeFactory ?? MemcacheClientConfiguration.DefaultNodeFactory)(nodeEndPoint, configuration, this); _nodes.Add(node); RegisterEvents(node); } _locator.Initialize(_nodes); }
/// <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(); } } }
/// <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; var nodeStatus = GetNodesFromConfiguration(bucket); List <IMemcacheNode> toBeDeleted; switch (bucket.NodeLocator) { case JsonBucket.TYPE_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); } // The endpoints in VBucketServerMap are in the right order nodesEndPoint = bucket.VBucketServerMap.ServerList; var updatedNodes = GenerateUpdatedNodeList(nodesEndPoint, nodeStatus, out toBeDeleted); // Atomic update to the latest cluster state _locator = new VBucketServerMapLocator(updatedNodes, bucket.VBucketServerMap.VBucketMap); break; } case JsonBucket.TYPE_KETAMA: { if (_locator == null) { _locator = new KetamaLocator(); } // create new nodes nodesEndPoint = nodeStatus.Keys.ToList(); var updatedNodes = GenerateUpdatedNodeList(nodesEndPoint, nodeStatus, out toBeDeleted); _locator.Initialize(updatedNodes); break; } default: throw new ConfigurationException("Unhandled locator type: " + bucket.NodeLocator); } // Dispose of the unused nodes after updating the current state CleanupNodes(toBeDeleted); } } catch (Exception e) { if (OnError != null) { OnError(e); } } finally { if (OnConfig != null) { OnConfig(); } } }