internal ControlConnection(byte initialProtocolVersion, Configuration config, Metadata metadata)
 {
     Metadata = metadata;
     _reconnectionSchedule = _reconnectionPolicy.NewSchedule();
     _reconnectionTimer = new Timer(_ => Refresh(true), null, Timeout.Infinite, Timeout.Infinite);
     _config = config;
     ProtocolVersion = initialProtocolVersion;
 }
 internal ControlConnection(byte initialProtocolVersion, Configuration config, Metadata metadata)
 {
     _metadata = metadata;
     _reconnectionPolicy = config.Policies.ReconnectionPolicy;
     _reconnectionSchedule = _reconnectionPolicy.NewSchedule();
     _reconnectionTimer = new Timer(_ => Reconnect(), null, Timeout.Infinite, Timeout.Infinite);
     _config = config;
     _serializer = new Serializer(initialProtocolVersion, config.TypeSerializers);
 }
Esempio n. 3
0
        internal KeyspaceMetadata(Metadata parent, string name, bool durableWrites, string strategyClass,
                                  IDictionary<string, int> replicationOptions)
        {
            //Can not directly reference to schemaParser as it might change
            _parent = parent;
            Name = name;
            DurableWrites = durableWrites;

            StrategyClass = strategyClass;
            if (strategyClass != null && strategyClass.StartsWith("org.apache.cassandra.locator."))
            {
                StrategyClass = strategyClass.Replace("org.apache.cassandra.locator.", "");   
            }
            Replication = replicationOptions;
        }
Esempio n. 4
0
        private Cluster(IEnumerable<IPAddress> contactPoints, Configuration configuration)
        {
            _contactPoints = contactPoints;
            _configuration = configuration;
            _metadata = new Metadata(configuration.Policies.ReconnectionPolicy);

            var controlpolicies = new Policies(
                _configuration.Policies.LoadBalancingPolicy,
                new ExponentialReconnectionPolicy(2*1000, 5*60*1000),
                Policies.DefaultRetryPolicy);

            foreach (IPAddress ep in _contactPoints)
                Metadata.AddHost(ep);

            //Use 1 connection per host
            //The connection will be reused, it wont create a connection per host.
            var controlPoolingOptions = new PoolingOptions()
                .SetCoreConnectionsPerHost(HostDistance.Local, 1)
                .SetMaxConnectionsPerHost(HostDistance.Local, 1)
                .SetMinSimultaneousRequestsPerConnectionTreshold(HostDistance.Local, 0)
                .SetMaxSimultaneousRequestsPerConnectionTreshold(HostDistance.Local, 127);

            var controlConnection = new ControlConnection
                (this,
                new List<IPAddress>(),
                controlpolicies,
                new ProtocolOptions(_configuration.ProtocolOptions.Port, configuration.ProtocolOptions.SslOptions),
                controlPoolingOptions,
                _configuration.SocketOptions,
                new ClientOptions(true, _configuration.ClientOptions.QueryAbortTimeout, null),
                _configuration.AuthProvider,
                _configuration.AuthInfoProvider
                );

            _metadata.SetupControllConnection(controlConnection);
            _binaryProtocolVersion = controlConnection.ProtocolVersion;
            _logger.Info("Binary protocol version: [" + _binaryProtocolVersion + "]");
        }
Esempio n. 5
0
        private Cluster(IEnumerable<IPAddress> contactPoints, Configuration configuration)
        {
            this._contactPoints = contactPoints;
            this._configuration = configuration;
            this._metadata = new Metadata(configuration.Policies.ReconnectionPolicy);

            var controlpolicies = new Cassandra.Policies(
                _configuration.Policies.LoadBalancingPolicy,
                new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000),
                Cassandra.Policies.DefaultRetryPolicy);

            foreach (var ep in _contactPoints)
                Metadata.AddHost(ep);

            var poolingOptions = new PoolingOptions().SetCoreConnectionsPerHost(HostDistance.Local, 1);

            var controlConnection = new ControlConnection(this, new List<IPAddress>(), controlpolicies,
                                                        new ProtocolOptions(_configuration.ProtocolOptions.Port),
                                                       poolingOptions, _configuration.SocketOptions,
                                                       new ClientOptions(
                                                           true,
                                                           _configuration.ClientOptions.QueryAbortTimeout, null,
                                                           _configuration.ClientOptions.AsyncCallAbortTimeout),
                                                       _configuration.AuthInfoProvider);

            _metadata.SetupControllConnection(controlConnection);
        }
