예제 #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,
                               IStartupOptionsFactory startupOptionsFactory,
                               ISessionFactoryBuilder <IInternalCluster, IInternalSession> sessionFactoryBuilder,
                               IReadOnlyDictionary <string, IExecutionProfile> executionProfiles,
                               IRequestOptionsMapper requestOptionsMapper,
                               MetadataSyncOptions metadataSyncOptions,
                               IEndPointResolver endPointResolver,
                               IRequestHandlerFactory requestHandlerFactory         = null,
                               IHostConnectionPoolFactory hostConnectionPoolFactory = null,
                               IRequestExecutionFactory requestExecutionFactory     = null,
                               IConnectionFactory connectionFactory = null,
                               IControlConnectionFactory controlConnectionFactory = null,
                               IPrepareHandlerFactory prepareHandlerFactory       = null,
                               ITimerFactory timerFactory = null)
        {
            AddressTranslator     = addressTranslator ?? throw new ArgumentNullException(nameof(addressTranslator));
            QueryOptions          = queryOptions ?? throw new ArgumentNullException(nameof(queryOptions));
            Policies              = policies;
            ProtocolOptions       = protocolOptions;
            PoolingOptions        = poolingOptions;
            SocketOptions         = socketOptions;
            ClientOptions         = clientOptions;
            AuthProvider          = authProvider;
            AuthInfoProvider      = authInfoProvider;
            StartupOptionsFactory = startupOptionsFactory;
            SessionFactoryBuilder = sessionFactoryBuilder;
            RequestOptionsMapper  = requestOptionsMapper;
            MetadataSyncOptions   = metadataSyncOptions?.Clone() ?? new MetadataSyncOptions();
            DnsResolver           = new DnsResolver();
            EndPointResolver      = endPointResolver ?? new EndPointResolver(DnsResolver, protocolOptions);

            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);
            ExecutionProfiles = BuildExecutionProfilesDictionary(executionProfiles, RequestOptions);

            // 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();
        }
예제 #2
0
 /// <summary>
 /// <para>
 /// If not set through this method, the default value options will be used (metadata synchronization is enabled by default). The api reference of <see cref="MetadataSyncOptions"/>
 /// specifies what is the default for each option.
 /// </para>
 /// <para>
 /// In case you disable Metadata synchronization, please ensure you invoke <see cref="ICluster.RefreshSchemaAsync"/> in order to keep the token metadata up to date
 /// otherwise you will not be getting everything you can out of token aware routing, i.e. <see cref="TokenAwarePolicy"/>, which is enabled by the default.
 /// </para>
 /// <para>
 /// Disabling this feature has the following impact:
 ///
 /// <list type="bullet">
 ///
 /// <item><description>
 /// Token metadata will not be computed and stored.
 /// This means that token aware routing (<see cref="TokenAwarePolicy"/>, enabled by default) will only work correctly
 /// if you keep the token metadata up to date using the <see cref="ICluster.RefreshSchemaAsync"/> method.
 /// If you wish to go this route of manually refreshing the metadata then
 /// it's recommended to refresh only the keyspaces that this application will use, by passing the <code>keyspace</code> parameter.
 /// </description></item>
 ///
 /// <item><description>
 /// Keyspace metadata will not be cached by the driver. Every time you call methods like <see cref="Metadata.GetTable"/>, <see cref="Metadata.GetKeyspace"/>
 /// and other similar methods of the <see cref="Metadata"/> class, the driver will query that data on demand and will not cache it.
 /// </description></item>
 ///
 /// <item><description>
 /// The driver will not handle <code>SCHEMA_CHANGED</code> responses. This means that when you execute schema changing statements through the driver, it will
 /// not update the schema or topology metadata automatically before returning.
 /// </description></item>
 ///
 /// </list>
 /// </para>
 /// </summary>
 /// <summary>
 /// </summary>
 /// <param name="metadataSyncOptions">The new options to set.</param>
 /// <returns>This Builder.</returns>
 public Builder WithMetadataSyncOptions(MetadataSyncOptions metadataSyncOptions)
 {
     _metadataSyncOptions = metadataSyncOptions;
     return(this);
 }
예제 #3
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,
                               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)
        {
            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();
            MetricsOptions              = metricsOptions ?? new DriverMetricsOptions();
            MetricsProvider             = driverMetricsProvider ?? new NullDriverMetricsProvider();
            SessionName                 = sessionName;
            MetricsEnabled              = driverMetricsProvider != null;
            TypeSerializers             = typeSerializerDefinitions?.Definitions;
            KeepContactPointsUnresolved = keepContactPointsUnresolved ?? 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();
        }