From 457ccc12506123746457412c47bd7709585a214f Mon Sep 17 00:00:00 2001 From: galarragas Date: Fri, 25 Dec 2015 10:00:03 +0000 Subject: [PATCH] Post revision changes: - Typo in documentation - Made case classes `final` - Hidden the actor's `log` with one passed as parameter to the method --- akka-contrib/docs/circuitbreaker.rst | 2 +- .../circuitbreaker/CircuitBreakerActor.scala | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/akka-contrib/docs/circuitbreaker.rst b/akka-contrib/docs/circuitbreaker.rst index a3d9adbb0c..bdcb894ffc 100644 --- a/akka-contrib/docs/circuitbreaker.rst +++ b/akka-contrib/docs/circuitbreaker.rst @@ -3,7 +3,7 @@ Circuit-Breaker Actor This is an alternative implementation of the [AKKA Circuit Breaker Pattern](http://doc.akka.io/docs/akka/snapshot/common/circuitbreaker.html). The main difference is that is intended to be used only for request-reply interactions with actor using the Circuit-Breaker as a proxy of the target one -in order to provide the same failfast functionnalities and a protocol similar to the AKKA Pattern implementation +in order to provide the same failfast functionalities and a protocol similar to the AKKA Pattern implementation ### Usage diff --git a/akka-contrib/src/main/scala/akka/contrib/circuitbreaker/CircuitBreakerActor.scala b/akka-contrib/src/main/scala/akka/contrib/circuitbreaker/CircuitBreakerActor.scala index 5cd40dde57..bacd99f134 100644 --- a/akka-contrib/src/main/scala/akka/contrib/circuitbreaker/CircuitBreakerActor.scala +++ b/akka-contrib/src/main/scala/akka/contrib/circuitbreaker/CircuitBreakerActor.scala @@ -1,9 +1,10 @@ /** - * Copyright (C) 2014-2015 Typesafe Inc. - */ + * Copyright (C) 2014-2015 Typesafe Inc. + */ package akka.contrib.circuitbreaker import akka.actor._ +import akka.event.LoggingAdapter import akka.pattern._ import akka.util.Timeout @@ -42,22 +43,22 @@ object CircuitBreakerActor { sealed trait CircuitBreakerCommand - case class TellOnly(msg: Any) extends CircuitBreakerCommand + final case class TellOnly(msg: Any) extends CircuitBreakerCommand sealed trait CircuitBreakerResponse - case class CircuitOpenFailure(failedMsg: Any) + final case class CircuitOpenFailure(failedMsg: Any) sealed trait CircuitBreakerEvent - case class CircuitOpen(circuit: ActorRef) extends CircuitBreakerCommand - case class CircuitClosed(circuit: ActorRef) extends CircuitBreakerCommand - case class CircuitHalfOpen(circuit: ActorRef) extends CircuitBreakerCommand + final case class CircuitOpen(circuit: ActorRef) extends CircuitBreakerCommand + final case class CircuitClosed(circuit: ActorRef) extends CircuitBreakerCommand + final case class CircuitHalfOpen(circuit: ActorRef) extends CircuitBreakerCommand sealed trait CircuitBreakerState case object Open extends CircuitBreakerState case object Closed extends CircuitBreakerState case object HalfOpen extends CircuitBreakerState - case class CircuitBreakerStateData(failureCount: Int = 0, firstHalfOpenMessageSent: Boolean = false) + final case class CircuitBreakerStateData(failureCount: Int = 0, firstHalfOpenMessageSent: Boolean = false) /** * Convenience builder with appropriate defaults to create the CircuitBreakerActor props @@ -71,11 +72,10 @@ object CircuitBreakerActor { * @param failureDetector function to detect if the a message received from the target actor as * response from a request represent a failure, defaults to a function accepting every * response making this circuit breaker be activated by response timeouts only - * * @param openCircuitFailureConverter function to map a failure into a response message. * Defaults to an identify function */ - case class CircuitBreakerActorBuilder( + final case class CircuitBreakerActorBuilder( maxFailures: Int, callTimeout: Timeout, resetTimeout: Timeout, circuitEventListener: Option[ActorRef] = None, failureDetector: Any ⇒ Boolean = { _ ⇒ false }, @@ -161,7 +161,7 @@ class CircuitBreakerActor( case Event(message, state) ⇒ log.debug("CLOSED: Sending message {} expecting a response withing timeout {}", message, callTimeout) val currentSender = sender() - forwardRequest(message, sender, state) + forwardRequest(message, sender, state, log) stay } @@ -206,7 +206,7 @@ class CircuitBreakerActor( case Event(message, state @ CircuitBreakerStateData(_, false)) ⇒ log.debug("HALF-OPEN: First message {} received, forwarding it to target {}", message, target) - forwardRequest(message, sender, state) + forwardRequest(message, sender, state, log) stay using state.copy(firstHalfOpenMessageSent = true) case Event(message, CircuitBreakerStateData(_, true)) ⇒ @@ -217,7 +217,7 @@ class CircuitBreakerActor( } } - def forwardRequest(message: Any, currentSender: ActorRef, state: CircuitBreakerStateData) = { + def forwardRequest(message: Any, currentSender: ActorRef, state: CircuitBreakerStateData, log: LoggingAdapter) = { import context.dispatcher target.ask(message)(callTimeout).onComplete {