diff --git a/akka-docs/rst/common/code/docs/circuitbreaker/CircuitBreakerDocSpec.scala b/akka-docs/rst/common/code/docs/circuitbreaker/CircuitBreakerDocSpec.scala index 6e942a0160..9d279f0df0 100644 --- a/akka-docs/rst/common/code/docs/circuitbreaker/CircuitBreakerDocSpec.scala +++ b/akka-docs/rst/common/code/docs/circuitbreaker/CircuitBreakerDocSpec.scala @@ -7,7 +7,9 @@ package docs.circuitbreaker //#imports1 import scala.concurrent.util.duration._ // small d is important here import akka.pattern.CircuitBreaker +import akka.pattern.pipe import akka.actor.Actor +import akka.actor.ActorLogging import scala.concurrent.Future import akka.event.Logging @@ -16,13 +18,14 @@ import akka.event.Logging class CircuitBreakerDocSpec {} //#circuit-breaker-initialization -class DangerousActor extends Actor { +class DangerousActor extends Actor with ActorLogging { + import context.dispatcher - val log = Logging(context.system, this) - implicit val executionContext = context.dispatcher val breaker = - new CircuitBreaker(context.system.scheduler, 5, 10.seconds, 1.minute) - .onOpen(notifyMeOnOpen) + new CircuitBreaker(context.system.scheduler, + maxFailures = 5, + callTimeout = 10.seconds, + resetTimeout = 1.minute).onOpen(notifyMeOnOpen) def notifyMeOnOpen = log.warning("My CircuitBreaker is now open, and will not close for one minute") @@ -33,7 +36,7 @@ class DangerousActor extends Actor { def receive = { case "is my middle name" ⇒ - sender ! breaker.withCircuitBreaker(Future(dangerousCall)) + breaker.withCircuitBreaker(Future(dangerousCall)) pipeTo sender case "block for me" ⇒ sender ! breaker.withSyncCircuitBreaker(dangerousCall) } diff --git a/akka-docs/rst/common/code/docs/circuitbreaker/DangerousJavaActor.java b/akka-docs/rst/common/code/docs/circuitbreaker/DangerousJavaActor.java index 287f10df4f..dbaa9b4100 100644 --- a/akka-docs/rst/common/code/docs/circuitbreaker/DangerousJavaActor.java +++ b/akka-docs/rst/common/code/docs/circuitbreaker/DangerousJavaActor.java @@ -12,6 +12,7 @@ import scala.concurrent.util.Duration; import akka.pattern.CircuitBreaker; import akka.event.Logging; +import static akka.pattern.Patterns.pipe; import static akka.dispatch.Futures.future; import java.util.concurrent.Callable; @@ -58,13 +59,12 @@ public class DangerousJavaActor extends UntypedActor { } }, getContext().dispatcher()); - getSender().tell(breaker - .callWithCircuitBreaker( - new Callable>() { - public Future call() throws Exception { - return f; - } - }), getSelf()); + pipe(breaker.callWithCircuitBreaker( + new Callable>() { + public Future call() throws Exception { + return f; + } + }), getContext().dispatcher()).to(getSender()); } if ("block for me".equals(m)) { getSender().tell(breaker