Class RipClientConfig.Builder

java.lang.Object
com.shri.restinpeace.RipClientConfig.Builder
Enclosing class:
RipClientConfig

public static final class RipClientConfig.Builder extends Object
Builds a RipClientConfig.
  • Method Details

    • baseUrl

      public RipClientConfig.Builder baseUrl(String baseUrl)
      Sets the runtime base URL.
      Parameters:
      baseUrl - the runtime base URL to resolve relative method URLs against
      Returns:
      this builder
    • connectTimeoutMillis

      public RipClientConfig.Builder connectTimeoutMillis(int connectTimeoutMillis)
      Sets the connect timeout.
      Parameters:
      connectTimeoutMillis - the connect timeout in milliseconds; must not be negative
      Returns:
      this builder
    • readTimeoutMillis

      public RipClientConfig.Builder readTimeoutMillis(int readTimeoutMillis)
      Sets the read (socket) timeout.
      Parameters:
      readTimeoutMillis - the read (socket) timeout in milliseconds; must not be negative
      Returns:
      this builder
    • proxy

      public RipClientConfig.Builder proxy(String host, int port)
      Sets an unauthenticated proxy.
      Parameters:
      host - the proxy host
      port - the proxy port
      Returns:
      this builder
    • proxy

      public RipClientConfig.Builder proxy(String host, int port, String username, String password)
      Sets an authenticated proxy.
      Parameters:
      host - the proxy host
      port - the proxy port
      username - the proxy username
      password - the proxy password
      Returns:
      this builder
    • objectMapper

      public RipClientConfig.Builder objectMapper(kong.unirest.ObjectMapper objectMapper)
      Sets the JSON ObjectMapper for this client.
      Parameters:
      objectMapper - the JSON ObjectMapper for this client
      Returns:
      this builder
    • cache

      public RipClientConfig.Builder cache(Cache cache)
      Sets the Cache for this client, overriding the shared default set via RIP.setCache(Cache) for this client only. Only GET responses are ever cached, and only when the response itself carries a Cache-Control max-age, an ETag, or a Last-Modified to honor.
      Parameters:
      cache - the cache to use for this client
      Returns:
      this builder
    • cacheKeyIncludesQueryString

      public RipClientConfig.Builder cacheKeyIncludesQueryString(boolean cacheKeyIncludesQueryString)
      Sets whether this client's cache key includes the request's query string, overriding the shared default set via RIP.setCacheKeyIncludesQueryString(boolean) (itself true by default, matching RIP's own established behavior) for this client only. Turn this off for an endpoint whose query params don't affect the response (e.g. an analytics/tracking param), so every query-string variant of the same path shares one cache entry instead of each getting its own - trading precision for a higher hit rate. Has no effect unless this client also has a Cache configured (its own via cache(Cache), or the shared default).
      Parameters:
      cacheKeyIncludesQueryString - whether this client's cache key includes the query string
      Returns:
      this builder
    • negativeCacheTtlMillis

      public RipClientConfig.Builder negativeCacheTtlMillis(long ttlMillis)
      Opts this client into negatively caching a confirmed 404, overriding the shared default set via RIP.setNegativeCacheTtlMillis(long) for this client only - so a client that already asked once for a resource that doesn't exist stops hammering the downstream asking again, for ttlMillis - regardless of whether the 404 response itself carries any Cache-Control/ETag/ Last-Modified at all (unlike every other cached status, which is only ever stored when the server's own headers say so). Has no effect unless this client also has a Cache configured (its own via cache(Cache), or the shared default), and is skipped the same way by @NoCache.
      Parameters:
      ttlMillis - how long a confirmed 404 stays negatively cached, in milliseconds; must be positive
      Returns:
      this builder
    • retryBudget

      public RipClientConfig.Builder retryBudget(int maxRetries, long windowMillis)
      Caps the *total* number of retries this client performs across every call within a rolling window - not a per-call limit, which is still each call's own @Retry#times() (or this config's retry(RetryConfig) default). Addresses a retry storm amplifying an outage: many concurrently failing calls each retrying up to their own times() independently can multiply an already-struggling downstream's request volume, where a shared budget caps the aggregate instead. Tokens refill continuously (a token-bucket, not a fixed window that resets in one burst): starting full at maxRetries, and regaining maxRetries / windowMillis tokens per elapsed millisecond, capped at maxRetries. Once the budget is exhausted, a call that would otherwise retry instead returns (or throws) its current outcome immediately, exactly as if it had reached its own times() - no different from an ordinary give-up. Not called at all (the default) means no cap beyond each call's own times(), byte-for-byte today's behavior.
      Parameters:
      maxRetries - the bucket's capacity - the maximum number of retries available at once; must be positive
      windowMillis - how long a fully-drained bucket takes to refill back to maxRetries, in milliseconds; must be positive
      Returns:
      this builder
    • interceptors

      public RipClientConfig.Builder interceptors(List<RequestInterceptor> interceptors)
      Sets this client's own interceptors, run in addition to (not instead of) every globally registered interceptor - for a concern specific to this one client (e.g. this service's own auth scheme) instead of every call RIP ever makes. Global interceptors run first in beforeRequest (bracketing everything, including this client's own) and last in afterResponse, the same "onion" ordering RequestInterceptor's own javadoc describes for interceptors registered globally.
      Parameters:
      interceptors - this client's own interceptors
      Returns:
      this builder
    • retry

      public RipClientConfig.Builder retry(RetryConfig retry)
      Sets this client's default retry policy - applied to a call whose method (and interface) has no @Retry of its own, which always wins over this when present. See RetryConfig.
      Parameters:
      retry - this client's default retry policy, or null for no retrying at all in that case
      Returns:
      this builder
    • circuitBreaker

      public RipClientConfig.Builder circuitBreaker(CircuitBreakerConfig circuitBreaker)
      Sets this client's circuit breaker - stops even attempting calls to this client once its failure rate crosses a threshold, for a cooldown period, instead of paying the cost of finding out each one would have failed too. See CircuitBreakerConfig's own javadoc (and docs/design/circuit-breaker-bulkhead.md) for the full state machine and every default.
      Parameters:
      circuitBreaker - this client's circuit breaker config, or null for no circuit breaker at all (the default)
      Returns:
      this builder
    • circuitBreaker

      public RipClientConfig.Builder circuitBreaker(CircuitBreakerProvider circuitBreakerProvider)
      Sets this client's circuit breaker to delegate its open/closed decision to an already-running external breaker instance (resilience4j or otherwise) instead of RIP's own built-in CircuitBreakerConfig-driven state machine. See CircuitBreakerProvider's own javadoc for the full reasoning and a worked example. Overrides any earlier circuitBreaker(CircuitBreakerConfig) call, the same "last call wins" shape CircuitBreakerConfig.Builder's own overloaded slidingWindowSize setters already use.
      Parameters:
      circuitBreakerProvider - this client's external circuit breaker provider, or null for no circuit breaker at all (the default)
      Returns:
      this builder
    • bulkhead

      public RipClientConfig.Builder bulkhead(BulkheadConfig bulkhead)
      Sets this client's bulkhead - caps how many calls to this client can be in flight at once, so one slow or hung downstream can't starve every other call sharing the same connection pool/thread capacity. See BulkheadConfig's own javadoc (and docs/design/circuit-breaker-bulkhead.md) for the full reasoning and every default.
      Parameters:
      bulkhead - this client's bulkhead config, or null for no concurrency cap at all (the default)
      Returns:
      this builder
    • bulkhead

      public RipClientConfig.Builder bulkhead(BulkheadProvider bulkheadProvider)
      Sets this client's bulkhead to delegate its admission decision to an already-running external bulkhead instance (resilience4j or otherwise) instead of RIP's own built-in BulkheadConfig-driven Semaphore. See BulkheadProvider's own javadoc for the full reasoning and a worked example. Overrides any earlier bulkhead(BulkheadConfig) call, the same "last call wins" shape this config's circuitBreaker(CircuitBreakerProvider) overload also uses.
      Parameters:
      bulkheadProvider - this client's external bulkhead provider, or null for no concurrency cap at all (the default)
      Returns:
      this builder
    • build

      public RipClientConfig build()
      Builds the config.
      Returns:
      the built config