public virtual ICluster Build(CassandraClusterElement clusterConfig, ILogger logger)
 {
     ICluster cluster = null;
     ClusterType clusterType;
     clusterType = (ClusterType) Enum.Parse(typeof(ClusterType), clusterConfig.ClusterType, true);
     switch (clusterType)
     {
         case ClusterType.DEFAULT:
             cluster = this.BuildDefaultCluster(clusterConfig, logger);
             break;
         default:
             throw new NotImplementedException(String.Format("ClusterType '{0}' not implemented.", clusterType));
     }
     return cluster;
 }
 /// <summary>
 /// Add CassandraClusterElement on the inner Array
 /// </summary>
 /// <seealso cref="Aquiles.Configuration.CassandraClusterElement"/>
 /// <param name="element">element to be added</param>
 public void Add(CassandraClusterElement element)
 {
     BaseAdd(element);
 }
 /// <summary>
 /// Remove the specified CassandraClusterElement from the inner Array
 /// </summary>
 /// <seealso cref="Aquiles.Configuration.CassandraClusterElement"/>
 /// <param name="element">element to be removed</param>
 public void Remove(CassandraClusterElement element)
 {
     if (BaseIndexOf(element) >= 0)
         BaseRemove(element.FriendlyName);
 }
 /// <summary>
 /// Given a CassandraClusterElement, it returns its position on the array
 /// </summary>
 /// <seealso cref="Aquiles.Configuration.CassandraClusterElement"/>
 /// <param name="element">a CassandraClusterElement contained on the array</param>
 /// <returns>the position of the element</returns>
 public int IndexOf(CassandraClusterElement element)
 {
     return BaseIndexOf(element);
 }
 protected virtual ICluster BuildDefaultCluster(CassandraClusterElement clusterConfig, ILogger logger)
 {
     DefaultClusterFactory clusterFactory = new DefaultClusterFactory();
     clusterFactory.Logger = logger;
     clusterFactory.FriendlyName = clusterConfig.FriendlyName;
     clusterFactory.PoolManager = this.buildPoolManager(clusterConfig, logger, clusterFactory.FriendlyName);
     return clusterFactory.Create();
 }
 protected abstract IConnectionFactory buildClientFactory(CassandraClusterElement clusterConfig);
        private IClientPool buildSizeControlledClientPool(CassandraClusterElement clusterConfig, ILogger logger, string clusterName)
        {
            SpecialConnectionParameterElement specialConfig = null;
            int intTempValue = 0;
            SizeControlledClientPoolFactory poolFactory = new SizeControlledClientPoolFactory();
            poolFactory.Name = String.Concat(clusterName, "_sizeControlledPool");
            poolFactory.ClientFactory = this.buildClientFactory(clusterConfig);
            poolFactory.EndpointManager = this.buildEndpointManager(clusterConfig, logger, poolFactory.Name);
            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, POOL_DUETIME_KEY);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue) && intTempValue >= 0)
            {
                poolFactory.DueTime = intTempValue;
            }
            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, POOL_PERIODICTIME_KEY);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue) && intTempValue > 0)
            {
                poolFactory.PeriodicTime = intTempValue;
            }
            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, POOL_MAGIC_NUMBER_KEY);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue) && intTempValue > 0)
            {
                poolFactory.MagicNumber = intTempValue;
            }
            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, POOL_MAXIMUM_CLIENTS_TO_SUPPORT_KEY);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue) && intTempValue > 0)
            {
                poolFactory.MaximumClientsToSupport = intTempValue;
            }

            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, POOL_MAXIMUM_RETRIES_TO_POLL_CLIENT);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue) && intTempValue >= 0)
            {
                poolFactory.MaximumRetriesToPollClient = intTempValue;
            }

            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, POOL_MINIMUM_CLIENTS_TO_KEEP_KEY);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue) && intTempValue >= 0)
            {
                poolFactory.MinimumClientsToKeep = intTempValue;
            }

            poolFactory.Logger = logger;

            return poolFactory.Create();
        }
        private IEndpointManager buildRoundRobinEndpointManager(CassandraClusterElement clusterConfig, ILogger logger, string poolName)
        {
            RoundRobinEndpointManagerFactory endpointManagerFactory = new RoundRobinEndpointManagerFactory();
            endpointManagerFactory.Name = String.Concat(poolName,"_endpointManager");
            endpointManagerFactory.ClientFactory = this.buildClientFactory(clusterConfig);
            endpointManagerFactory.Endpoints = this.buildEndpoints(clusterConfig.EndpointManager.CassandraEndpoints, clusterConfig.EndpointManager.DefaultTimeout);
            SpecialConnectionParameterElement specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, ENDPOINTMANAGER_PERIODICTIME_KEY);
            int intTempValue = 0;
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue))
            {
                endpointManagerFactory.DueTime = intTempValue;
            }
            specialConfig = this.retrieveSpecialParameter(clusterConfig.Connection.SpecialConnectionParameters, ENDPOINTMANAGER_PERIODICTIME_KEY);
            if (specialConfig != null && Int32.TryParse(specialConfig.Value, out intTempValue))
            {
                endpointManagerFactory.PeriodicTime = intTempValue;
            }

            endpointManagerFactory.Logger = logger;

            return endpointManagerFactory.Create();
        }
        private IClientPool buildNoClientPool(CassandraClusterElement clusterConfig, ILogger logger, string clusterName)
        {
            NoClientPoolFactory poolFactory = new NoClientPoolFactory();
            poolFactory.Name = String.Concat(clusterName, "_noPool");
            poolFactory.ClientFactory = this.buildClientFactory(clusterConfig);
            poolFactory.EndpointManager = this.buildEndpointManager(clusterConfig, logger, poolFactory.Name);
            poolFactory.Logger = logger;

            return poolFactory.Create();
        }
        protected virtual IClientPool buildPoolManager(CassandraClusterElement clusterConfig, ILogger logger, string clusterName)
        {
            IClientPool clientPool = null;
            ConnectionElement connectionConfig = clusterConfig.Connection;
            PoolType poolType;
            poolType = (PoolType) Enum.Parse(typeof(PoolType), connectionConfig.PoolType, true);
            switch (poolType)
            {
                case PoolType.NOPOOL:
                    clientPool = this.buildNoClientPool(clusterConfig, logger, clusterName);
                    break;
                case PoolType.SIZECONTROLLEDPOOL:
                    clientPool = this.buildSizeControlledClientPool(clusterConfig, logger, clusterName);
                    break;
                default:
                    throw new NotImplementedException(String.Format("PoolType '{0}' not implemented.", poolType));
            }

            return clientPool;
        }
 protected virtual IEndpointManager buildEndpointManager(CassandraClusterElement clusterConfig, ILogger logger, string poolName)
 {
     IEndpointManager endpointManager = null;
     EndpointManagerType endpointManagerType;
     endpointManagerType = (EndpointManagerType) Enum.Parse(typeof(EndpointManagerType), clusterConfig.EndpointManager.Type, true);
     switch (endpointManagerType)
     {
         case EndpointManagerType.ROUNDROBIN:
             endpointManager = this.buildRoundRobinEndpointManager(clusterConfig, logger, poolName);
             break;
         default:
             throw new NotImplementedException(String.Format("EndpointManagerType '{0}' not implemented.", endpointManagerType));
     }
     return endpointManager;
 }