=doc #3689 Don't rewrite arrows in doc and samples

This commit is contained in:
Patrik Nordwall 2013-12-03 16:34:26 +01:00
parent 37f8f2831b
commit 5a019c0a7a
61 changed files with 531 additions and 517 deletions

View file

@ -26,8 +26,8 @@ import scala.concurrent.Await
class MyActor extends Actor {
val log = Logging(context.system, this)
def receive = {
case "test" log.info("received test")
case _ log.info("received unknown message")
case "test" => log.info("received test")
case _ => log.info("received unknown message")
}
}
//#my-actor
@ -40,14 +40,14 @@ class FirstActor extends Actor {
val child = context.actorOf(Props[MyActor], name = "myChild")
//#plus-some-behavior
def receive = {
case x sender ! x
case x => sender ! x
}
//#plus-some-behavior
}
//#context-actorOf
class ActorWithArgs(arg: String) extends Actor {
def receive = { case _ () }
def receive = { case _ => () }
}
class DemoActorWrapper extends Actor {
@ -64,7 +64,7 @@ class DemoActorWrapper extends Actor {
class DemoActor(magicNumber: Int) extends Actor {
def receive = {
case x: Int sender ! (x + magicNumber)
case x: Int => sender ! (x + magicNumber)
}
}
@ -79,10 +79,10 @@ class DemoActorWrapper extends Actor {
class AnonymousActor extends Actor {
//#anonymous-actor
def receive = {
case m: DoIt
case m: DoIt =>
context.actorOf(Props(new Actor {
def receive = {
case DoIt(msg)
case DoIt(msg) =>
val replyMsg = doSomeDangerousWork(msg)
sender ! replyMsg
context.stop(self)
@ -112,13 +112,13 @@ class Hook extends Actor {
class ReplyException extends Actor {
def receive = {
case _
case _ =>
//#reply-exception
try {
val result = operation()
sender ! result
} catch {
case e: Exception
case e: Exception =>
sender ! akka.actor.Status.Failure(e)
throw e
}
@ -136,10 +136,10 @@ class Swapper extends Actor {
val log = Logging(system, this)
def receive = {
case Swap
case Swap =>
log.info("Hi")
become({
case Swap
case Swap =>
log.info("Ho")
unbecome() // resets the latest 'become' (just for fun)
}, discardOld = false) // push on top instead of replace
@ -166,7 +166,7 @@ abstract class GenericActor extends Actor {
// generic message handler
def genericMessageHandler: Receive = {
case event printf("generic: %s\n", event)
case event => printf("generic: %s\n", event)
}
def receive = specificMessageHandler orElse genericMessageHandler
@ -174,7 +174,7 @@ abstract class GenericActor extends Actor {
class SpecificActor extends GenericActor {
def specificMessageHandler = {
case event: MyMsg printf("specific: %s\n", event.subject)
case event: MyMsg => printf("specific: %s\n", event.subject)
}
}
@ -190,7 +190,7 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
import context._
val myActor = actorOf(Props[MyActor], name = "myactor")
def receive = {
case x myActor ! x
case x => myActor ! x
}
}
//#import-context
@ -207,17 +207,17 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
// TODO: convert docs to AkkaSpec(Map(...))
val filter = EventFilter.custom {
case e: Logging.Info true
case _ false
case e: Logging.Info => true
case _ => false
}
system.eventStream.publish(TestEvent.Mute(filter))
system.eventStream.subscribe(testActor, classOf[Logging.Info])
myActor ! "test"
expectMsgPF(1 second) { case Logging.Info(_, _, "received test") true }
expectMsgPF(1 second) { case Logging.Info(_, _, "received test") => true }
myActor ! "unknown"
expectMsgPF(1 second) { case Logging.Info(_, _, "received unknown message") true }
expectMsgPF(1 second) { case Logging.Info(_, _, "received unknown message") => true }
system.eventStream.unsubscribe(testActor)
system.eventStream.publish(TestEvent.UnMute(filter))
@ -245,7 +245,7 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
//#creating-props-deprecated
// DEPRECATED: old case class signature
val props4 = Props(
creator = { () new MyActor },
creator = { () => new MyActor },
dispatcher = "my-dispatcher")
// DEPRECATED due to duplicate functionality with Props.apply()
@ -273,8 +273,8 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
"creating actor with IndirectActorProducer" in {
class Echo(name: String) extends Actor {
def receive = {
case n: Int sender ! name
case message
case n: Int => sender ! name
case message =>
val target = testActor
//#forward
target forward message
@ -348,10 +348,10 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
// To set an initial delay
context.setReceiveTimeout(30 milliseconds)
def receive = {
case "Hello"
case "Hello" =>
// To set in a response to a message
context.setReceiveTimeout(100 milliseconds)
case ReceiveTimeout
case ReceiveTimeout =>
// To turn it off
context.setReceiveTimeout(Duration.Undefined)
throw new RuntimeException("Receive timed out")
@ -364,18 +364,18 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
class HotSwapActor extends Actor {
import context._
def angry: Receive = {
case "foo" sender ! "I am already angry?"
case "bar" become(happy)
case "foo" => sender ! "I am already angry?"
case "bar" => become(happy)
}
def happy: Receive = {
case "bar" sender ! "I am already happy :-)"
case "foo" become(angry)
case "bar" => sender ! "I am already happy :-)"
case "foo" => become(angry)
}
def receive = {
case "foo" become(angry)
case "bar" become(happy)
case "foo" => become(angry)
case "bar" => become(happy)
}
}
//#hot-swap-actor
@ -389,16 +389,16 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
import akka.actor.Stash
class ActorWithProtocol extends Actor with Stash {
def receive = {
case "open"
case "open" =>
unstashAll()
context.become({
case "write" // do writing...
case "close"
case "write" => // do writing...
case "close" =>
unstashAll()
context.unbecome()
case msg stash()
case msg => stash()
}, discardOld = false) // stack on top instead of replacing
case msg stash()
case msg => stash()
}
}
//#stash
@ -415,9 +415,9 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
var lastSender = system.deadLetters
def receive = {
case "kill"
case "kill" =>
context.stop(child); lastSender = sender
case Terminated(`child`) lastSender ! "finished"
case Terminated(`child`) => lastSender ! "finished"
}
}
//#watch
@ -457,15 +457,15 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
context.actorSelection("/user/another") ! Identify(identifyId)
def receive = {
case ActorIdentity(`identifyId`, Some(ref))
case ActorIdentity(`identifyId`, Some(ref)) =>
context.watch(ref)
context.become(active(ref))
case ActorIdentity(`identifyId`, None) context.stop(self)
case ActorIdentity(`identifyId`, None) => context.stop(self)
}
def active(another: ActorRef): Actor.Receive = {
case Terminated(`another`) context.stop(self)
case Terminated(`another`) => context.stop(self)
}
}
//#identify
@ -490,7 +490,7 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
// the actor has been stopped
} catch {
// the actor wasn't stopped within 5 seconds
case e: akka.pattern.AskTimeoutException
case e: akka.pattern.AskTimeoutException =>
}
//#gracefulStop
}
@ -507,9 +507,9 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
val f: Future[Result] =
for {
x ask(actorA, Request).mapTo[Int] // call pattern directly
s (actorB ask Request).mapTo[String] // call by implicit conversion
d (actorC ? Request).mapTo[Double] // call by symbolic name
x <- ask(actorA, Request).mapTo[Int] // call pattern directly
s <- (actorB ask Request).mapTo[String] // call by implicit conversion
d <- (actorC ? Request).mapTo[Double] // call by symbolic name
} yield Result(x, s, d)
f pipeTo actorD // .. or ..
@ -519,12 +519,12 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
class Replier extends Actor {
def receive = {
case ref: ActorRef
case ref: ActorRef =>
//#reply-with-sender
sender.tell("reply", context.parent) // replies will go back to parent
sender.!("reply")(context.parent) // alternative syntax (beware of the parens!)
//#reply-with-sender
case x
case x =>
//#reply-without-sender
sender ! x // replies will go to this actor
//#reply-without-sender
@ -547,8 +547,8 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
"using ActorDSL outside of akka.actor package" in {
import akka.actor.ActorDSL._
actor(new Act {
superviseWith(OneForOneStrategy() { case _ Stop; Restart; Resume; Escalate })
superviseWith(AllForOneStrategy() { case _ Stop; Restart; Resume; Escalate })
superviseWith(OneForOneStrategy() { case _ => Stop; Restart; Resume; Escalate })
superviseWith(AllForOneStrategy() { case _ => Stop; Restart; Resume; Escalate })
})
}
@ -561,9 +561,9 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
private var pfsOption: Option[Vector[PF]] = Some(Vector.empty)
private def mapPfs[C](f: Vector[PF] (Option[Vector[PF]], C)): C = {
private def mapPfs[C](f: Vector[PF] => (Option[Vector[PF]], C)): C = {
pfsOption.fold(throw new IllegalStateException("Already built"))(f) match {
case (newPfsOption, result) {
case (newPfsOption, result) => {
pfsOption = newPfsOption
result
}
@ -571,10 +571,10 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
}
def +=(pf: PF): Unit =
mapPfs { case pfs (Some(pfs :+ pf), ()) }
mapPfs { case pfs => (Some(pfs :+ pf), ()) }
def result(): PF =
mapPfs { case pfs (None, pfs.foldLeft[PF](Map.empty) { _ orElse _ }) }
mapPfs { case pfs => (None, pfs.foldLeft[PF](Map.empty) { _ orElse _ }) }
}
trait ComposableActor extends Actor {
@ -584,13 +584,13 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
trait TheirComposableActor extends ComposableActor {
receiveBuilder += {
case "foo" sender ! "foo received"
case "foo" => sender ! "foo received"
}
}
class MyComposableActor extends TheirComposableActor {
receiveBuilder += {
case "bar" sender ! "bar received"
case "bar" => sender ! "bar received"
}
}
//#receive-orElse2

View file

@ -5,7 +5,7 @@ package docs.actor
import language.postfixOps
import akka.testkit.{ AkkaSpec MyFavoriteTestFrameWorkPlusAkkaTestKit }
import akka.testkit.{ AkkaSpec => MyFavoriteTestFrameWorkPlusAkkaTestKit }
import akka.util.ByteString
//#test-code
@ -46,23 +46,23 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
//#when-syntax
when(Idle) {
case Event(SetTarget(ref), Uninitialized)
case Event(SetTarget(ref), Uninitialized) =>
stay using Todo(ref, Vector.empty)
}
//#when-syntax
//#transition-elided
onTransition {
case Active -> Idle
case Active -> Idle =>
stateData match {
case Todo(ref, queue) ref ! Batch(queue)
case Todo(ref, queue) => ref ! Batch(queue)
}
}
//#transition-elided
//#when-syntax
when(Active, stateTimeout = 1 second) {
case Event(Flush | StateTimeout, t: Todo)
case Event(Flush | StateTimeout, t: Todo) =>
goto(Idle) using t.copy(queue = Vector.empty)
}
//#when-syntax
@ -70,10 +70,10 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
//#unhandled-elided
whenUnhandled {
// common code for both states
case Event(Queue(obj), t @ Todo(_, v))
case Event(Queue(obj), t @ Todo(_, v)) =>
goto(Active) using t.copy(queue = v :+ obj)
case Event(e, s)
case Event(e, s) =>
log.warning("received unhandled request {} in state {}/{}", e, stateName, s)
stay
}
@ -99,16 +99,16 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
//#modifier-syntax
when(SomeState) {
case Event(msg, _)
case Event(msg, _) =>
goto(Processing) using (newData) forMax (5 seconds) replying (WillDo)
}
//#modifier-syntax
//#transition-syntax
onTransition {
case Idle -> Active setTimer("timeout", Tick, 1 second, true)
case Active -> _ cancelTimer("timeout")
case x -> Idle log.info("entering Idle from " + x)
case Idle -> Active => setTimer("timeout", Tick, 1 second, true)
case Active -> _ => cancelTimer("timeout")
case x -> Idle => log.info("entering Idle from " + x)
}
//#transition-syntax
@ -122,7 +122,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
//#stop-syntax
when(Error) {
case Event("stop", _)
case Event("stop", _) =>
// do cleanup ...
stop()
}
@ -130,38 +130,38 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
//#transform-syntax
when(SomeState)(transform {
case Event(bytes: ByteString, read) stay using (read + bytes.length)
case Event(bytes: ByteString, read) => stay using (read + bytes.length)
} using {
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000 =>
goto(Processing)
})
//#transform-syntax
//#alt-transform-syntax
val processingTrigger: PartialFunction[State, State] = {
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000 =>
goto(Processing)
}
when(SomeState)(transform {
case Event(bytes: ByteString, read) stay using (read + bytes.length)
case Event(bytes: ByteString, read) => stay using (read + bytes.length)
} using processingTrigger)
//#alt-transform-syntax
//#termination-syntax
onTermination {
case StopEvent(FSM.Normal, state, data) // ...
case StopEvent(FSM.Shutdown, state, data) // ...
case StopEvent(FSM.Failure(cause), state, data) // ...
case StopEvent(FSM.Normal, state, data) => // ...
case StopEvent(FSM.Shutdown, state, data) => // ...
case StopEvent(FSM.Failure(cause), state, data) => // ...
}
//#termination-syntax
//#unhandled-syntax
whenUnhandled {
case Event(x: X, data)
case Event(x: X, data) =>
log.info("Received unhandled event: " + x)
stay
case Event(msg, _)
case Event(msg, _) =>
log.warning("Received unknown event: " + msg)
goto(Error)
}
@ -175,7 +175,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
//#body-elided
override def logDepth = 12
onTermination {
case StopEvent(FSM.Failure(_), state, data)
case StopEvent(FSM.Failure(_), state, data) =>
val lastEvents = getLog.mkString("\n\t")
log.warning("Failure in state " + state + " with data " + data + "\n" +
"Events leading up to this point:\n\t" + lastEvents)

View file

@ -49,14 +49,14 @@ class Listener extends Actor with ActorLogging {
context.setReceiveTimeout(15 seconds)
def receive = {
case Progress(percent)
case Progress(percent) =>
log.info("Current progress: {} %", percent)
if (percent >= 100.0) {
log.info("That's all, shutting down")
context.system.shutdown()
}
case ReceiveTimeout
case ReceiveTimeout =>
// No progress within 15 seconds, ServiceUnavailable
log.error("Shutting down due to unavailable service")
context.system.shutdown()
@ -83,7 +83,7 @@ class Worker extends Actor with ActorLogging {
// Stop the CounterService child if it throws ServiceUnavailable
override val supervisorStrategy = OneForOneStrategy() {
case _: CounterService.ServiceUnavailable Stop
case _: CounterService.ServiceUnavailable => Stop
}
// The sender of the initial Start message will continuously be notified
@ -94,18 +94,18 @@ class Worker extends Actor with ActorLogging {
import context.dispatcher // Use this Actors' Dispatcher as ExecutionContext
def receive = LoggingReceive {
case Start if progressListener.isEmpty
case Start if progressListener.isEmpty =>
progressListener = Some(sender)
context.system.scheduler.schedule(Duration.Zero, 1 second, self, Do)
case Do
case Do =>
counterService ! Increment(1)
counterService ! Increment(1)
counterService ! Increment(1)
// Send current progress to the initial sender
counterService ? GetCurrentCount map {
case CurrentCount(_, count) Progress(100.0 * count / totalCount)
case CurrentCount(_, count) => Progress(100.0 * count / totalCount)
} pipeTo progressListener.get
}
}
@ -135,7 +135,7 @@ class CounterService extends Actor {
// After 3 restarts within 5 seconds it will be stopped.
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 3,
withinTimeRange = 5 seconds) {
case _: Storage.StorageException Restart
case _: Storage.StorageException => Restart
}
val key = self.path.name
@ -166,21 +166,21 @@ class CounterService extends Actor {
def receive = LoggingReceive {
case Entry(k, v) if k == key && counter == None
case Entry(k, v) if k == key && counter == None =>
// Reply from Storage of the initial value, now we can create the Counter
val c = context.actorOf(Props(classOf[Counter], key, v))
counter = Some(c)
// Tell the counter to use current storage
c ! UseStorage(storage)
// and send the buffered backlog to the counter
for ((replyTo, msg) backlog) c.tell(msg, sender = replyTo)
for ((replyTo, msg) <- backlog) c.tell(msg, sender = replyTo)
backlog = IndexedSeq.empty
case msg @ Increment(n) forwardOrPlaceInBacklog(msg)
case msg @ Increment(n) => forwardOrPlaceInBacklog(msg)
case msg @ GetCurrentCount forwardOrPlaceInBacklog(msg)
case msg @ GetCurrentCount => forwardOrPlaceInBacklog(msg)
case Terminated(actorRef) if Some(actorRef) == storage
case Terminated(actorRef) if Some(actorRef) == storage =>
// After 3 restarts the storage child is stopped.
// We receive Terminated because we watch the child, see initStorage.
storage = None
@ -189,7 +189,7 @@ class CounterService extends Actor {
// Try to re-establish storage after while
context.system.scheduler.scheduleOnce(10 seconds, self, Reconnect)
case Reconnect
case Reconnect =>
// Re-establish storage after the scheduled delay
initStorage()
}
@ -199,8 +199,8 @@ class CounterService extends Actor {
// the counter. Before that we place the messages in a backlog, to be sent
// to the counter when it is initialized.
counter match {
case Some(c) c forward msg
case None
case Some(c) => c forward msg
case None =>
if (backlog.size >= MaxBacklog)
throw new ServiceUnavailable(
"CounterService not available, lack of initial value")
@ -230,15 +230,15 @@ class Counter(key: String, initialValue: Long) extends Actor {
var storage: Option[ActorRef] = None
def receive = LoggingReceive {
case UseStorage(s)
case UseStorage(s) =>
storage = s
storeCount()
case Increment(n)
case Increment(n) =>
count += n
storeCount()
case GetCurrentCount
case GetCurrentCount =>
sender ! CurrentCount(key, count)
}
@ -271,8 +271,8 @@ class Storage extends Actor {
val db = DummyDB
def receive = LoggingReceive {
case Store(Entry(key, count)) db.save(key, count)
case Get(key) sender ! Entry(key, db.load(key).getOrElse(0L))
case Store(Entry(key, count)) => db.save(key, count)
case Get(key) => sender ! Entry(key, db.load(key).getOrElse(0L))
}
}

View file

@ -26,15 +26,15 @@ object FaultHandlingDocSpec {
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case _: ArithmeticException Resume
case _: NullPointerException Restart
case _: IllegalArgumentException Stop
case _: Exception Escalate
case _: ArithmeticException => Resume
case _: NullPointerException => Restart
case _: IllegalArgumentException => Stop
case _: Exception => Escalate
}
//#strategy
def receive = {
case p: Props sender ! context.actorOf(p)
case p: Props => sender ! context.actorOf(p)
}
}
//#supervisor
@ -48,15 +48,15 @@ object FaultHandlingDocSpec {
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case _: ArithmeticException Resume
case _: NullPointerException Restart
case _: IllegalArgumentException Stop
case _: Exception Escalate
case _: ArithmeticException => Resume
case _: NullPointerException => Restart
case _: IllegalArgumentException => Stop
case _: Exception => Escalate
}
//#strategy2
def receive = {
case p: Props sender ! context.actorOf(p)
case p: Props => sender ! context.actorOf(p)
}
// override default to kill all children during restart
override def preRestart(cause: Throwable, msg: Option[Any]) {}
@ -71,9 +71,9 @@ object FaultHandlingDocSpec {
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case _: ArithmeticException Resume
case t
super.supervisorStrategy.decider.applyOrElse(t, (_: Any) Escalate)
case _: ArithmeticException => Resume
case t =>
super.supervisorStrategy.decider.applyOrElse(t, (_: Any) => Escalate)
}
//#default-strategy-fallback
@ -85,9 +85,9 @@ object FaultHandlingDocSpec {
class Child extends Actor {
var state = 0
def receive = {
case ex: Exception throw ex
case x: Int state = x
case "get" sender ! state
case ex: Exception => throw ex
case x: Int => state = x
case "get" => sender ! state
}
}
//#child
@ -133,7 +133,7 @@ class FaultHandlingDocSpec extends AkkaSpec with ImplicitSender {
//#stop
watch(child) // have testActor watch child
child ! new IllegalArgumentException // break it
expectMsgPF() { case Terminated(`child`) () }
expectMsgPF() { case Terminated(`child`) => () }
//#stop
}
EventFilter[Exception]("CRASH", occurrences = 2) intercept {
@ -147,7 +147,7 @@ class FaultHandlingDocSpec extends AkkaSpec with ImplicitSender {
child2 ! new Exception("CRASH") // escalate failure
expectMsgPF() {
case t @ Terminated(`child2`) if t.existenceConfirmed ()
case t @ Terminated(`child2`) if t.existenceConfirmed => ()
}
//#escalate-kill
//#escalate-restart

View file

@ -10,7 +10,7 @@ object InitializationDocSpec {
class PreStartInitExample extends Actor {
override def receive = {
case _ // Ignore
case _ => // Ignore
}
//#preStartInit
@ -37,14 +37,14 @@ object InitializationDocSpec {
var initializeMe: Option[String] = None
override def receive = {
case "init"
case "init" =>
initializeMe = Some("Up and running")
context.become(initialized, discardOld = true)
}
def initialized: Receive = {
case "U OK?" initializeMe foreach { sender ! _ }
case "U OK?" => initializeMe foreach { sender ! _ }
}
//#messageInit

View file

@ -43,7 +43,7 @@ class SchedulerDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
val Tick = "tick"
class TickActor extends Actor {
def receive = {
case Tick //Do something
case Tick => //Do something
}
}
val tickActor = system.actorOf(Props(classOf[TickActor], this))

View file

@ -12,7 +12,7 @@ import org.scalatest.matchers.MustMatchers
import akka.testkit._
//Mr funny man avoids printing to stdout AND keeping docs alright
import java.lang.String.{ valueOf println }
import java.lang.String.{ valueOf => println }
import akka.actor.ActorRef
//#typed-actor-iface
@ -91,7 +91,7 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
//#typed-actor-extension-tools
} catch {
case e: Exception //dun care
case e: Exception => //dun care
}
}
@ -160,7 +160,7 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
//Use "childSquarer" as a Squarer
//#typed-actor-hierarchy
} catch {
case e: Exception //ignore
case e: Exception => //ignore
}
}

View file

@ -34,16 +34,16 @@ class UnnestedReceives extends Actor {
}
def receive = {
case 'Replay //Our first message should be a 'Replay message, all others are invalid
case 'Replay => //Our first message should be a 'Replay message, all others are invalid
allOldMessages() foreach process //Process all old messages/events
become { //Switch behavior to look for the GoAhead signal
case 'GoAhead //When we get the GoAhead signal we process all our buffered messages/events
case 'GoAhead => //When we get the GoAhead signal we process all our buffered messages/events
queue foreach process
queue.clear
become { //Then we change behaviour to process incoming messages/events as they arrive
case msg process(msg)
case msg => process(msg)
}
case msg //While we haven't gotten the GoAhead signal, buffer all incoming messages
case msg => //While we haven't gotten the GoAhead signal, buffer all incoming messages
queue += msg //Here you have full control, you can handle overflow etc
}
}

View file

@ -17,7 +17,7 @@ import akka.actor.{ Actor, ExtendedActorSystem }
class MyActor extends Actor {
def receive = {
case x
case x =>
}
}
@ -61,8 +61,8 @@ class MyMailboxType(systemSettings: ActorSystem.Settings, config: Config)
override def create(owner: Option[ActorRef],
system: Option[ActorSystem]): MessageQueue =
(owner zip system) headOption match {
case Some((o, s: ExtendedActorSystem)) new MyMessageQueue(o, s)
case _
case Some((o, s: ExtendedActorSystem)) => new MyMessageQueue(o, s)
case _ =>
throw new IllegalArgumentException("requires an owner " +
"(i.e. does not work with BalancingDispatcher)")
}