Beispiel #1
0
        /// <summary>
        /// Add a cluster to the current cluster connections.
        /// </summary>
        public static MetaCluster AddCluster(ArrayRig <IPEndPoint> entryPoints, string username = null, string password = null)
        {
            var cluster = new MetaCluster(entryPoints, username, password);

            // if the default cluster has not been set assign the new cluster
            if (_defaultCluster == null)
            {
                DefaultCluster = cluster;
            }

            Clusters.Add(cluster);

            return(cluster);
        }
Beispiel #2
0
        /// <summary>
        /// Add a cluster to the current cluster connections.
        /// </summary>
        public static MetaCluster AddCluster(Cassandra.Cluster cluster)
        {
            var metaCluster = new MetaCluster(cluster);

            // if the default cluster has not been set assign the new cluster
            if (_defaultCluster == null)
            {
                DefaultCluster = metaCluster;
            }

            Clusters.Add(metaCluster);

            return(metaCluster);
        }
Beispiel #3
0
 /// <summary>
 /// Remove a data cluster from the active collections.
 /// </summary>
 internal static void RemoveCluster(MetaCluster cluster)
 {
     // if the cluster being removed is the default cluster
     if (cluster == _defaultCluster)
     {
         if (Clusters.Count == 0)
         {
             _defaultCluster = null;
         }
         else
         {
             DefaultCluster = Clusters[0];
         }
     }
     Clusters.RemoveQuick(cluster);
 }
Beispiel #4
0
        /// <summary>
        /// Initialize a Keyspace by name in association with the specified cluster.
        /// </summary>
        internal Keyspace(string name, MetaCluster metaCluster)
        {
            if (metaCluster == null)
            {
                MetaCluster = ManagerCql.DefaultCluster;
            }
            else
            {
                MetaCluster = metaCluster;
            }

            // initialize cache collections
            Tables        = new Shared <Dictionary <string, Table> >(new Dictionary <string, Table>());
            Statements    = new Shared <Dictionary <int, PreparedStatement> >(new Dictionary <int, PreparedStatement>());
            TableMetadata = new Shared <Dictionary <string, TableMetadata> >(new Dictionary <string, TableMetadata>());
            // initialize the batch related fields
            _batch     = new ArrayRig <Statement>();
            _batchLock = new Lock();

            // decrease the batch timeout if debugging
      #if DEBUG
            BatchTimeout = 10000;
      #endif

            // create the act used to execute batch statements
            Act executeBatch = new Act(() => ExecuteBatch());
            _batchTimer = new Timer(BatchInterval, executeBatch, false);
            _onExecuted = new ArrayRig <IAction>();

            // setup the auto update watch
            if (_autoUpdateTime > 0)
            {
                _autoUpdateWatch = new Watch(_autoUpdateTime, true, OnAutoUpdate);
            }

            try {
                // connect to the cluster
                _session = MetaCluster.Cluster.Connect();
            } catch (Exception ex) {
                // log the error
                Log.Error("Problem getting Keyspace '" + name + "' metadata from the Cluster.", ex);
                return;
            }

            // initialize a Mapper instance for use by this Keyspace
            Mapper = new Mapper(_session);

            // get the metadata associated with this Keyspace
            Metadata = MetaCluster.Cluster.Metadata.GetKeyspace(name);

            // if the Keyspace doesn't exist
            if (Metadata == null)
            {
                // create the Keyspace
                if (MetaCluster.DataCenters == null)
                {
                    _session.CreateKeyspace(name,
                                            ReplicationStrategies.CreateSimpleStrategyReplicationProperty(1));
                }
                else
                {
                    _session.CreateKeyspace(name,
                                            ReplicationStrategies.CreateNetworkTopologyStrategyReplicationProperty(MetaCluster.DataCenters));
                }

                // get the metadata
                Metadata = MetaCluster.Cluster.Metadata.GetKeyspace(name);
            }

            // add the Keyspace to the DataCluster
            MetaCluster.AddKeyspace(this);

            // make the target Keyspace of the Session to this Keyspace
            _session.ChangeKeyspace(Metadata.Name);

            TableMetadata.Take();
            foreach (var tableMetadata in Metadata.GetTablesMetadata())
            {
                TableMetadata.Item.Add(tableMetadata.Name, tableMetadata);
            }
            TableMetadata.Release();
        }
Beispiel #5
0
        //-------------------------------------------//

        /// <summary>
        /// Construct a new instance of the load balancer.
        /// </summary>
        public LoadBalancer(MetaCluster metaCluster)
        {
            _metaCluster = metaCluster;
        }