Package io.etcd.jetcd

Class ClientBuilder

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class ClientBuilder
    extends java.lang.Object
    implements java.lang.Cloneable
    ClientBuilder knows how to create an Client instance.
    • Method Detail

      • target

        public java.lang.String target()
        Gets the etcd target.
        Returns:
        the etcd target.
      • target

        public ClientBuilder target​(java.lang.String target)
        configure etcd server endpoints.
        Parameters:
        target - etcd server target
        Returns:
        this builder to train
        Throws:
        java.lang.NullPointerException - if target is null or one of endpoint is null
      • endpoints

        public ClientBuilder endpoints​(java.lang.String... endpoints)
        configure etcd server endpoints using the IPNameResolver.
        Parameters:
        endpoints - etcd server endpoints, at least one
        Returns:
        this builder to train
        Throws:
        java.lang.NullPointerException - if endpoints is null or one of endpoint is null
        java.lang.IllegalArgumentException - if some endpoint is invalid
      • endpoints

        public ClientBuilder endpoints​(java.net.URI... endpoints)
        configure etcd server endpoints using the IPNameResolver.
        Parameters:
        endpoints - etcd server endpoints, at least one
        Returns:
        this builder to train
        Throws:
        java.lang.NullPointerException - if endpoints is null or one of endpoint is null
        java.lang.IllegalArgumentException - if some endpoint is invalid
      • endpoints

        public ClientBuilder endpoints​(java.lang.Iterable<java.net.URI> endpoints)
        configure etcd server endpoints using the IPNameResolver.
        Parameters:
        endpoints - etcd server endpoints, at least one
        Returns:
        this builder to train
        Throws:
        java.lang.NullPointerException - if endpoints is null or one of endpoint is null
        java.lang.IllegalArgumentException - if some endpoint is invalid
      • user

        public ClientBuilder user​(ByteSequence user)
        config etcd auth user.
        Parameters:
        user - etcd auth user
        Returns:
        this builder
        Throws:
        java.lang.NullPointerException - if user is null
      • password

        public ByteSequence password()
        Returns the auth password
      • password

        public ClientBuilder password​(ByteSequence password)
        config etcd auth password.
        Parameters:
        password - etcd auth password
        Returns:
        this builder
        Throws:
        java.lang.NullPointerException - if password is null
      • namespace

        public ByteSequence namespace()
        Returns the namespace of each key used
      • namespace

        public ClientBuilder namespace​(ByteSequence namespace)
        config the namespace of keys used in KV, Txn, Lock and Watch. "/" will be treated as no namespace.
        Parameters:
        namespace - the namespace of each key used
        Returns:
        this builder
        Throws:
        java.lang.NullPointerException - if namespace is null
      • executorService

        public java.util.concurrent.ExecutorService executorService()
        Returns the executor service
      • executorService

        public ClientBuilder executorService​(java.util.concurrent.ExecutorService executorService)
        config executor service.
        Parameters:
        executorService - executor service
        Returns:
        this builder
        Throws:
        java.lang.NullPointerException - if executorService is null
      • loadBalancerPolicy

        public ClientBuilder loadBalancerPolicy​(java.lang.String loadBalancerPolicy)
        config load balancer policy.
        Parameters:
        loadBalancerPolicy - etcd load balancer policy
        Returns:
        this builder
        Throws:
        java.lang.NullPointerException - if loadBalancerPolicy is null
      • loadBalancerPolicy

        public java.lang.String loadBalancerPolicy()
        get the load balancer policy for etcd client.
        Returns:
        loadBalancerFactory
      • sslContext

        public io.netty.handler.ssl.SslContext sslContext()
        Returns the ssl context
      • sslContext

        public ClientBuilder sslContext​(io.netty.handler.ssl.SslContext sslContext)
        SSL/TLS context to use instead of the system default. It must have been configured with GrpcSslContexts, but options could have been overridden.
        Parameters:
        sslContext - the ssl context
        Returns:
        this builder
      • sslContext

        public ClientBuilder sslContext​(java.util.function.Consumer<io.netty.handler.ssl.SslContextBuilder> consumer)
                                 throws javax.net.ssl.SSLException
        Configure SSL/TLS context create through GrpcSslContexts.forClient() to use.
        Parameters:
        consumer - the SslContextBuilder consumer
        Returns:
        this builder
        Throws:
        javax.net.ssl.SSLException - if the SslContextBuilder fails
      • authority

        public java.lang.String authority()
        Returns The authority used to authenticate connections to servers.
      • authority

        public ClientBuilder authority​(java.lang.String authority)
        Sets the authority used to authenticate connections to servers.
        Parameters:
        authority - the authority used to authenticate connections to servers.
        Returns:
        this builder
      • maxInboundMessageSize

        public java.lang.Integer maxInboundMessageSize()
        Returns the maximum message size allowed for a single gRPC frame.
      • maxInboundMessageSize

        public ClientBuilder maxInboundMessageSize​(java.lang.Integer maxInboundMessageSize)
        Sets the maximum message size allowed for a single gRPC frame.
        Parameters:
        maxInboundMessageSize - the maximum message size allowed for a single gRPC frame.
        Returns:
        this builder
      • headers

        public java.util.Map<io.grpc.Metadata.Key<?>,​java.lang.Object> headers()
        Returns the headers to be added to http request headers
      • headers

        public ClientBuilder headers​(java.util.Map<io.grpc.Metadata.Key<?>,​java.lang.Object> headers)
        Sets headers to be added to http request headers.
        Parameters:
        headers - headers to be added to http request headers.
        Returns:
        this builder
      • header

        public ClientBuilder header​(java.lang.String key,
                                    java.lang.String value)
        Set headers.
        Parameters:
        key - Sets an header key to be added to http request headers.
        value - Sets an header value to be added to http request headers.
        Returns:
        this builder
      • authHeaders

        public java.util.Map<io.grpc.Metadata.Key<?>,​java.lang.Object> authHeaders()
        Returns the headers to be added to auth request headers
      • authHeaders

        public ClientBuilder authHeaders​(java.util.Map<io.grpc.Metadata.Key<?>,​java.lang.Object> authHeaders)
        Set the auth headers.
        Parameters:
        authHeaders - Sets headers to be added to auth request headers.
        Returns:
        this builder
      • authHeader

        public ClientBuilder authHeader​(java.lang.String key,
                                        java.lang.String value)
        Add an auth header.
        Parameters:
        key - Sets an header key to be added to auth request headers.
        value - Sets an header value to be added to auth request headers.
        Returns:
        this builder
      • interceptors

        public java.util.List<io.grpc.ClientInterceptor> interceptors()
        Returns the interceptors
      • interceptors

        public ClientBuilder interceptors​(java.util.List<io.grpc.ClientInterceptor> interceptors)
        Set the interceptors.
        Parameters:
        interceptors - the interceptors.
        Returns:
        this builder
      • interceptor

        public ClientBuilder interceptor​(io.grpc.ClientInterceptor interceptor,
                                         io.grpc.ClientInterceptor... interceptors)
        Add an interceptor.
        Parameters:
        interceptor - an interceptors to add
        interceptors - additional interceptors
        Returns:
        this builder
      • authInterceptors

        public java.util.List<io.grpc.ClientInterceptor> authInterceptors()
        Returns the auth interceptors
      • authInterceptors

        public ClientBuilder authInterceptors​(java.util.List<io.grpc.ClientInterceptor> interceptors)
        Set the auth interceptors.
        Parameters:
        interceptors - Set the interceptors to add to the auth chain
        Returns:
        this builder
      • authInterceptors

        public ClientBuilder authInterceptors​(io.grpc.ClientInterceptor interceptor,
                                              io.grpc.ClientInterceptor... interceptors)
        Add an auth interceptor.
        Parameters:
        interceptor - an interceptors to add to the auth chain
        interceptors - additional interceptors to add to the auth chain
        Returns:
        this builder
      • retryDelay

        public long retryDelay()
        Returns The delay between retries.
      • retryDelay

        public ClientBuilder retryDelay​(long retryDelay)
        The delay between retries.
        Parameters:
        retryDelay - The delay between retries.
        Returns:
        this builder
      • retryMaxDelay

        public long retryMaxDelay()
        Returns the max backing off delay between retries
      • retryMaxDelay

        public ClientBuilder retryMaxDelay​(long retryMaxDelay)
        Set the max backing off delay between retries.
        Parameters:
        retryMaxDelay - The max backing off delay between retries.
        Returns:
        this builder
      • keepaliveTime

        public java.time.Duration keepaliveTime()
      • keepaliveTime

        public ClientBuilder keepaliveTime​(java.time.Duration keepaliveTime)
        The interval for gRPC keepalives. The current minimum allowed by gRPC is 10s
        Parameters:
        keepaliveTime - time between keepalives
        Returns:
        this builder
      • keepaliveTimeout

        public java.time.Duration keepaliveTimeout()
      • keepaliveTimeout

        public ClientBuilder keepaliveTimeout​(java.time.Duration keepaliveTimeout)
        The timeout for gRPC keepalives
        Parameters:
        keepaliveTimeout - the gRPC keep alive timeout.
        Returns:
        this builder
      • keepaliveWithoutCalls

        public java.lang.Boolean keepaliveWithoutCalls()
      • keepaliveWithoutCalls

        public ClientBuilder keepaliveWithoutCalls​(java.lang.Boolean keepaliveWithoutCalls)
        Keepalive option for gRPC
        Parameters:
        keepaliveWithoutCalls - the gRPC keep alive without calls.
        Returns:
        this builder
      • retryChronoUnit

        public java.time.temporal.ChronoUnit retryChronoUnit()
        Returns he retries period unit.
      • retryChronoUnit

        public ClientBuilder retryChronoUnit​(java.time.temporal.ChronoUnit retryChronoUnit)
        Sets the retries period unit.
        Parameters:
        retryChronoUnit - the retries period unit.
        Returns:
        this builder
      • retryMaxDuration

        public java.time.Duration retryMaxDuration()
        Returns the retries max duration.
      • connectTimeout

        public java.time.Duration connectTimeout()
        Returns the connect timeout.
      • retryMaxDuration

        public ClientBuilder retryMaxDuration​(java.time.Duration retryMaxDuration)
        Set the retries max duration.
        Parameters:
        retryMaxDuration - the retries max duration.
        Returns:
        this builder
      • connectTimeout

        public ClientBuilder connectTimeout​(java.time.Duration connectTimeout)
        Set the connection timeout.
        Parameters:
        connectTimeout - Sets the connection timeout. Clients connecting to fault tolerant etcd clusters (eg, clusters with more than 2 etcd server peers/endpoints) should consider a value that will allow switching timely from a crashed/partitioned peer to a consensus peer.
        Returns:
        this builder
      • waitForReady

        public boolean waitForReady()
        Enable gRPC's wait for ready semantics.
        Returns:
        if this client uses gRPC's wait for ready semantics.
        See Also:
        gRPC Wait for Ready Semantics
      • waitForReady

        public ClientBuilder waitForReady​(boolean waitForReady)
        Configure the gRPC's wait for ready semantics.
        Parameters:
        waitForReady - if this client should use gRPC's wait for ready semantics. Enabled by default.
        Returns:
        this builder.
        See Also:
        gRPC Wait for Ready Semantics
      • build

        public Client build()
        build a new Client.
        Returns:
        Client instance.
        Throws:
        io.etcd.jetcd.common.exception.EtcdException - if client experiences build error.
      • copy

        public ClientBuilder copy()
        Returns a copy of this builder