Liking cljdoc? Tell your friends :D

preflex.resilient

Resilience abstractions with backpressure:

  • Bounded thread pool - (compared to unbounded thread pool) helps keep computation and memory consumption in check
  • Circuit breaker - cuts off execution when a resource is unavailable, and resumes when it is available again
  • Semaphore - limits total number of clients competing for resources
  • Fallback - When primary computation fails, fall back to standby
Resilience abstractions with backpressure:
* Bounded thread pool - (compared to unbounded thread pool) helps keep computation and memory consumption in check
* Circuit breaker     - cuts off execution when a resource is unavailable, and resumes when it is available again
* Semaphore           - limits total number of clients competing for resources
* Fallback            - When primary computation fails, fall back to standby
raw docstring

future-call-viaclj

(future-call-via thread-pool f)
(future-call-via thread-pool
                 {:keys [context-maker on-task-submit on-task-reject
                         on-task-error on-task-timeout]
                  :or {context-maker im/make-context
                       on-task-submit in/nop
                       on-task-reject (fn [_ _] (e/thread-pool-rejected))
                       on-task-error (fn [_ e] (e/exception-occurred e))
                       on-task-timeout (fn [_ _] (e/operation-timed-out))}}
                 f)

Same as clojure.core/future-call, but for a specified thread pool with instrumentation. Options: :context-maker (fn [thread-pool]) - creates context to be passed as first arg to other listeners :on-task-submit (fn [context]) - called when task submission succeeds on the thread pool :on-task-reject (fn [context ex]) - called when task submission is rejected on the thread pool :on-task-error (fn [context ex]) - called when the future object cannot be derefed successfully :on-task-timeout (fn [context ex]) - called when the future object cannot be derefed in specified time

Same as `clojure.core/future-call`, but for a specified thread pool with instrumentation.
Options:
  :context-maker   (fn [thread-pool]) - creates context to be passed as first arg to other listeners
  :on-task-submit  (fn [context])     - called when task submission succeeds on the thread pool
  :on-task-reject  (fn [context ex])  - called when task submission is rejected on the thread pool
  :on-task-error   (fn [context ex])  - called when the future object cannot be derefed successfully
  :on-task-timeout (fn [context ex])  - called when the future object cannot be derefed in specified time
sourceraw docstring

make-binary-semaphoreclj

(make-binary-semaphore)
(make-binary-semaphore {semaphore-name :name
                        semaphore-fair? :fair?
                        :or {semaphore-name (gensym "counting-semaphore-")
                             semaphore-fair? false}})

Given max permits count, create and return a binary semaphore. Options: :name (any type) semaphore name, coerced as string :fair? (boolean) whether semaphore should use fair acquisition

Given max permits count, create and return a binary semaphore.
Options:
  :name  (any type) semaphore name, coerced as string
  :fair? (boolean)  whether semaphore should use fair acquisition
sourceraw docstring

make-bounded-thread-poolclj

(make-bounded-thread-pool max-thread-count queue-capacity)
(make-bounded-thread-pool max-thread-count
                          queue-capacity
                          {thread-pool-name :name
                           :keys [keep-alive-duration core-thread-count
                                  core-thread-timeout?]
                           :or {thread-pool-name (gensym "bounded-thread-pool-")
                                keep-alive-duration [10000 :millis]
                                core-thread-count max-thread-count
                                core-thread-timeout? true}
                           :as options})

Given max thread-count, work queue-size and options, create and return a bounded thread pool. Options: :name (any type) thread-pool name, coerced as string :keep-alive-duration (Duration) timeout for idle threads after which they may be terminated :core-thread-count (int) core thread count :core-thread-timeout? (boolean) whether idle core threads should be terminated after timeout

Given max thread-count, work queue-size and options, create and return a bounded thread pool.
Options:
  :name                 (any type) thread-pool name, coerced as string
  :keep-alive-duration  (Duration) timeout for idle threads after which they may be terminated
  :core-thread-count    (int)      core thread count
  :core-thread-timeout? (boolean)  whether idle core threads should be terminated after timeout
