Class StargateClientBuilder

java.lang.Object
io.stargate.sdk.StargateClientBuilder
All Implemented Interfaces:
Serializable

public class StargateClientBuilder extends Object implements Serializable
The Stargate SDK allows to connect to multiple APIS and provides a wide range of options. With the more advanced settings we need an abtraction for the configuration. It can then be loaded from multiple sources like .. a builder, an application.yaml, a service discovery with different configuration loader.
Author:
Cedrick LUNVEN (@clunven)
See Also:
  • Field Details

    • DEFAULT_DATACENTER

      public static final String DEFAULT_DATACENTER
      default datacenter id.
      See Also:
    • username

      protected String username
      user name.
    • password

      protected String password
      This the endPoint to invoke to work with different API(s).
    • appToken

      protected String appToken
      if provided the authentication URL is not use to get token.
    • stargateNodesDC

      protected Map<String,StargateDataCenter> stargateNodesDC
      if an apiToken is provided it will be used for all nodes.
    • localDatacenter

      protected String localDatacenter
      Local datacenter.
    • enabledCql

      protected boolean enabledCql
      If the flag is enabled the Cql Session will not be created even if parameters are ok.
    • cqlSession

      protected com.datastax.oss.driver.api.core.CqlSession cqlSession
      Providing Ad Hoc CqlSession.
    • driverConfig

      protected com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder driverConfig
      Dynamic configuration.
    • cqlOptions

      protected com.datastax.oss.driver.api.core.config.OptionsMap cqlOptions
      Track options in the object to help retrive values. The configuration is loaded with a Programmatic Loader and not the options Map.
    • cqlMetricsRegistry

      protected Object cqlMetricsRegistry
      Metrics Registry if provided.
    • cqlRequestTracker

      protected com.datastax.oss.driver.api.core.tracker.RequestTracker cqlRequestTracker
      Request tracker.
    • enabledGrpc

      protected boolean enabledGrpc
      If the flag is enabled the Grpc Session will not be created even if parameters are ok.
    • httpRetryConfig

      protected com.evanlennick.retry4j.config.RetryConfig httpRetryConfig
      Override Retry configuration.
    • httpRequestConfig

      protected org.apache.hc.client5.http.config.RequestConfig httpRequestConfig
      Override Request configuration.
    • httpObservers

      protected Map<String,io.stargate.sdk.audit.ServiceCallObserver> httpObservers
      Observers.
  • Constructor Details

    • StargateClientBuilder

      public StargateClientBuilder()
      Load defaults from Emvironment variables
  • Method Details

    • getStargateNodesDC

      public Map<String,StargateDataCenter> getStargateNodesDC()
      Gets stargateNodesDC
      Returns:
      value of stargateNodesDC
    • withAuthCredentials

      public StargateClientBuilder withAuthCredentials(String username, String password)
      Fill username and password.
      Parameters:
      username - user identifier
      password - password
      Returns:
      current reference
    • getApiTokenProvider

      public io.stargate.sdk.api.TokenProvider getApiTokenProvider(String dc)
      Retrieve an TokenProvider based on token.
      Parameters:
      dc - current DC
      Returns:
      the token provider
    • withApiToken

      public StargateClientBuilder withApiToken(String token)
      Api token available for all the nodes.
      Parameters:
      token - current token
      Returns:
      self reference
    • withApiTokenProvider

      public StargateClientBuilder withApiTokenProvider(String... url)
      You will get one token provider for a DC
      Parameters:
      url - list of URL for authentication
      Returns:
      slef reference
    • withApiTokenProviderDC

      public StargateClientBuilder withApiTokenProviderDC(String dc, io.stargate.sdk.api.TokenProvider tokenProvider)
      Provide token provider for a DC.
      Parameters:
      dc - datacentername
      tokenProvider - token provider
      Returns:
      self reference
    • withApiTokenProviderDC

      public StargateClientBuilder withApiTokenProviderDC(String dc, String... url)
      You will get one token provider for a DC
      Parameters:
      dc - datacenter name
      url - list of URL for authentication
      Returns:
      slef reference
    • addServiceRest

      public StargateClientBuilder addServiceRest(io.stargate.sdk.http.ServiceHttp rest)
      Add a node to the cluster.
      Parameters:
      rest - rest node
      Returns:
      current builder
    • addServiceRest

      public StargateClientBuilder addServiceRest(String dc, io.stargate.sdk.http.ServiceHttp rest)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      dc - target datacenter
      rest - target service
      Returns:
      current reference
    • addServiceJson

      public StargateClientBuilder addServiceJson(String dc, io.stargate.sdk.http.ServiceHttp json)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      dc - target datacenter
      json - target json service
      Returns:
      current reference
    • addDocumentService

      public StargateClientBuilder addDocumentService(String dc, io.stargate.sdk.http.ServiceHttp rest)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      dc - target datacenter
      rest - target service
      Returns:
      current reference
    • addDocumentService

      public StargateClientBuilder addDocumentService(io.stargate.sdk.http.ServiceHttp doc)
      Add a new Document Service.
      Parameters:
      doc - document service
      Returns:
      current reference
    • addGraphQLService

      public StargateClientBuilder addGraphQLService(String dc, io.stargate.sdk.http.ServiceHttp rest)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      dc - target datacenter
      rest - target service
      Returns:
      current reference
    • addGraphQLService

      public StargateClientBuilder addGraphQLService(io.stargate.sdk.http.ServiceHttp rest)
      Add a GraphQL Service in the current DC
      Parameters:
      rest - current graphQL service
      Returns:
      current reference.
    • addGrpcService

      public StargateClientBuilder addGrpcService(String dc, ServiceGrpc grpc)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      dc - target datacenter
      grpc - target service
      Returns:
      current reference
    • addGrpcService

      public StargateClientBuilder addGrpcService(ServiceGrpc grpc)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      grpc - target service
      Returns:
      current reference
    • withLocalDatacenter

      public StargateClientBuilder withLocalDatacenter(String localDc)
      Populate current datacenter. Will be used as localDc in cqlSession if provided or local DC at Http level.
      Parameters:
      localDc - localDataCernter Name
      Returns:
      current reference
    • getLocalDatacenter

      public String getLocalDatacenter()
      Getter accessor for attribute 'localDC'.
      Returns:
      current value of 'localDC'
    • setLocalDatacenter

      public void setLocalDatacenter(String localDc)
      Update local datacenter without the cqlOptions. To also update the options please use withLocalDatacenter.
      Parameters:
      localDc - current value of localDC
    • enableCql

      public StargateClientBuilder enableCql()
      By default Cqlsession is not created, you can enable the flag or using any withCql* operations to enableit.
      Returns:
      reference of current object
    • withCqlSession

      public StargateClientBuilder withCqlSession(com.datastax.oss.driver.api.core.CqlSession cql)
      Provide your own CqlSession skipping settings in the builder.
      Parameters:
      cql - existing session
      Returns:
      self reference
    • withCqlDriverConfigurationFile

      public StargateClientBuilder withCqlDriverConfigurationFile(File configFile)
      You want to initialize CqlSession with a configuration file
      Parameters:
      configFile - a configuration file
      Returns:
      the current reference
    • withCqlDriverConfigLoaderBuilder

      public StargateClientBuilder withCqlDriverConfigLoaderBuilder(com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder pdclb)
      Provide the proper programmatic config loader builder. It will be orverriden when used with Spring.
      Parameters:
      pdclb - builder
      Returns:
      current reference
    • withCqlOptionBoolean

      public StargateClientBuilder withCqlOptionBoolean(com.datastax.oss.driver.api.core.config.TypedDriverOption<Boolean> option, Boolean du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionBooleanDC

      public StargateClientBuilder withCqlOptionBooleanDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Boolean> option, Boolean du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionBooleanList

      public StargateClientBuilder withCqlOptionBooleanList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Boolean>> option, List<Boolean> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionBooleanListDC

      public StargateClientBuilder withCqlOptionBooleanListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Boolean>> option, List<Boolean> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClass

      public StargateClientBuilder withCqlOptionClass(com.datastax.oss.driver.api.core.config.TypedDriverOption<Class<?>> option, Class<?> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClassDC

      public StargateClientBuilder withCqlOptionClassDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Class<?>> option, Class<?> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClassList

      public StargateClientBuilder withCqlOptionClassList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Class<?>>> option, List<Class<?>> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClassListDC

      public StargateClientBuilder withCqlOptionClassListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Class<?>>> option, List<Class<?>> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDouble

      public StargateClientBuilder withCqlOptionDouble(com.datastax.oss.driver.api.core.config.TypedDriverOption<Double> option, Double du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDoubleDC

      public StargateClientBuilder withCqlOptionDoubleDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Double> option, Double du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDoubleList

      public StargateClientBuilder withCqlOptionDoubleList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Double>> option, List<Double> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDoubleListDC

      public StargateClientBuilder withCqlOptionDoubleListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Double>> option, List<Double> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDuration

      public StargateClientBuilder withCqlOptionDuration(com.datastax.oss.driver.api.core.config.TypedDriverOption<Duration> option, Duration du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDurationDC

      public StargateClientBuilder withCqlOptionDurationDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Duration> option, Duration du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDurationList

      public StargateClientBuilder withCqlOptionDurationList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Duration>> option, List<Duration> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDurationListDC

      public StargateClientBuilder withCqlOptionDurationListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Duration>> option, List<Duration> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionInteger

      public StargateClientBuilder withCqlOptionInteger(com.datastax.oss.driver.api.core.config.TypedDriverOption<Integer> option, Integer du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionIntegerDC

      public StargateClientBuilder withCqlOptionIntegerDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Integer> option, Integer du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionIntegerList

      public StargateClientBuilder withCqlOptionIntegerList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Integer>> option, List<Integer> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionIntegerListDC

      public StargateClientBuilder withCqlOptionIntegerListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Integer>> option, List<Integer> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLong

      public StargateClientBuilder withCqlOptionLong(com.datastax.oss.driver.api.core.config.TypedDriverOption<Long> option, Long du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLongDC

      public StargateClientBuilder withCqlOptionLongDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Long> option, Long du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLongList

      public StargateClientBuilder withCqlOptionLongList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Long>> option, List<Long> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLongListDC

      public StargateClientBuilder withCqlOptionLongListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Long>> option, List<Long> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionString

      public StargateClientBuilder withCqlOptionString(com.datastax.oss.driver.api.core.config.TypedDriverOption<String> option, String du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionStringDC

      public StargateClientBuilder withCqlOptionStringDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<String> option, String du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionStringList

      public StargateClientBuilder withCqlOptionStringList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<String>> option, List<String> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionStringListDC

      public StargateClientBuilder withCqlOptionStringListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<String>> option, List<String> du)
      Add a propery to the Cql Context.
      Parameters:
      dc - targate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlMetricsRegistry

      public StargateClientBuilder withCqlMetricsRegistry(Object registry)
      Metrics registry.
      Parameters:
      registry - target metrics registry
      Returns:
      client config
    • withCqlRequestTracker

      public StargateClientBuilder withCqlRequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker cqlReqTracker)
      CqlRequest Tracker registry.
      Parameters:
      cqlReqTracker - cql tracker
      Returns:
      client config
    • withCqlConsistencyLevel

      public StargateClientBuilder withCqlConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel cl)
      Set the consistency level
      Parameters:
      cl - current consitency level
      Returns:
      self reference
    • withCqlConsistencyLevelDC

      public StargateClientBuilder withCqlConsistencyLevelDC(String dc, com.datastax.oss.driver.api.core.ConsistencyLevel cl)
      Define consistency level for a DC.
      Parameters:
      dc - datacenter name
      cl - consistency level
      Returns:
      self reference
    • withCqlContactPoints

      public StargateClientBuilder withCqlContactPoints(String... contactPoints)
      Fill contact points.
      Parameters:
      contactPoints - contact points
      Returns:
      current reference
    • withCqlContactPointsDC

      public StargateClientBuilder withCqlContactPointsDC(String dc, String... contactPoints)
      Fill contact points.
      Parameters:
      dc - datacenter name
      contactPoints - contact points
      Returns:
      current reference
    • withCqlKeyspace

      public StargateClientBuilder withCqlKeyspace(String keyspace)
      Fill Keyspaces.
      Parameters:
      keyspace - keyspace name
      Returns:
      current reference
    • withCqlCloudSecureConnectBundle

      public StargateClientBuilder withCqlCloudSecureConnectBundle(String cloudConfigUrl)
      Providing SCB. (note it is one per Region).
      Parameters:
      cloudConfigUrl - configuration
      Returns:
      current reference
    • withCqlCloudSecureConnectBundleDC

      public StargateClientBuilder withCqlCloudSecureConnectBundleDC(String dc, String cloudConfigUrl)
      Providing SCB. (note it is one per Region).
      Parameters:
      dc - datacenter name
      cloudConfigUrl - configuration
      Returns:
      current reference
    • isEnabledCql

      public boolean isEnabledCql()
      Getter accessor for attribute 'disableCqlSession'.
      Returns:
      current value of 'disableCqlSession'
    • getCqlSession

      public com.datastax.oss.driver.api.core.CqlSession getCqlSession()
      Getter accessor for attribute 'cqlSession'.
      Returns:
      current value of 'cqlSession'
    • getCqlOptions

      public com.datastax.oss.driver.api.core.config.OptionsMap getCqlOptions()
      Getter accessor for attribute 'cqloptions'.
      Returns:
      value for cql option
    • getCqlRequestTracker

      public com.datastax.oss.driver.api.core.tracker.RequestTracker getCqlRequestTracker()
      Getter accessor for attribute 'cqlRequestTracker'.
      Returns:
      current value of 'cqlRequestTracker'
    • getCqlDriverConfigLoaderBuilder

      public com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder getCqlDriverConfigLoaderBuilder()
      Accessor to driver config builder.
      Returns:
      driver config builder
    • getCqlMetricsRegistry

      public Object getCqlMetricsRegistry()
      Getter accessor for attribute 'metricsRegistry'.
      Returns:
      current value of 'metricsRegistry'
    • enableGrpc

      public StargateClientBuilder enableGrpc()
      By default Cqlsession is not created, you can enable the flag or using any withCql* operations to enableit.
      Returns:
      reference of current object
    • isEnabledGrpc

      public boolean isEnabledGrpc()
      Getter accessor for attribute 'disableCqlSession'.
      Returns:
      current value of 'disableCqlSession'
    • withHttpRequestConfig

      public StargateClientBuilder withHttpRequestConfig(org.apache.hc.client5.http.config.RequestConfig reqConfig)
      Enable fine Grained configuration of the HTTP Client.
      Parameters:
      reqConfig - request configuration
      Returns:
      self reference
    • withHttpRetryConfig

      public StargateClientBuilder withHttpRetryConfig(com.evanlennick.retry4j.config.RetryConfig retryConfig)
      Enable fine Grained configuration of the HTTP Retries.
      Parameters:
      retryConfig - request configuration
      Returns:
      self reference
    • addHttpObserver

      public StargateClientBuilder addHttpObserver(String name, io.stargate.sdk.audit.ServiceCallObserver observer)
      Api Invocations trigger some events processed in observer.
      Parameters:
      name - unique identiier
      observer - instance of your Observer
      Returns:
      self reference
    • withHttpObservers

      public StargateClientBuilder withHttpObservers(Map<String,io.stargate.sdk.audit.ServiceCallObserver> observers)
      Api Invocations trigger some events processed in observer.
      Parameters:
      observers - instance of your Observer
      Returns:
      self reference
    • getRetryConfig

      public com.evanlennick.retry4j.config.RetryConfig getRetryConfig()
      Getter accessor for attribute 'retryConfig'.
      Returns:
      current value of 'retryConfig'
    • getRequestConfig

      public org.apache.hc.client5.http.config.RequestConfig getRequestConfig()
      Getter accessor for attribute 'requestConfig'.
      Returns:
      current value of 'requestConfig'
    • getObservers

      public Map<String,io.stargate.sdk.audit.ServiceCallObserver> getObservers()
      Getter accessor for attribute 'observers'.
      Returns:
      current value of 'observers'
    • build

      public StargateClient build()
      Building a StargateClient from the values in the BUILDER
      Returns:
      instance of the client