diff --git a/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala b/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala index 5db3783d79..b128944ff1 100644 --- a/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala +++ b/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala @@ -191,7 +191,7 @@ object DistributedPubSubMediator { def business: Receive - def receive = business orElse defaultReceive + def receive = business.orElse[Any, Unit](defaultReceive) def remove(ref: ActorRef): Unit = { if (subscribers.contains(ref)) diff --git a/akka-contrib/src/main/scala/akka/contrib/pattern/ReceivePipeline.scala b/akka-contrib/src/main/scala/akka/contrib/pattern/ReceivePipeline.scala index 600049c5c9..94f397b55e 100644 --- a/akka-contrib/src/main/scala/akka/contrib/pattern/ReceivePipeline.scala +++ b/akka-contrib/src/main/scala/akka/contrib/pattern/ReceivePipeline.scala @@ -38,7 +38,7 @@ trait ReceivePipeline extends Actor { val around = aroundCache match { case Some((`receive`, cached)) ⇒ cached case _ ⇒ - val zipped = pipeline.foldRight(receive)((outer, inner) ⇒ outer(inner) orElse inner) + val zipped = pipeline.foldRight[Receive](receive)((outer, inner) ⇒ outer(inner).orElse[Any, Unit](inner)) aroundCache = Some((receive, zipped)) zipped } diff --git a/akka-contrib/src/test/scala/akka/contrib/pattern/ReceivePipelineSpec.scala b/akka-contrib/src/test/scala/akka/contrib/pattern/ReceivePipelineSpec.scala index 90239675a1..597e260004 100644 --- a/akka-contrib/src/test/scala/akka/contrib/pattern/ReceivePipelineSpec.scala +++ b/akka-contrib/src/test/scala/akka/contrib/pattern/ReceivePipelineSpec.scala @@ -2,49 +2,60 @@ package akka.contrib.pattern import akka.testkit.{ ImplicitSender, AkkaSpec } import akka.actor.{ Actor, Props } +import scala.concurrent.duration._ -class ReplierActor extends Actor with ReceivePipeline { - def receive: Actor.Receive = becomeAndReply - def becomeAndReply: Actor.Receive = { - case "become" ⇒ context.become(justReply) - case m ⇒ sender ! m +object ReceivePipelineSpec { + + class ReplierActor extends Actor with ReceivePipeline { + def receive: Actor.Receive = becomeAndReply + def becomeAndReply: Actor.Receive = { + case "become" ⇒ context.become(justReply) + case m ⇒ sender ! m + } + def justReply: Actor.Receive = { + case m ⇒ sender ! m + } } - def justReply: Actor.Receive = { - case m ⇒ sender ! m + + case class IntList(l: List[Int]) { + override def toString: String = s"IntList(${l.mkString(", ")})" } -} -trait ListBuilderInterceptor { - this: ReceivePipeline ⇒ + trait ListBuilderInterceptor { + this: ReceivePipeline ⇒ - pipelineOuter(inner ⇒ - { - case n: Int ⇒ inner((n until n + 3).toList) - }) -} + pipelineOuter(inner ⇒ + { + case n: Int ⇒ inner(IntList((n until n + 3).toList)) + }) + } -trait AdderInterceptor { - this: ReceivePipeline ⇒ + trait AdderInterceptor { + this: ReceivePipeline ⇒ - pipelineInner(inner ⇒ - { - case n: Int ⇒ inner(n + 10) - case l: List[Int] ⇒ inner(l.map(_ + 10)) - case "explicitly ignored" ⇒ - }) -} + pipelineInner(inner ⇒ + { + case n: Int ⇒ inner(n + 10) + case IntList(l) ⇒ inner(IntList(l.map(_ + 10))) + case "explicitly ignored" ⇒ + }) + } -trait ToStringInterceptor { - this: ReceivePipeline ⇒ + trait ToStringInterceptor { + this: ReceivePipeline ⇒ + + pipelineInner(inner ⇒ + { + case i: Int ⇒ inner(i.toString) + case IntList(l) ⇒ inner(l.toString) + case other: Iterable[_] ⇒ inner(other.toString) + }) + } - pipelineInner(inner ⇒ - { - case i: Int ⇒ inner(i.toString) - case l: Iterable[_] ⇒ inner(l.toString()) - }) } class ReceivePipelineSpec extends AkkaSpec with ImplicitSender { + import ReceivePipelineSpec._ "A ReceivePipeline" must { @@ -82,7 +93,8 @@ class ReceivePipelineSpec extends AkkaSpec with ImplicitSender { val replier = system.actorOf(Props( new ReplierActor with ListBuilderInterceptor with AdderInterceptor with ToStringInterceptor)) replier ! "explicitly ignored" - expectNoMsg() + replier ! 8L // unhandled by all interceptors but still replied + expectMsg(8L) } "support changing behavior without losing the interceptions" in { @@ -101,9 +113,9 @@ class ReceivePipelineSpec extends AkkaSpec with ImplicitSender { val innerOuterReplier = system.actorOf(Props( new ReplierActor with AdderInterceptor with ListBuilderInterceptor)) outerInnerReplier ! 4 - expectMsg(List(14, 15, 16)) + expectMsg(IntList(List(14, 15, 16))) innerOuterReplier ! 6 - expectMsg(List(16, 17, 18)) + expectMsg(IntList(List(16, 17, 18))) } } @@ -231,7 +243,7 @@ object MixinSample extends App { // The Dude says 'Yeah, well, you know, that's just, like, your opinion, man.' //#mixin-actor - system.shutdown() + system.terminate() } object UnhandledSample extends App { diff --git a/akka-docs/rst/additional/code/docs/faq/Faq.scala b/akka-docs/rst/additional/code/docs/faq/Faq.scala index 6d270fdd97..9ba5025db1 100644 --- a/akka-docs/rst/additional/code/docs/faq/Faq.scala +++ b/akka-docs/rst/additional/code/docs/faq/Faq.scala @@ -21,6 +21,9 @@ class MyActor extends Actor { case BarMessage(bar) => sender() ! BazMessage("Got " + bar) // warning here: // "match may not be exhaustive. It would fail on the following input: FooMessage(_)" + //#exhaustiveness-check + case FooMessage(_) => // avoid the warning in our build logs + //#exhaustiveness-check } } } diff --git a/akka-docs/rst/java/code/docs/future/FutureDocTest.java b/akka-docs/rst/java/code/docs/future/FutureDocTest.java index d947c49645..4279728760 100644 --- a/akka-docs/rst/java/code/docs/future/FutureDocTest.java +++ b/akka-docs/rst/java/code/docs/future/FutureDocTest.java @@ -554,6 +554,7 @@ public class FutureDocTest { } @Test(expected = IllegalStateException.class) + @SuppressWarnings("unchecked") public void useAfter() throws Exception { //#after final ExecutionContext ec = system.dispatcher(); diff --git a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala index d3f296c332..42dd5cb7f4 100644 --- a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala @@ -92,7 +92,7 @@ class ActorWithMessagesWrapper { import MyActor._ def receive = { case Greeting(greeter) => log.info(s"I was greeted by $greeter.") - case Goodbye => log.info("Someone said goodbye to me.") + case Goodbye => log.info("Someone said goodbye to me.") } } //#messages-in-companion @@ -229,7 +229,7 @@ class Consumer extends Actor with ActorLogging with ConsumerBehavior { class ProducerConsumer extends Actor with ActorLogging with ProducerBehavior with ConsumerBehavior { - def receive = producerBehavior orElse consumerBehavior + def receive = producerBehavior.orElse[Any, Unit](consumerBehavior) } // protocol diff --git a/akka-docs/rst/scala/code/docs/actor/FSMDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/FSMDocSpec.scala index 41cae10068..f8ad23af39 100644 --- a/akka-docs/rst/scala/code/docs/actor/FSMDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/FSMDocSpec.scala @@ -12,13 +12,10 @@ import akka.util.ByteString import akka.actor.Props import scala.collection.immutable -class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit { - - //#fsm-code-elided - //#simple-imports - import akka.actor.{ ActorRef, FSM } - import scala.concurrent.duration._ - //#simple-imports +object FSMDocSpec { + // messages and data types + //#test-code + import akka.actor.ActorRef //#simple-events // received events final case class SetTarget(ref: ActorRef) @@ -38,6 +35,17 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit { case object Uninitialized extends Data final case class Todo(target: ActorRef, queue: immutable.Seq[Any]) extends Data //#simple-state + //#test-code +} + +class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit { + import FSMDocSpec._ + + //#fsm-code-elided + //#simple-imports + import akka.actor.{ ActorRef, FSM } + import scala.concurrent.duration._ + //#simple-imports //#simple-fsm class Buncher extends FSM[State, Data] { @@ -56,6 +64,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit { case Active -> Idle => stateData match { case Todo(ref, queue) => ref ! Batch(queue) + case _ => // nothing to do } } //#transition-elided diff --git a/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSample.scala b/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSample.scala index 3e9454647e..d26b689c5a 100644 --- a/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSample.scala +++ b/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSample.scala @@ -113,7 +113,8 @@ class Worker extends Actor with ActorLogging { //#messages object CounterService { final case class Increment(n: Int) - case object GetCurrentCount + sealed abstract class GetCurrentCount + case object GetCurrentCount extends GetCurrentCount final case class CurrentCount(key: String, count: Long) class ServiceUnavailable(msg: String) extends RuntimeException(msg) @@ -176,9 +177,9 @@ class CounterService extends Actor { for ((replyTo, msg) <- backlog) c.tell(msg, sender = replyTo) backlog = IndexedSeq.empty - case msg @ Increment(n) => forwardOrPlaceInBacklog(msg) + case msg: Increment => forwardOrPlaceInBacklog(msg) - case msg @ GetCurrentCount => forwardOrPlaceInBacklog(msg) + case msg: GetCurrentCount => forwardOrPlaceInBacklog(msg) case Terminated(actorRef) if Some(actorRef) == storage => // After 3 restarts the storage child is stopped. diff --git a/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSpec.scala index f8025e9854..92f46ad1fc 100644 --- a/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/FaultHandlingDocSpec.scala @@ -108,7 +108,7 @@ class FaultHandlingDocSpec extends TestKit(ActorSystem("FaultHandlingDocSpec", t } "A supervisor" must "apply the chosen strategy for its child" in { - //#testkit + //#testkit //#create val supervisor = system.actorOf(Props[Supervisor], "supervisor") diff --git a/akka-docs/rst/scala/code/docs/actor/TypedActorDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/TypedActorDocSpec.scala index 6d6fc0227e..4c107e8254 100644 --- a/akka-docs/rst/scala/code/docs/actor/TypedActorDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/TypedActorDocSpec.scala @@ -143,7 +143,7 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) { //#typed-actor-call-strict //#typed-actor-calls - Await.result(fSquare, 3 seconds) should be(100) + Await.result(fSquare, 3.seconds) should be(100) oSquare should be(Some(100)) @@ -193,7 +193,7 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) { TypedActor(system).poisonPill(awesomeFooBar) //#typed-actor-supercharge-usage - Await.result(f, 3 seconds) should be("YES") + Await.result(f, 3.seconds) should be("YES") } "typed router pattern" in { diff --git a/akka-docs/rst/scala/code/docs/io/EchoServer.scala b/akka-docs/rst/scala/code/docs/io/EchoServer.scala index 0b515a709c..4f1fea6976 100644 --- a/akka-docs/rst/scala/code/docs/io/EchoServer.scala +++ b/akka-docs/rst/scala/code/docs/io/EchoServer.scala @@ -70,18 +70,19 @@ class EchoManager(handlerClass: Class[_]) extends Actor with ActorLogging { } +//#echo-handler object EchoHandler { + final case class Ack(offset: Int) extends Tcp.Event + def props(connection: ActorRef, remote: InetSocketAddress): Props = Props(classOf[EchoHandler], connection, remote) } -//#echo-handler class EchoHandler(connection: ActorRef, remote: InetSocketAddress) extends Actor with ActorLogging { import Tcp._ - - final case class Ack(offset: Int) extends Event + import EchoHandler._ // sign death pact: this actor terminates when connection breaks context watch connection diff --git a/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala b/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala index be37d04e47..5a03629050 100644 --- a/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala @@ -87,8 +87,9 @@ object ScalaUdpDocSpec { //#connected case msg: String => connection ! UdpConnected.Send(ByteString(msg)) - case d @ UdpConnected.Disconnect => connection ! d - case UdpConnected.Disconnected => context.stop(self) + case UdpConnected.Disconnect => + connection ! UdpConnected.Disconnect + case UdpConnected.Disconnected => context.stop(self) } } //#connected diff --git a/akka-docs/rst/scala/code/docs/persistence/PersistenceDocSpec.scala b/akka-docs/rst/scala/code/docs/persistence/PersistenceDocSpec.scala index 87b32f9664..3fb0a3154f 100644 --- a/akka-docs/rst/scala/code/docs/persistence/PersistenceDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/persistence/PersistenceDocSpec.scala @@ -4,13 +4,19 @@ package docs.persistence -import akka.actor.{ Actor, ActorSystem, Props } +import akka.actor.{ Actor, ActorRef, ActorSystem, Props } import akka.persistence._ import com.typesafe.config.ConfigFactory import scala.concurrent.duration._ import scala.language.postfixOps -trait PersistenceDocSpec { + +object PersistenceDocSpec { + + trait SomeOtherMessage + + val persistentActor: ActorRef = ??? + val config = """ //#auto-update-interval @@ -21,13 +27,7 @@ trait PersistenceDocSpec { //#auto-update """ - trait SomeOtherMessage - - implicit val system: ActorSystem - - import system._ - - new AnyRef { + object Recovery { trait MyPersistentActor1 extends PersistentActor { //#recover-on-start-disabled override def preStart() = () @@ -45,7 +45,6 @@ trait PersistenceDocSpec { //#recover-on-start-custom } - val persistentActor = system.deadLetters //#recover-explicit persistentActor ! Recover() //#recover-explicit @@ -69,7 +68,7 @@ trait PersistenceDocSpec { } } - new AnyRef { + object NoRecovery { trait MyPersistentActor1 extends PersistentActor { //#recover-fully-disabled override def preStart() = self ! Recover(toSequenceNr = 0L) @@ -77,7 +76,7 @@ trait PersistenceDocSpec { } } - new AnyRef { + object PersistenceId { trait PersistentActorMethods { //#persistence-id def persistenceId: String @@ -101,7 +100,7 @@ trait PersistenceDocSpec { } } - new AnyRef { + object AtLeastOnce { //#at-least-once-example import akka.actor.{ Actor, ActorPath } import akka.persistence.AtLeastOnceDelivery @@ -145,7 +144,7 @@ trait PersistenceDocSpec { //#at-least-once-example } - new AnyRef { + object SaveSnapshot { class MyPersistentActor extends PersistentActor { override def persistenceId = "my-stable-persistence-id" @@ -164,7 +163,7 @@ trait PersistenceDocSpec { } } - new AnyRef { + object OfferSnapshot { class MyPersistentActor extends PersistentActor { override def persistenceId = "my-stable-persistence-id" @@ -183,8 +182,6 @@ trait PersistenceDocSpec { import akka.actor.Props - val persistentActor = system.actorOf(Props[MyPersistentActor]) - //#snapshot-criteria persistentActor ! Recover(fromSnapshot = SnapshotSelectionCriteria( maxSequenceNr = 457L, @@ -192,9 +189,7 @@ trait PersistenceDocSpec { //#snapshot-criteria } - new AnyRef { - - val persistentActor = system.actorOf(Props[MyPersistentActor]()) + object PersistAsync { //#persist-async class MyPersistentActor extends PersistentActor { @@ -228,9 +223,8 @@ trait PersistenceDocSpec { //#persist-async } - new AnyRef { - val persistentActor = system.actorOf(Props[MyPersistentActor]()) + object Defer { //#defer class MyPersistentActor extends PersistentActor { @@ -268,9 +262,12 @@ trait PersistenceDocSpec { //#defer-caller } - new AnyRef { + + object View { import akka.actor.Props + val system: ActorSystem = ??? + //#view class MyView extends PersistentView { override def persistenceId: String = "some-persistence-id" diff --git a/akka-osgi/src/main/scala/akka/osgi/DefaultOSGiLogger.scala b/akka-osgi/src/main/scala/akka/osgi/DefaultOSGiLogger.scala index d2af5f5042..028f3042fc 100644 --- a/akka-osgi/src/main/scala/akka/osgi/DefaultOSGiLogger.scala +++ b/akka-osgi/src/main/scala/akka/osgi/DefaultOSGiLogger.scala @@ -17,7 +17,7 @@ class DefaultOSGiLogger extends DefaultLogger { val messageFormat = " %s | %s | %s | %s" - override def receive: Receive = uninitialisedReceive orElse super.receive + override def receive: Receive = uninitialisedReceive.orElse[Any, Unit](super.receive) /** * Behaviour of the logger that waits for its LogService diff --git a/akka-persistence/src/test/scala/akka/persistence/SnapshotSpec.scala b/akka-persistence/src/test/scala/akka/persistence/SnapshotSpec.scala index dfca6a7b76..7f6c096b98 100644 --- a/akka-persistence/src/test/scala/akka/persistence/SnapshotSpec.scala +++ b/akka-persistence/src/test/scala/akka/persistence/SnapshotSpec.scala @@ -14,8 +14,8 @@ object SnapshotSpec { var state = List.empty[String] override def receiveRecover: Receive = { - case payload: String ⇒ state = s"${payload}-${lastSequenceNr}" :: state - case SnapshotOffer(_, snapshot: List[String]) ⇒ state = snapshot + case payload: String ⇒ state = s"${payload}-${lastSequenceNr}" :: state + case SnapshotOffer(_, snapshot: List[_]) ⇒ state = snapshot.asInstanceOf[List[String]] } override def receiveCommand = { diff --git a/akka-slf4j/src/test/scala/akka/event/slf4j/Slf4jLoggerSpec.scala b/akka-slf4j/src/test/scala/akka/event/slf4j/Slf4jLoggerSpec.scala index 5db4f3745c..e88b862253 100644 --- a/akka-slf4j/src/test/scala/akka/event/slf4j/Slf4jLoggerSpec.scala +++ b/akka-slf4j/src/test/scala/akka/event/slf4j/Slf4jLoggerSpec.scala @@ -26,6 +26,8 @@ object Slf4jLoggerSpec { } """ + case class StringWithMDC(s: String, mdc: Map[String, Any]) + class LogProducer extends Actor with DiagnosticActorLogging { def receive = { @@ -33,7 +35,7 @@ object Slf4jLoggerSpec { log.error(e, e.getMessage) case (s: String, x: Int, y: Int) ⇒ log.info(s, x, y) - case (s: String, mdc: Map[String, Any]) ⇒ + case StringWithMDC(s, mdc) ⇒ log.mdc(mdc) log.info(s) log.clearMDC() @@ -96,7 +98,7 @@ class Slf4jLoggerSpec extends AkkaSpec(Slf4jLoggerSpec.config) with BeforeAndAft } "put custom MDC values when specified" in { - producer ! ("Message with custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> "Custom MDC Values")) + producer ! StringWithMDC("Message with custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> "Custom MDC Values")) awaitCond(outputString.contains("----"), 5 seconds) val s = outputString @@ -109,7 +111,7 @@ class Slf4jLoggerSpec extends AkkaSpec(Slf4jLoggerSpec.config) with BeforeAndAft } "Support null values in custom MDC" in { - producer ! ("Message with null custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> null)) + producer ! StringWithMDC("Message with null custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> null)) awaitCond(outputString.contains("----"), 5 seconds) val s = outputString diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index 81c16e596b..d1b56ec30b 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -287,17 +287,17 @@ object AkkaBuild extends Build { pomIncludeRepository := (_ => false) // do not leak internal repositories during staging ) - private def deprecation: Boolean = System.getProperty("akka.deprecation", "false").toBoolean + private def allWarnings: Boolean = System.getProperty("akka.allwarnings", "false").toBoolean lazy val defaultSettings = baseSettings ++ resolverSettings ++ TestExtras.Filter.settings ++ Protobuf.settings ++ Seq( // compile options scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"), - scalacOptions in Compile ++= (if (deprecation) Seq("-deprecation") else Nil), + scalacOptions in Compile ++= (if (allWarnings) Seq("-deprecation") else Nil), scalacOptions in Test := (scalacOptions in Test).value.filterNot(_ == "-Xlog-reflective-calls"), // -XDignore.symbol.file suppresses sun.misc.Unsafe warnings javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-XDignore.symbol.file"), - javacOptions in compile ++= (if (deprecation) Seq("-Xlint:deprecation") else Nil), + javacOptions in compile ++= (if (allWarnings) Seq("-Xlint:deprecation") else Nil), javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.6"), incOptions := incOptions.value.withNameHashing(true),