Skip to content

Instantly share code, notes, and snippets.

@krukow
Created January 1, 2010 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krukow/267168 to your computer and use it in GitHub Desktop.
Save krukow/267168 to your computer and use it in GitHub Desktop.
(ns net.higher-order.integration.circuit-breaker.states)
(deftype TransitionPolicy [fail-count timeout])
(defprotocol CircuitBreakerTransitions
"Transition functions for circuit-breaker states"
(proceed [s] "true if breaker should proceed with call in this state")
(on-success [s] "transition from s to this state after a successful call")
(on-error [s] "transition from s to this state after an unsuccessful call")
(on-before-call [s] "transition from s to this state before a call"))
(deftype ClosedState [policy fail-count] clojure.lang.IPersistentMap)
(deftype OpenState [policy time-stamp] clojure.lang.IPersistentMap)
(deftype InitialHalfOpenState [policy] clojure.lang.IPersistentMap)
(deftype PendingHalfOpenState [policy] clojure.lang.IPersistentMap)
(def #^{:private true}
abs-transitions
{:proceed (constantly false)
:on-success identity
:on-error identity
:on-before-call identity})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment