public static ICluster GetCluster(ClusterConfig clusterConfig) { clusterConfig.CheckArgumentNotNull("clusterConfig"); clusterConfig.Endpoints.CheckArgumentNotNull("clusterConfig.Endpoints"); TransportConfig transportConfig = clusterConfig.Transport ?? new TransportConfig(); IRecoveryService recoveryService = FindRecoveryService(transportConfig.Recoverable); // create endpoints IEndpointSnitch snitch = Factory.Create(clusterConfig.Endpoints.Snitch, _logger); IEnumerable<IPAddress> endpoints = clusterConfig.Endpoints.Servers.Select(NetworkFinder.Find); // create required services IEndpointStrategy endpointsManager = EndpointStrategy.Factory.Create(clusterConfig.Endpoints.Strategy, endpoints, snitch, _logger); IConnectionFactory connectionFactory = Transport.Factory.Create(transportConfig.Type, transportConfig, _logger); // create the cluster now ICluster cluster = Cluster.Factory.Create("Default", endpointsManager, _logger, connectionFactory, recoveryService); IDiscoveryService discoveryService = Discovery.Factory.Create(clusterConfig.Endpoints.Discovery, _logger); var newPeers = discoveryService.DiscoverPeers(cluster); endpointsManager.Update(newPeers); return cluster; }
public ICluster GetCluster(ClusterConfig clusterConfig) { clusterConfig.CheckArgumentNotNull("clusterConfig"); clusterConfig.Endpoints.CheckArgumentNotNull("clusterConfig.Endpoints"); TransportConfig transportConfig = clusterConfig.Transport ?? new TransportConfig(); IRecoveryService recoveryService = GetRecoveryService(transportConfig.Recoverable); KeyspaceConfig keyspaceConfig = clusterConfig.DefaultKeyspace ?? new KeyspaceConfig(); // create endpoints IEndpointSnitch snitch = ServiceActivator<Factory>.Create<IEndpointSnitch>(clusterConfig.Endpoints.Snitch, _logger); IEnumerable<IPAddress> endpoints = clusterConfig.Endpoints.Servers.Select(Network.Find).Where(x => null != x).ToArray(); if (!endpoints.Any()) { throw new ArgumentException("Expecting at least one valid endpoint"); } // create required services IEndpointStrategy endpointsManager = ServiceActivator<EndpointStrategy.Factory>.Create<IEndpointStrategy>(clusterConfig.Endpoints.Strategy, endpoints, snitch, _logger, clusterConfig.Endpoints); IConnectionFactory connectionFactory = ServiceActivator<Transport.Factory>.Create<IConnectionFactory>(transportConfig.Type, transportConfig, keyspaceConfig, _logger, _instrumentation); IPartitioner partitioner = ServiceActivator<Partitioner.Factory>.Create<IPartitioner>(clusterConfig.Partitioner); // create the cluster now ICluster cluster = ServiceActivator<Cluster.Factory>.Create<ICluster>(clusterConfig.Type, endpointsManager, _logger, connectionFactory, recoveryService, partitioner, clusterConfig); IDiscoveryService discoveryService = ServiceActivator<Discovery.Factory>.Create<IDiscoveryService>(clusterConfig.Endpoints.Discovery.Type, clusterConfig.Endpoints.Discovery, _logger, cluster); discoveryService.OnTopologyUpdate += endpointsManager.Update; cluster.OnClosed += discoveryService.SafeDispose; return cluster; }