sourceraw docstring

make-circuit-breakerclj

(make-circuit-breaker fault-detector retry-resolver)
(make-circuit-breaker fault-detector
                      retry-resolver
                      {circuit-breaker-name :name
                       :keys [fair? on-trip on-connect]
                       :or {circuit-breaker-name (gensym "circuit-breaker-")
                            fair? false
                            on-trip in/nop
                            on-connect in/nop}
                       :as options})

Create a circuit breaker that is based on the following principles:

  • Circuit breaker can only be in either connected (C) or tripped (T) state.
  • Tripping happens based on fault-detector (preflex.type.IFaultDetector/fault?)
  • In tripped state, circuit breaker allows operation based on retry-resolver to see if the system has recovered.
  • A caller may invoke (preflex.type.ICircuitBreaker/mark!) informing about the status of an operation. Success sets circuit-breaker into connected state, whereas failure may set circuit breaker into tripped state. Options: :name (any type) circuit-breaker name, coerced as string :fair? (boolean) whether state-transition should be fair across threads :on-trip (fn [impl]) called when circuit breaker switches from connected to tripped state :on-connect (fn [impl]) called when circuit breaker switches from tripped to connected state
Create a circuit breaker that is based on the following principles:
* Circuit breaker can only be in either connected (C) or tripped (T) state.
* Tripping happens based on fault-detector (preflex.type.IFaultDetector/fault?)
* In tripped state, circuit breaker allows operation based on retry-resolver to see if the system has recovered.
* A caller may invoke (preflex.type.ICircuitBreaker/mark!) informing about the status of an operation. Success
  sets circuit-breaker into connected state, whereas failure may set circuit breaker into tripped state.
Options:
  :name       (any type)  circuit-breaker name, coerced as string
  :fair?      (boolean)   whether state-transition should be fair across threads
  :on-trip    (fn [impl]) called when circuit breaker switches from connected to tripped state
  :on-connect (fn [impl]) called when circuit breaker switches from tripped to connected state
sourceraw docstring

make-counting-semaphoreclj

(make-counting-semaphore max-permits)
(make-counting-semaphore max-permits
                         {semaphore-name :name
                          semaphore-fair? :fair?
                          :or {semaphore-name (gensym "counting-semaphore-")
                               semaphore-fair? false}})

Given max permits count, create and return a counting semaphore. Options: :name (any type) semaphore name, coerced as string :fair? (boolean) whether semaphore should use fair acquisition

Given max permits count, create and return a counting semaphore.
Options:
  :name  (any type) semaphore name, coerced as string
  :fair? (boolean)  whether semaphore should use fair acquisition
sourceraw docstring

make-discrete-fault-detectorclj

(make-discrete-fault-detector connected-until-errcount connected-until-duration)
(make-discrete-fault-detector connected-until-errcount
                              connected-until-duration
                              {:keys [now-millis-finder]
                               :or {now-millis-finder u/now-millis}})

Create a fault detector based on threshold specified as connected-until-errcount errors in connected-until-duration (converted to millis) time. This follows the X errors in Y discrete duration measurement.

Create a fault detector based on threshold specified as connected-until-errcount errors in connected-until-duration
(converted to millis) time. This follows the X errors in Y discrete duration measurement.
sourceraw docstring

make-half-open-retry-resolverclj

(make-half-open-retry-resolver half-open-duration)
(make-half-open-retry-resolver half-open-duration
                               {:keys [now-millis-finder open-duration
                                       retry-times]
                                :or {now-millis-finder u/now-millis
                                     open-duration half-open-duration
                                     retry-times 1}
                                :as options})

Make a retry-resolver that allows specified number of retries per every half-open window. Retries happen consecutively at the beginning of every half-open window. An 'open' window precedes all half-open windows. Durations are converted to millis for time calculation. Options: :now-millis-finder (fn []) -> long function that returns current time in millis :open-duration (duration, default: half-open-duration) 'open' period preceding the half-open periods :retry-times (int, default: 1) max number of times to retry in every half-open window