Esempio n. 6
0
 private Cluster(IEnumerable<IPEndPoint> contactPoints, Configuration configuration)
 {
     Configuration = configuration;
     _metadata = new Metadata(configuration);
     foreach (var ep in contactPoints)
     {
         _metadata.AddHost(ep);
     }
 }
Esempio n. 7
0
        /// <summary>
        ///  Creates a new session on this cluster and sets a keyspace to use.
        /// </summary>
        /// <param name="keyspace"> The name of the keyspace to use for the created <code>Session</code>. </param>
        /// <returns>a new session on this cluster set to keyspace: 
        ///  <code>keyspaceName</code>. </returns>
        public Session Connect(string keyspace)
        {
            bool controlConnectionCreated = false;
            lock (_controlConnectionGuard)
            {
                if (_controlConnection == null)
                {
                    controlConnectionCreated = true;
                    var controlpolicies = new Cassandra.Policies(
                        _configuration.Policies.LoadBalancingPolicy,
                        new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000),
                        Cassandra.Policies.DefaultRetryPolicy);

                    _hosts = new Hosts(_configuration.Policies.ReconnectionPolicy);

                    foreach (var ep in _contactPoints)
                        _hosts.AddIfNotExistsOrBringUpIfDown(ep);

                    var poolingOptions = new PoolingOptions().SetCoreConnectionsPerHost(HostDistance.Local, 1);

                    _controlConnection = new ControlConnection(this, new List<IPAddress>(), controlpolicies,
                                                               _configuration.ProtocolOptions,
                                                               poolingOptions, _configuration.SocketOptions,
                                                               new ClientOptions(
                                                                   _configuration.ClientOptions.WithoutRowSetBuffering,
                                                                   _configuration.ClientOptions.QueryAbortTimeout, null,
                                                                   _configuration.ClientOptions.AsyncCallAbortTimeout),
                                                               _configuration.AuthInfoProvider,
                                                               _configuration.MetricsEnabled);

                    _metadata = new Metadata(_hosts, _controlConnection);

                    _controlConnection.Init();
                }
            }
            var scs = new Session(this, _contactPoints, _configuration.Policies,
                                  _configuration.ProtocolOptions,
                                  _configuration.PoolingOptions, _configuration.SocketOptions,
                                  _configuration.ClientOptions,
                                  _configuration.AuthInfoProvider, _configuration.MetricsEnabled, keyspace, _hosts);
            scs.Init();
            lock (_connectedSessions)
                _connectedSessions.Add(scs);
            _logger.Info("Session connected!");

            if (controlConnectionCreated)
                RefreshSchema();

            return scs;
        }
Esempio n. 8
0
 internal ControlConnection(ICluster cluster, Metadata metadata)
 {
     Metadata = metadata;
     _reconnectionSchedule = _reconnectionPolicy.NewSchedule();
     _reconnectionTimer = new Timer(_ => Refresh(true), null, Timeout.Infinite, Timeout.Infinite);
     _config = cluster.Configuration;
 }
Esempio n. 9
0
 internal ControlConnection(byte initialProtocolVersion, Configuration config, Metadata metadata)
 {
     _metadata             = metadata;
     _reconnectionPolicy   = config.Policies.ReconnectionPolicy;
     _reconnectionSchedule = _reconnectionPolicy.NewSchedule();
     _reconnectionTimer    = new Timer(_ => Reconnect(), null, Timeout.Infinite, Timeout.Infinite);
     _config     = config;
     _serializer = new Serializer(initialProtocolVersion, config.TypeSerializers);
 }
Esempio n. 10
0
 internal KeyspaceMetadata(Metadata parent, string name, bool durableWrites, string strategyClass,
                           IDictionary <string, int> replicationOptions, bool isVirtual = false)
     : this(parent, name, durableWrites, strategyClass, replicationOptions, new ReplicationStrategyFactory(), isVirtual)
 {
 }
Esempio n. 11
0
 internal SchemaParserV3(Metadata parent, Func <string, string, Task <UdtColumnInfo> > udtResolver)
     : base(parent, udtResolver)
 {
 }
Esempio n. 12
0
 protected SchemaParser(Metadata parent)
 {
     Cc     = parent.ControlConnection;
     Parent = parent;
 }
Esempio n. 13
0
 internal SchemaParserV1(Metadata parent) : base(parent)
 {
 }