Example #1
0
 /// <summary>
 /// Creates a new instance. This class is also used to shareable a context across all instance that are created below one Cluster instance.
 /// One configuration instance per Cluster instance.
 /// </summary>
 internal Configuration(Policies policies,
     ProtocolOptions protocolOptions,
     PoolingOptions poolingOptions,
     SocketOptions socketOptions,
     ClientOptions clientOptions,
     IAuthProvider authProvider,
     IAuthInfoProvider authInfoProvider,
     QueryOptions queryOptions,
     IAddressTranslator addressTranslator)
 {
     if (addressTranslator == null)
     {
         throw new ArgumentNullException("addressTranslator");
     }
     if (queryOptions == null)
     {
         throw new ArgumentNullException("queryOptions");
     }
     _policies = policies;
     _protocolOptions = protocolOptions;
     _poolingOptions = poolingOptions;
     _socketOptions = socketOptions;
     _clientOptions = clientOptions;
     _authProvider = authProvider;
     _authInfoProvider = authInfoProvider;
     _queryOptions = queryOptions;
     _addressTranslator = addressTranslator;
 }
Example #2
0
        private Cluster Connect()
        {
            try
            {
                QueryOptions queryOptions = new QueryOptions()
                    .SetConsistencyLevel(ConsistencyLevel.One);
                var builder = Cassandra.Cluster.Builder();
                builder.AddContactPoints(CassandraConfig.ContactPoints);

                if (!string.IsNullOrEmpty(CassandraConfig.Credentials.UserName) &&
                    !string.IsNullOrEmpty(CassandraConfig.Credentials.Password))
                {
                    builder.WithCredentials(
                        CassandraConfig.Credentials.UserName,
                        CassandraConfig.Credentials.Password);
                }
                builder.WithQueryOptions(queryOptions);
                Cluster cluster = builder.Build();

                return cluster;
            }
            catch (Exception e)
            {
                return null;
            }
        }
 internal static QueryProtocolOptions CreateFromQuery(Statement query, QueryOptions queryOptions)
 {
     if (query == null)
     {
         return Default;
     }
     var consistency = query.ConsistencyLevel ?? queryOptions.GetConsistencyLevel();
     var pageSize = query.PageSize != 0 ? query.PageSize : queryOptions.GetPageSize();
     var options = new QueryProtocolOptions(
         consistency,
         query.QueryValues,
         query.SkipMetadata, 
         pageSize, 
         query.PagingState, 
         query.SerialConsistencyLevel)
     {
         Timestamp = query.Timestamp
     };
     return options;
 }
Example #4
0
 /// <summary>
 /// Sets the QueryOptions to use for the newly created Cluster.
 /// 
 /// If no query options are set through this method, default query
 /// options will be used.
 /// </summary>
 /// <param name="options">the QueryOptions to use.</param>
 /// <returns>this Builder.</returns>
 public Builder WithQueryOptions(QueryOptions options)
 {
     _queryOptions = options;
     return this;
 }
Example #5
0
 /// <summary>
 /// Sets the default consistency level.
 /// </summary>
 internal void SetDefaultConsistencyLevel(ConsistencyLevel consistencyLevel)
 {
     QueryOptions.SetDefaultConsistencyLevel(consistencyLevel);
 }