Make a retry-resolver that allows specified number of retries per every half-open window. Retries happen
consecutively at the beginning of every half-open window. An 'open' window precedes all half-open windows.
Durations are converted to millis for time calculation.
Options:
  :now-millis-finder (fn []) -> long  function that returns current time in millis
  :open-duration (duration, default: half-open-duration) 'open' period preceding the half-open periods
  :retry-times   (int, default: 1) max number of times to retry in every half-open window
sourceraw docstring

make-rolling-fault-detectorclj

(make-rolling-fault-detector connected-until-errcount connected-until-duration)
(make-rolling-fault-detector
  connected-until-errcount
  connected-until-duration
  {:keys [bucket-interval] :or {bucket-interval [1000 :millis]} :as options})

Create a protocols-instance that detects faults based on threshold specified as connected-until-errcount errors in connected-until-duration (converted to millis) time. This follows the X errors in Y duration measurement. See also: preflex.metrics/make-rolling-integer-counter

Create a protocols-instance that detects faults based on threshold specified as connected-until-errcount errors in
connected-until-duration (converted to millis) time. This follows the X errors in Y duration measurement.
See also: preflex.metrics/make-rolling-integer-counter
sourceraw docstring

make-serial-fault-detectorclj

(make-serial-fault-detector connected-until-errcount)

Create a protocols-instance that detects faults based on threshold specified as X consecutive errors.

Create a protocols-instance that detects faults based on threshold specified as X consecutive errors.
sourceraw docstring

via-circuit-breakerclj

(via-circuit-breaker circuit-breaker f)
(via-circuit-breaker circuit-breaker
                     {:keys [context-maker on-circuit-allow on-circuit-deny]
                      :or {context-maker im/make-context
                           on-circuit-allow in/nop
                           on-circuit-deny (fn [_] (e/circuit-breaker-open))}
                      :as options}
                     f)

Execute given task using specified circuit breaker. Options: :context-maker (fn []) - creates context to be passed as first arg to other listeners :on-circuit-allow (fn [context]) - does nothing by default :on-circuit-deny (fn [context]) - throws appropriate exception by default

Execute given task using specified circuit breaker.
Options:
  :context-maker    (fn [])        - creates context to be passed as first arg to other listeners
  :on-circuit-allow (fn [context]) - does nothing by default
  :on-circuit-deny  (fn [context]) - throws appropriate exception by default
sourceraw docstring

via-fallbackclj

(via-fallback fallback-fns f)
(via-fallback fallback-fns
              {:keys [context-maker pre-invoke post-result post-error]
               :or {context-maker im/make-context
                    pre-invoke in/nop
                    post-result in/nop
                    post-error in/nop}}
              f)

Given one or more tasks (each task is a no-arg fn/invokable) execute them serially such that the first successful result is returned. On failure invoke the next fn and so on. In the event of no success, return the last failure. Options: :context-maker (fn [tasks]) - creates context to be passed as first arg to other listeners :pre-invoke (fn [context f]) - called before every task invocation :post-result (fn [context f result]) - called when finally returning a result :post-error (fn [context f error]) - called when finally throwing an error

Given one or more tasks (each task is a no-arg fn/invokable) execute them serially such that the first successful
result is returned. On failure invoke the next fn and so on. In the event of no success, return the last failure.
Options:
  :context-maker (fn [tasks])            - creates context to be passed as first arg to other listeners
  :pre-invoke    (fn [context f])        - called before every task invocation
  :post-result   (fn [context f result]) - called when finally returning a result
  :post-error    (fn [context f error])  - called when finally throwing an error
sourceraw docstring

via-latency-trackerclj

(via-latency-tracker latency-tracker f)
(via-latency-tracker latency-tracker
                     {:keys [now-finder] :or {now-finder u/now-millis}}
                     f)

Execute given task using latency tracker, an arity-2 fn accepting success-status true/false and long-int latency. Options: :now-finder (fn []) fn returning stopwatch time now as long int

