This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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")) | |
(def #^{:private true | |
:doc "Default shared transition functions"} | |
def-transitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrecord TransitionPolicy [#^int max-fails #^long timeout]) | |
(defrecord ClosedState [#^TransitionPolicy policy #^int fail-count]) | |
(defrecord OpenState [#^TransitionPolicy policy #^long time-stamp]) | |
(defrecord InitialHalfOpenState [#^TransitionPolicy policy]) | |
(defrecord PendingHalfOpenState [#^TransitionPolicy policy]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(extend ClosedState CircuitBreakerTransitions | |
(merge | |
def-transitions | |
{:proceed (constantly true) | |
:on-success | |
(fn [{f :fail-count p :policy, :as s}] | |
(if (zero? f) s (ClosedState. p 0))) | |
:on-error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def default-policy (TransitionPolicy. 5 5000)) | |
(def initial-state (ClosedState. default-policy 0)) | |
(assert (= initial-state (on-success initial-state))) | |
(assert (= (ClosedState. default-policy 1) (on-error initial-state))) | |
(def e4 (ClosedState. default-policy 4)) | |
(assert (= OpenState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def default-policy (TransitionPolicy. 5 5000)) | |
(def initial-state (ClosedState. default-policy 0)) | |
(defn make-circuit-breaker | |
"Creates a circuit-breaker instance. If called with no arguments | |
a circuit-breaker in the initial closed state with the default policy is | |
created. If called with one argument supporting the CircuitBreakerTransitions | |
protocol, a circuit-breaker is created using that as state." | |
([] (atom initial-state)) | |
([#^CircuitBreakerTransitions s] (atom s))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def cb (make-circuit-breaker)) | |
(def succ (wrap-with (constantly 42) cb)) | |
(def fail (wrap-with (fn [] (throw (Exception.))) cb)) | |
(dotimes [i 5] | |
(try (fail) (catch Exception e))) | |
(assert (= (ClosedState. default-policy 5) @cb)) | |
(try (fail) (catch Exception e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIQuery *)swipe { | |
[[UIQueryExpectation withQuery:self] exist:@"before you can swipe it"]; | |
for (UIView *view in [self targetViews]) { | |
UITouch *touch = [[UITouch alloc] initInView:view]; | |
UIEvent *eventDown = [[NSClassFromString(@"UITouchesEvent") alloc] initWithTouch:touch]; | |
NSSet *touches = [[NSMutableSet alloc] initWithObjects:&touch count:1]; | |
[touch.view touchesBegan:touches withEvent:eventDown]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
- (UIQuery *)swipe { | |
[[UIQueryExpectation withQuery:self] exist:@"before you can swipe it"]; | |
for (UIView *view in [self targetViews]) { | |
NSMutableArray* events = [NSMutableArray | |
arrayWithCapacity:10]; | |
for (NSMutableDictionary *event in [self swipeEventsForView:view]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIQuery *)swipe { | |
postMouseEvent(96,97,0); | |
postMouseEvent(96,97,1); | |
[self performSelector:@selector(postEvent) withObject:nil afterDelay:2]; | |
//... | |
} | |
- (void) postEvent { | |
for (int i=0;i<150;i++) { | |
// [self performSelector:@selector(postEvent) withObject:nil afterDelay:0.2+0.01*i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//line breaks inserted for readability | |
java -jar closure-compiler/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --define goog.DEBUG=false --module_output_path_prefix public/2011-10-06_18-20-43_compiled_ --module chatpp_modules:97 --module chatpp_storage_module:2:chatpp_modules | |
--js public/closure-library/closure/goog/deps.js | |
--js public/closure-library/closure/goog/base.js | |
--js public/closure-library/closure/goog/debug/errorhandlerweakdep.js | |
... | |
--js public/chatpp/model/user/User.js | |
--js public/chatpp/events/AppEvent.js | |
--js public/chatpp/model/message/Message.js | |
--js public/chatpp/model/model.js |