Example #6
0
        /// <summary>
        /// Creates a new instance. This class is also used to shareable a context across all instance that are created below one Cluster instance.
        /// One configuration instance per Cluster instance.
        /// </summary>
        internal Configuration(Policies policies,
                               ProtocolOptions protocolOptions,
                               PoolingOptions poolingOptions,
                               SocketOptions socketOptions,
                               ClientOptions clientOptions,
                               IAuthProvider authProvider,
                               IAuthInfoProvider authInfoProvider,
                               QueryOptions queryOptions,
                               IAddressTranslator addressTranslator,
                               IReadOnlyDictionary <string, IExecutionProfile> executionProfiles,
                               MetadataSyncOptions metadataSyncOptions,
                               IEndPointResolver endPointResolver,
                               IDriverMetricsProvider driverMetricsProvider,
                               DriverMetricsOptions metricsOptions,
                               string sessionName,
                               GraphOptions graphOptions,
                               Guid?clusterId,
                               string appVersion,
                               string appName,
                               MonitorReportingOptions monitorReportingOptions,
                               TypeSerializerDefinitions typeSerializerDefinitions,
                               bool?keepContactPointsUnresolved,
                               bool?allowBetaProtocolVersions,
                               ISessionFactory sessionFactory                       = null,
                               IRequestOptionsMapper requestOptionsMapper           = null,
                               IStartupOptionsFactory startupOptionsFactory         = null,
                               IInsightsSupportVerifier insightsSupportVerifier     = null,
                               IRequestHandlerFactory requestHandlerFactory         = null,
                               IHostConnectionPoolFactory hostConnectionPoolFactory = null,
                               IRequestExecutionFactory requestExecutionFactory     = null,
                               IConnectionFactory connectionFactory                 = null,
                               IControlConnectionFactory controlConnectionFactory   = null,
                               IPrepareHandlerFactory prepareHandlerFactory         = null,
                               ITimerFactory timerFactory = null,
                               IObserverFactoryBuilder observerFactoryBuilder = null,
                               IInsightsClientFactory insightsClientFactory   = null,
                               IContactPointParser contactPointParser         = null,
                               IServerNameResolver serverNameResolver         = null,
                               IDnsResolver dnsResolver = null,
                               IMetadataRequestHandler metadataRequestHandler     = null,
                               ITopologyRefresherFactory topologyRefresherFactory = null,
                               ISchemaParserFactory schemaParserFactory           = null,
                               ISupportedOptionsInitializerFactory supportedOptionsInitializerFactory = null,
                               IProtocolVersionNegotiator protocolVersionNegotiator = null,
                               IServerEventsSubscriber serverEventsSubscriber       = null)
        {
            AddressTranslator = addressTranslator ?? throw new ArgumentNullException(nameof(addressTranslator));
            QueryOptions      = queryOptions ?? throw new ArgumentNullException(nameof(queryOptions));
            GraphOptions      = graphOptions ?? new GraphOptions();

            ClusterId                   = clusterId ?? Guid.NewGuid();
            ApplicationVersion          = appVersion ?? Configuration.DefaultApplicationVersion;
            ApplicationName             = appName ?? Configuration.FallbackApplicationName;
            ApplicationNameWasGenerated = appName == null;

            Policies                           = policies;
            ProtocolOptions                    = protocolOptions;
            PoolingOptions                     = poolingOptions;
            SocketOptions                      = socketOptions;
            ClientOptions                      = clientOptions;
            AuthProvider                       = authProvider;
            AuthInfoProvider                   = authInfoProvider;
            StartupOptionsFactory              = startupOptionsFactory ?? new StartupOptionsFactory(ClusterId, ApplicationVersion, ApplicationName);
            SessionFactory                     = sessionFactory ?? new SessionFactory();
            RequestOptionsMapper               = requestOptionsMapper ?? new RequestOptionsMapper();
            MetadataSyncOptions                = metadataSyncOptions?.Clone() ?? new MetadataSyncOptions();
            DnsResolver                        = dnsResolver ?? new DnsResolver();
            MetadataRequestHandler             = metadataRequestHandler ?? new MetadataRequestHandler();
            TopologyRefresherFactory           = topologyRefresherFactory ?? new TopologyRefresherFactory();
            SchemaParserFactory                = schemaParserFactory ?? new SchemaParserFactory();
            SupportedOptionsInitializerFactory = supportedOptionsInitializerFactory ?? new SupportedOptionsInitializerFactory();
            ProtocolVersionNegotiator          = protocolVersionNegotiator ?? new ProtocolVersionNegotiator();
            ServerEventsSubscriber             = serverEventsSubscriber ?? new ServerEventsSubscriber();

            MetricsOptions              = metricsOptions ?? new DriverMetricsOptions();
            MetricsProvider             = driverMetricsProvider ?? new NullDriverMetricsProvider();
            SessionName                 = sessionName;
            MetricsEnabled              = driverMetricsProvider != null;
            TypeSerializers             = typeSerializerDefinitions?.Definitions;
            KeepContactPointsUnresolved = keepContactPointsUnresolved ?? false;
            AllowBetaProtocolVersions   = allowBetaProtocolVersions ?? false;

            ObserverFactoryBuilder    = observerFactoryBuilder ?? (MetricsEnabled ? (IObserverFactoryBuilder) new MetricsObserverFactoryBuilder() : new NullObserverFactoryBuilder());
            RequestHandlerFactory     = requestHandlerFactory ?? new RequestHandlerFactory();
            HostConnectionPoolFactory = hostConnectionPoolFactory ?? new HostConnectionPoolFactory();
            RequestExecutionFactory   = requestExecutionFactory ?? new RequestExecutionFactory();
            ConnectionFactory         = connectionFactory ?? new ConnectionFactory();
            ControlConnectionFactory  = controlConnectionFactory ?? new ControlConnectionFactory();
            PrepareHandlerFactory     = prepareHandlerFactory ?? new PrepareHandlerFactory();
            TimerFactory = timerFactory ?? new TaskBasedTimerFactory();

            RequestOptions    = RequestOptionsMapper.BuildRequestOptionsDictionary(executionProfiles, policies, socketOptions, clientOptions, queryOptions, GraphOptions);
            ExecutionProfiles = BuildExecutionProfilesDictionary(executionProfiles, RequestOptions);

            MonitorReportingOptions = monitorReportingOptions ?? new MonitorReportingOptions();
            InsightsSupportVerifier = insightsSupportVerifier ?? Configuration.DefaultInsightsSupportVerifier;
            InsightsClientFactory   = insightsClientFactory ?? Configuration.DefaultInsightsClientFactory;
            ServerNameResolver      = serverNameResolver ?? new ServerNameResolver(ProtocolOptions);
            EndPointResolver        = endPointResolver ?? new EndPointResolver(ServerNameResolver);
            ContactPointParser      = contactPointParser ?? new ContactPointParser(DnsResolver, ProtocolOptions, ServerNameResolver, KeepContactPointsUnresolved);

            // Create the buffer pool with 16KB for small buffers and 256Kb for large buffers.
            // The pool does not eagerly reserve the buffers, so it doesn't take unnecessary memory
            // to create the instance.
            BufferPool = new RecyclableMemoryStreamManager(16 * 1024, 256 * 1024, ProtocolOptions.MaximumFrameLength);
            Timer      = new HashedWheelTimer();
        }