Execute given task using latency tracker, an arity-2 fn accepting success-status true/false and long-int latency.
Options:
  :now-finder  (fn []) fn returning stopwatch time now as long int
sourceraw docstring

via-semaphoreclj

(via-semaphore semaphore f)
(via-semaphore semaphore
               {:keys [context-maker on-semaphore-acquire on-semaphore-release
                       on-semaphore-reject]
                :or {context-maker im/make-context
                     on-semaphore-acquire in/nop
                     on-semaphore-release in/nop
                     on-semaphore-reject (fn [_] (e/semaphore-rejected))}
                :as options}
               f)

Execute given task (no-arg fn) using specified semaphore. Acquire a permit and execute task before finally releasing the permit. Handle events on-acquired, on-released, on-rejected using optional handlers. When no permit is available, throw appropriate exception by default. Options: :context-maker (fn [semaphore]) - creates context to be passed as first arg to other listeners :on-semaphore-acquire (fn [context]) - accepts context, does nothing by default :on-semaphore-release (fn [context]) - accepts context, does nothing by default :on-semaphore-reject (fn [context]) - accepts context, does nothing by default

Execute given task (no-arg fn) using specified semaphore. Acquire a permit and execute task before finally releasing
the permit. Handle events on-acquired, on-released, on-rejected using optional handlers. When no permit is available,
throw appropriate exception by default.
Options:
  :context-maker        (fn [semaphore]) - creates context to be passed as first arg to other listeners
  :on-semaphore-acquire (fn [context])   - accepts context, does nothing by default
  :on-semaphore-release (fn [context])   - accepts context, does nothing by default
  :on-semaphore-reject  (fn [context])   - accepts context, does nothing by default
sourceraw docstring

via-success-failure-trackerclj

(via-success-failure-tracker success-failure-tracker f)
(via-success-failure-tracker
  success-failure-tracker
  {:keys [context-maker post-result post-error]
   :or {context-maker im/make-context post-result in/nop post-error in/nop}}
  f)

Execute given task using specified tracker, an arity-1 fn that accepts true to indicate success and false to indicate failure. Options: :context-maker (fn [tracker]) called with success-failure-tracker as argument :post-result (fn [context result]) called with context and the result being returned as arguments :post-error (fn [context error]) called with context and the error being thrown as arguments

Execute given task using specified tracker, an arity-1 fn that accepts true to indicate success and false to
indicate failure.
Options:
  :context-maker (fn [tracker])        called with success-failure-tracker as argument
  :post-result   (fn [context result]) called with context and the result being returned as arguments
  :post-error    (fn [context error])  called with context and the error being thrown as arguments
sourceraw docstring

via-thread-poolclj

(via-thread-pool thread-pool f)
(via-thread-pool thread-pool
                 {:keys [context-maker on-task-submit on-task-reject
                         on-task-error on-task-timeout task-timeout]
                  :or {context-maker im/make-context
                       on-task-submit in/nop
                       on-task-reject (fn [_ _] (e/thread-pool-rejected))
                       on-task-error (fn [_ e] (e/exception-occurred e))
                       on-task-timeout (fn [_ _] (e/operation-timed-out))}
                  :as options}
                 f)

Execute given task (no-arg fn) asynchronously on specified thread pool and return result. Options: :context-maker (fn [thread-pool]) - creates context to be passed as first arg to other listeners :on-task-submit (fn [context]) - called when task submission succeeds on the thread pool :on-task-reject (fn [context ex]) - called when task submission is rejected on the thread pool :on-task-error (fn [context ex]) - called when the future object cannot be derefed successfully :on-task-timeout (fn [context ex]) - called when the future object cannot be derefed in specified time :task-timeout proto - timeout duration as preflex.type/IDuration instance e.g. [1000 :millis]

Execute given task (no-arg fn) asynchronously on specified thread pool and return result.
Options:
  :context-maker   (fn [thread-pool]) - creates context to be passed as first arg to other listeners
  :on-task-submit  (fn [context])     - called when task submission succeeds on the thread pool
  :on-task-reject  (fn [context ex])  - called when task submission is rejected on the thread pool
  :on-task-error   (fn [context ex])  - called when the future object cannot be derefed successfully
  :on-task-timeout (fn [context ex])  - called when the future object cannot be derefed in specified time
  :task-timeout    proto - timeout duration as preflex.type/IDuration instance e.g. [1000 :millis]
sourceraw docstring

with-circuit-breakerclj/smacro

(with-circuit-breaker circuit-breaker options & body)

Execute body of code using specified circuit breaker. See: preflex.core/via-circuit-breaker

Execute body of code using specified circuit breaker.
See: preflex.core/via-circuit-breaker
sourceraw docstring

with-fallbackclj/smacro

(with-fallback fallback-fns options & body)

Execute body of code using specified fallback functions. See: preflex.core/via-fallback

Execute body of code using specified fallback functions.
See: preflex.core/via-fallback
sourceraw docstring

with-latency-trackerclj/smacro

(with-latency-tracker latency-tracker options & body)

Execute body of code using latency tracker. See: preflex.core/via-latency-tracker

Execute body of code using latency tracker.
See: preflex.core/via-latency-tracker
sourceraw docstring

with-semaphoreclj/smacro

(with-semaphore semaphore options & body)

Execute given body of code using specified semaphore. See: preflex.core/via-semaphore

Execute given body of code using specified semaphore.
See: preflex.core/via-semaphore
sourceraw docstring

with-success-failure-trackerclj/smacro

(with-success-failure-tracker success-failure-tracker options & body)

Execute body of code using specified tracker. See: preflex.core/via-success-failure-tracker

Execute body of code using specified tracker.
See: preflex.core/via-success-failure-tracker
sourceraw docstring

with-thread-poolclj/smacro

(with-thread-pool thread-pool options & body)

Execute body of code asynchronously by submitting as a task to a thread-pool. See: preflex.core/via-thread-pool

Execute body of code asynchronously by submitting as a task to a thread-pool.
See: preflex.core/via-thread-pool
sourceraw docstring

wrap-circuit-breakerclj

(wrap-circuit-breaker circuit-breaker f)
(wrap-circuit-breaker circuit-breaker options f)

Wrap given fn with specified circuit breaker. See: preflex.core/via-circuit-breaker

Wrap given fn with specified circuit breaker.
See: preflex.core/via-circuit-breaker
sourceraw docstring

wrap-fallbackclj

(wrap-fallback fallback-fns f)
(wrap-fallback fallback-fns options f)

Wrap given fns (invokables) with fallback functions. See: preflex.core/via-fallback

Wrap given fns (invokables) with fallback functions.
See: preflex.core/via-fallback
sourceraw docstring

wrap-latency-trackerclj

(wrap-latency-tracker latency-tracker f)
(wrap-latency-tracker latency-tracker options f)

Wrap given fn (invokable) with latency tracker. See: preflex.core/via-latency-tracker

Wrap given fn (invokable) with latency tracker.
See: preflex.core/via-latency-tracker
sourceraw docstring

wrap-semaphoreclj

(wrap-semaphore semaphore f)
(wrap-semaphore semaphore options f)

Wrap given fn (invokable) using specified semaphore. See: preflex.core/via-semaphore

Wrap given fn (invokable) using specified semaphore.
See: preflex.core/via-semaphore
sourceraw docstring

wrap-success-failure-trackerclj

(wrap-success-failure-tracker success-failure-tracker f)
(wrap-success-failure-tracker success-failure-tracker options f)

Wrap given fn (invokable) with specified tracker. See: preflex.core/via-success-failure-tracker

Wrap given fn (invokable) with specified tracker.
See: preflex.core/via-success-failure-tracker
sourceraw docstring

wrap-thread-poolclj

(wrap-thread-pool thread-pool f)
(wrap-thread-pool thread-pool options f)

Wrap given fn with specified thread pool. See: preflex.core/via-thread-pool

Wrap given fn with specified thread pool.
See: preflex.core/via-thread-pool
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close