Package com.shri.restinpeace
Class RipClientConfig.Builder
java.lang.Object
com.shri.restinpeace.RipClientConfig.Builder
- Enclosing class:
- RipClientConfig
Builds a
RipClientConfig.-
Method Summary
Modifier and TypeMethodDescriptionSets the runtime base URL.build()Builds the config.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.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-inBulkheadConfig-drivenSemaphore.Sets theCachefor this client, overriding the shared default set viaRIP.setCache(Cache)for this client only.cacheKeyIncludesQueryString(boolean cacheKeyIncludesQueryString) Sets whether this client's cache key includes the request's query string, overriding the shared default set viaRIP.setCacheKeyIncludesQueryString(boolean)(itselftrueby default, matching RIP's own established behavior) for this client only.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.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-inCircuitBreakerConfig-driven state machine.connectTimeoutMillis(int connectTimeoutMillis) Sets the connect timeout.interceptors(List<RequestInterceptor> interceptors) Sets this client's own interceptors, run in addition to (not instead of) every globally registeredinterceptor- for a concern specific to this one client (e.g. this service's own auth scheme) instead of every call RIP ever makes.negativeCacheTtlMillis(long ttlMillis) Opts this client into negatively caching a confirmed404, overriding the shared default set viaRIP.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, forttlMillis- regardless of whether the404response itself carries anyCache-Control/ETag/Last-Modifiedat all (unlike every other cached status, which is only ever stored when the server's own headers say so).objectMapper(kong.unirest.ObjectMapper objectMapper) Sets the JSONObjectMapperfor this client.Sets an unauthenticated proxy.Sets an authenticated proxy.readTimeoutMillis(int readTimeoutMillis) Sets the read (socket) timeout.retry(RetryConfig retry) Sets this client's default retry policy - applied to a call whose method (and interface) has no@Retryof its own, which always wins over this when present.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'sretry(RetryConfig)default).
-
Method Details
-
baseUrl
Sets the runtime base URL.- Parameters:
baseUrl- the runtime base URL to resolve relative method URLs against- Returns:
- this builder
-
connectTimeoutMillis
Sets the connect timeout.- Parameters:
connectTimeoutMillis- the connect timeout in milliseconds; must not be negative- Returns:
- this builder
-
readTimeoutMillis
Sets the read (socket) timeout.- Parameters:
readTimeoutMillis- the read (socket) timeout in milliseconds; must not be negative- Returns:
- this builder
-
proxy
Sets an unauthenticated proxy.- Parameters:
host- the proxy hostport- the proxy port- Returns:
- this builder
-
proxy
Sets an authenticated proxy.- Parameters:
host- the proxy hostport- the proxy portusername- the proxy usernamepassword- the proxy password- Returns:
- this builder
-
objectMapper
Sets the JSONObjectMapperfor this client.- Parameters:
objectMapper- the JSONObjectMapperfor this client- Returns:
- this builder
-
cache
Sets theCachefor this client, overriding the shared default set viaRIP.setCache(Cache)for this client only. OnlyGETresponses are ever cached, and only when the response itself carries aCache-Control max-age, anETag, or aLast-Modifiedto honor.- Parameters:
cache- the cache to use for this client- Returns:
- this builder
-
cacheKeyIncludesQueryString
Sets whether this client's cache key includes the request's query string, overriding the shared default set viaRIP.setCacheKeyIncludesQueryString(boolean)(itselftrueby 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 aCacheconfigured (its own viacache(Cache), or the shared default).- Parameters:
cacheKeyIncludesQueryString- whether this client's cache key includes the query string- Returns:
- this builder
-
negativeCacheTtlMillis
Opts this client into negatively caching a confirmed404, overriding the shared default set viaRIP.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, forttlMillis- regardless of whether the404response itself carries anyCache-Control/ETag/Last-Modifiedat 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 aCacheconfigured (its own viacache(Cache), or the shared default), and is skipped the same way by@NoCache.- Parameters:
ttlMillis- how long a confirmed404stays negatively cached, in milliseconds; must be positive- Returns:
- this builder
-
retryBudget
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'sretry(RetryConfig)default). Addresses a retry storm amplifying an outage: many concurrently failing calls each retrying up to their owntimes()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 atmaxRetries, and regainingmaxRetries / windowMillistokens per elapsed millisecond, capped atmaxRetries. 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 owntimes()- no different from an ordinary give-up. Not called at all (the default) means no cap beyond each call's owntimes(), byte-for-byte today's behavior.- Parameters:
maxRetries- the bucket's capacity - the maximum number of retries available at once; must be positivewindowMillis- how long a fully-drained bucket takes to refill back tomaxRetries, in milliseconds; must be positive- Returns:
- this builder
-
interceptors
Sets this client's own interceptors, run in addition to (not instead of) every globally registeredinterceptor- 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 inbeforeRequest(bracketing everything, including this client's own) and last inafterResponse, the same "onion" orderingRequestInterceptor's own javadoc describes for interceptors registered globally.- Parameters:
interceptors- this client's own interceptors- Returns:
- this builder
-
retry
Sets this client's default retry policy - applied to a call whose method (and interface) has no@Retryof its own, which always wins over this when present. SeeRetryConfig.- Parameters:
retry- this client's default retry policy, ornullfor no retrying at all in that case- Returns:
- this builder
-
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. SeeCircuitBreakerConfig's own javadoc (anddocs/design/circuit-breaker-bulkhead.md) for the full state machine and every default.- Parameters:
circuitBreaker- this client's circuit breaker config, ornullfor no circuit breaker at all (the default)- Returns:
- this builder
-
circuitBreaker
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-inCircuitBreakerConfig-driven state machine. SeeCircuitBreakerProvider's own javadoc for the full reasoning and a worked example. Overrides any earliercircuitBreaker(CircuitBreakerConfig)call, the same "last call wins" shapeCircuitBreakerConfig.Builder's own overloadedslidingWindowSizesetters already use.- Parameters:
circuitBreakerProvider- this client's external circuit breaker provider, ornullfor no circuit breaker at all (the default)- Returns:
- this builder
-
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. SeeBulkheadConfig's own javadoc (anddocs/design/circuit-breaker-bulkhead.md) for the full reasoning and every default.- Parameters:
bulkhead- this client's bulkhead config, ornullfor no concurrency cap at all (the default)- Returns:
- this builder
-
bulkhead
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-inBulkheadConfig-drivenSemaphore. SeeBulkheadProvider's own javadoc for the full reasoning and a worked example. Overrides any earlierbulkhead(BulkheadConfig)call, the same "last call wins" shape this config'scircuitBreaker(CircuitBreakerProvider)overload also uses.- Parameters:
bulkheadProvider- this client's external bulkhead provider, ornullfor no concurrency cap at all (the default)- Returns:
- this builder
-
build
Builds the config.- Returns:
- the built config
-