diff --git a/akka-actor/src/main/java/akka/japi/pf/Match.java b/akka-actor/src/main/java/akka/japi/pf/Match.java
index d18e854b14..c7ef9ee0c6 100644
--- a/akka-actor/src/main/java/akka/japi/pf/Match.java
+++ b/akka-actor/src/main/java/akka/japi/pf/Match.java
@@ -121,7 +121,7 @@ public class Match extends AbstractMatch {
*
*
*
- * Matcher<X, Y> matcher = Matcher.create(...);
+ * Match<X, Y> matcher = Match.create(...);
*
* Y someY = matcher.match(obj);
*
diff --git a/akka-actor/src/main/scala/akka/actor/Actor.scala b/akka-actor/src/main/scala/akka/actor/Actor.scala
index 59abb36f71..0e963d3a82 100644
--- a/akka-actor/src/main/scala/akka/actor/Actor.scala
+++ b/akka-actor/src/main/scala/akka/actor/Actor.scala
@@ -542,7 +542,7 @@ trait Actor {
* Actors are automatically started asynchronously when created.
* Empty default implementation.
*/
- @throws(classOf[Exception]) // when changing this you MUST also change UntypedActorDocTest
+ @throws(classOf[Exception]) // when changing this you MUST also change ActorDocTest
//#lifecycle-hooks
def preStart(): Unit = ()
@@ -554,7 +554,7 @@ trait Actor {
* Is called asynchronously after 'actor.stop()' is invoked.
* Empty default implementation.
*/
- @throws(classOf[Exception]) // when changing this you MUST also change UntypedActorDocTest
+ @throws(classOf[Exception]) // when changing this you MUST also change ActorDocTest
//#lifecycle-hooks
def postStop(): Unit = ()
@@ -568,7 +568,7 @@ trait Actor {
* Is called on a crashed Actor right BEFORE it is restarted to allow clean
* up of resources before Actor is terminated.
*/
- @throws(classOf[Exception]) // when changing this you MUST also change UntypedActorDocTest
+ @throws(classOf[Exception]) // when changing this you MUST also change ActorDocTest
//#lifecycle-hooks
def preRestart(reason: Throwable, message: Option[Any]): Unit = {
context.children foreach { child ⇒
@@ -586,7 +586,7 @@ trait Actor {
*
* Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash.
*/
- @throws(classOf[Exception]) // when changing this you MUST also change UntypedActorDocTest
+ @throws(classOf[Exception]) // when changing this you MUST also change ActorDocTest
//#lifecycle-hooks
def postRestart(reason: Throwable): Unit = {
preStart()
diff --git a/akka-actor/src/main/scala/akka/actor/ActorCell.scala b/akka-actor/src/main/scala/akka/actor/ActorCell.scala
index 925fc9ff14..4fa5428cf2 100644
--- a/akka-actor/src/main/scala/akka/actor/ActorCell.scala
+++ b/akka-actor/src/main/scala/akka/actor/ActorCell.scala
@@ -166,7 +166,7 @@ trait ActorContext extends ActorRefFactory {
* UntypedActorContext is the UntypedActor equivalent of ActorContext,
* containing the Java API
*/
-@deprecated("Use AbstractActor instead of UntypedActor.", since = "2.5.0")
+@deprecated("Use AbstractActor.ActorContext instead of UntypedActorContext.", since = "2.5.0")
trait UntypedActorContext extends ActorContext {
/**
diff --git a/akka-actor/src/main/scala/akka/actor/UntypedActorWithStash.scala b/akka-actor/src/main/scala/akka/actor/UntypedActorWithStash.scala
index 20fc03bb0d..f460306ab4 100644
--- a/akka-actor/src/main/scala/akka/actor/UntypedActorWithStash.scala
+++ b/akka-actor/src/main/scala/akka/actor/UntypedActorWithStash.scala
@@ -44,14 +44,14 @@ package akka.actor
* There is also an unrestricted version [[akka.actor.UntypedActorWithUnrestrictedStash]] that does not
* enforce the mailbox type.
*/
-@deprecated("Use AbstractActor instead of UntypedActor.", since = "2.5.0")
+@deprecated("Use AbstractActorWithStash instead of UntypedActorWithStash.", since = "2.5.0")
abstract class UntypedActorWithStash extends UntypedActor with Stash
/**
* Actor base class with `Stash` that enforces an unbounded deque for the actor.
* See [[akka.actor.UntypedActorWithStash]] for details on how `Stash` works.
*/
-@deprecated("Use AbstractActor instead of UntypedActor.", since = "2.5.0")
+@deprecated("Use AbstractActorWithUnboundedStash instead of UntypedActorWithUnboundedStash.", since = "2.5.0")
abstract class UntypedActorWithUnboundedStash extends UntypedActor with UnboundedStash
/**
@@ -59,5 +59,5 @@ abstract class UntypedActorWithUnboundedStash extends UntypedActor with Unbounde
* manually, and the mailbox should extend the [[akka.dispatch.DequeBasedMessageQueueSemantics]] marker trait.
* See [[akka.actor.UntypedActorWithStash]] for details on how `Stash` works.
*/
-@deprecated("Use AbstractActor instead of UntypedActor.", since = "2.5.0")
+@deprecated("Use AbstractActorWithUnrestrictedStash instead of UntypedActorWithUnrestrictedStash.", since = "2.5.0")
abstract class UntypedActorWithUnrestrictedStash extends UntypedActor with UnrestrictedStash
diff --git a/akka-contrib/src/test/java/akka/contrib/pattern/ReliableProxyTest.java b/akka-contrib/src/test/java/akka/contrib/pattern/ReliableProxyTest.java
index 0ab90178d0..0552751ba9 100644
--- a/akka-contrib/src/test/java/akka/contrib/pattern/ReliableProxyTest.java
+++ b/akka-contrib/src/test/java/akka/contrib/pattern/ReliableProxyTest.java
@@ -31,7 +31,7 @@ public class ReliableProxyTest extends JUnitSuite {
private final ActorSystem system = actorSystemResource.getSystem();
static//#demo-proxy
- public class ProxyParent extends UntypedActor {
+ public class ProxyParent extends AbstractActor {
private final ActorRef proxy;
public ProxyParent(ActorPath targetPath) {
@@ -40,17 +40,20 @@ public class ReliableProxyTest extends JUnitSuite {
Duration.create(100, TimeUnit.MILLISECONDS)));
}
- public void onReceive(Object msg) {
- if ("hello".equals(msg)) {
- proxy.tell("world!", getSelf());
- }
+ @Override
+ public Receive createReceive() {
+ return receiveBuilder()
+ .matchEquals("hello", m -> {
+ proxy.tell("world!", self());
+ })
+ .build();
}
}
//#demo-proxy
static//#demo-transition
- public class ProxyTransitionParent extends UntypedActor {
+ public class ProxyTransitionParent extends AbstractActor {
private final ActorRef proxy;
private ActorRef client = null;
@@ -61,22 +64,24 @@ public class ReliableProxyTest extends JUnitSuite {
proxy.tell(new FSM.SubscribeTransitionCallBack(getSelf()), getSelf());
}
- public void onReceive(Object msg) {
- if ("hello".equals(msg)) {
- proxy.tell("world!", getSelf());
- client = getSender();
- } else if (msg instanceof FSM.CurrentState>) {
- // get initial state
- } else if (msg instanceof FSM.Transition>) {
- @SuppressWarnings("unchecked")
- final FSM.Transition transition =
- (FSM.Transition) msg;
- assert transition.fsmRef().equals(proxy);
- if (transition.from().equals(ReliableProxy.active()) &&
- transition.to().equals(ReliableProxy.idle())) {
- client.tell("done", getSelf());
- }
- }
+ @Override
+ public Receive createReceive() {
+ return receiveBuilder()
+ .matchEquals("hello", message -> {
+ proxy.tell("world!", self());
+ client = sender();
+ })
+ .matchUnchecked(FSM.CurrentState.class, (FSM.CurrentState state) -> {
+ // get initial state
+ })
+ .matchUnchecked(FSM.Transition.class, (FSM.Transition transition) -> {
+ assert transition.fsmRef().equals(proxy);
+ if (transition.from().equals(ReliableProxy.active()) &&
+ transition.to().equals(ReliableProxy.idle())) {
+ client.tell("done", self());
+ }
+ })
+ .build();
}
}
diff --git a/akka-contrib/src/test/java/akka/contrib/throttle/TimerBasedThrottlerTest.java b/akka-contrib/src/test/java/akka/contrib/throttle/TimerBasedThrottlerTest.java
index abf7da484e..081211c62d 100644
--- a/akka-contrib/src/test/java/akka/contrib/throttle/TimerBasedThrottlerTest.java
+++ b/akka-contrib/src/test/java/akka/contrib/throttle/TimerBasedThrottlerTest.java
@@ -15,8 +15,7 @@ import com.typesafe.config.ConfigFactory;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
-import akka.actor.UntypedActor;
-import akka.contrib.throttle.TimerBasedThrottler;
+import akka.actor.AbstractActor;
import akka.testkit.AkkaJUnitActorSystemResource;
public class TimerBasedThrottlerTest extends JUnitSuite {
@@ -51,10 +50,14 @@ public class TimerBasedThrottlerTest extends JUnitSuite {
static//#demo-code
//A simple actor that prints whatever it receives
- public class Printer extends UntypedActor {
+ public class Printer extends AbstractActor {
@Override
- public void onReceive(Object msg) {
- System.out.println(msg);
+ public Receive createReceive() {
+ return receiveBuilder()
+ .matchAny(message -> {
+ System.out.println(message);
+ })
+ .build();
}
}
diff --git a/akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java b/akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java
index 051d22fefe..fd607a8525 100644
--- a/akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java
+++ b/akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java
@@ -2,7 +2,7 @@ package docs.io;
import akka.actor.ActorRef;
import akka.actor.Props;
-import akka.actor.UntypedActor;
+import akka.actor.AbstractActor;
import akka.io.Inet;
import akka.io.Tcp;
import akka.io.TcpMessage;
@@ -17,23 +17,26 @@ import java.util.List;
*/
public class JavaReadBackPressure {
- static public class Listener extends UntypedActor {
+ static public class Listener extends AbstractActor {
ActorRef tcp;
ActorRef listener;
@Override
//#pull-accepting
- public void onReceive(Object message) throws Exception {
- if (message instanceof Tcp.Bound) {
- listener = sender();
- // Accept connections one by one
- listener.tell(TcpMessage.resumeAccepting(1), self());
- } else if (message instanceof Tcp.Connected) {
- ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, sender()));
- sender().tell(TcpMessage.register(handler), self());
- // Resume accepting connections
- listener.tell(TcpMessage.resumeAccepting(1), self());
- }
+ public Receive createReceive() {
+ return receiveBuilder()
+ .match(Tcp.Bound.class, x -> {
+ listener = sender();
+ // Accept connections one by one
+ listener.tell(TcpMessage.resumeAccepting(1), self());
+ })
+ .match(Tcp.Connected.class, x -> {
+ ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, sender()));
+ sender().tell(TcpMessage.register(handler), self());
+ // Resume accepting connections
+ listener.tell(TcpMessage.resumeAccepting(1), self());
+ })
+ .build();
}
//#pull-accepting
@@ -63,7 +66,7 @@ public class JavaReadBackPressure {
static public class Ack implements Tcp.Event {
}
- static public class PullEcho extends UntypedActor {
+ static public class PullEcho extends AbstractActor {
final ActorRef connection;
public PullEcho(ActorRef connection) {
@@ -77,17 +80,18 @@ public class JavaReadBackPressure {
}
@Override
- public void onReceive(Object message) throws Exception {
- if (message instanceof Tcp.Received) {
- ByteString data = ((Tcp.Received) message).data();
- connection.tell(TcpMessage.write(data, new Ack()), self());
- } else if (message instanceof Ack) {
- connection.tell(TcpMessage.resumeReading(), self());
- }
+ public Receive createReceive() {
+ return receiveBuilder()
+ .match(Tcp.Received.class, message -> {
+ ByteString data = message.data();
+ connection.tell(TcpMessage.write(data, new Ack()), self());
+ })
+ .match(Ack.class, message -> {
+ connection.tell(TcpMessage.resumeReading(), self());
+ })
+ .build();
}
//#pull-reading-echo
-
-
}
}
diff --git a/akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java b/akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java
index 2817d33898..626c051f94 100644
--- a/akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java
+++ b/akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java
@@ -6,7 +6,7 @@ package docs.io;
//#imports
import akka.actor.ActorRef;
-import akka.actor.UntypedActor;
+import akka.actor.AbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import akka.io.Inet;
@@ -57,7 +57,7 @@ public class JavaUdpMulticast {
}
//#multicast-group
- public static class Listener extends UntypedActor {
+ public static class Listener extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
ActorRef sink;
@@ -78,21 +78,22 @@ public class JavaUdpMulticast {
}
@Override
- public void onReceive(Object msg) {
- if (msg instanceof Udp.Bound) {
- final Udp.Bound b = (Udp.Bound) msg;
- log.info("Bound to {}", b.localAddress());
- sink.tell(b, self());
- } else if (msg instanceof Udp.Received) {
- final Udp.Received r = (Udp.Received) msg;
- final String txt = r.data().decodeString("utf-8");
- log.info("Received '{}' from {}", txt, r.sender());
- sink.tell(txt, self());
- } else unhandled(msg);
+ public Receive createReceive() {
+ return receiveBuilder()
+ .match(Udp.Bound.class, bound -> {
+ log.info("Bound to {}", bound.localAddress());
+ sink.tell(bound, self());
+ })
+ .match(Udp.Received.class, received -> {
+ final String txt = received.data().decodeString("utf-8");
+ log.info("Received '{}' from {}", txt, received.sender());
+ sink.tell(txt, self());
+ })
+ .build();
}
}
- public static class Sender extends UntypedActor {
+ public static class Sender extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
String iface;
@@ -114,12 +115,14 @@ public class JavaUdpMulticast {
}
@Override
- public void onReceive(Object msg) {
- if (msg instanceof Udp.SimpleSenderReady) {
- InetSocketAddress remote = new InetSocketAddress(group + "%" + iface, port);
- log.info("Sending message to " + remote);
- sender().tell(UdpMessage.send(ByteString.fromString(message), remote), self());
- } else unhandled(msg);
+ public Receive createReceive() {
+ return receiveBuilder()
+ .match(Udp.SimpleSenderReady.class, x -> {
+ InetSocketAddress remote = new InetSocketAddress(group + "%" + iface, port);
+ log.info("Sending message to " + remote);
+ sender().tell(UdpMessage.send(ByteString.fromString(message), remote), self());
+ })
+ .build();
}
}
}
diff --git a/akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java b/akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java
index f9ad8d8642..dec0e8bea4 100644
--- a/akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java
+++ b/akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java
@@ -4,12 +4,11 @@
package docs.io;
-import akka.testkit.AkkaJUnitActorSystemResource;
-import org.junit.ClassRule;
+import akka.japi.pf.ReceiveBuilder;
import org.junit.Test;
import akka.actor.ActorSystem;
-import akka.actor.UntypedActor;
+import akka.actor.AbstractActor;
//#imports
import java.net.InetSocketAddress;
import java.util.ArrayList;
@@ -24,14 +23,15 @@ import akka.util.ByteString;
public class UdpConnectedDocTest {
- static public class Demo extends UntypedActor {
+ static public class Demo extends AbstractActor {
ActorRef connectionActor = null;
ActorRef handler = self();
ActorSystem system = getContext().system();
@Override
- public void onReceive(Object msg) {
- if ("connect".equals(msg)) {
+ public Receive createReceive() {
+ ReceiveBuilder builder = receiveBuilder();
+ builder.matchEquals("connect", message -> {
//#manager
final ActorRef udp = UdpConnected.get(system).manager();
//#manager
@@ -48,34 +48,33 @@ public class UdpConnectedDocTest {
options.add(UdpSO.broadcast(true));
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr, localAddr, options), self());
//#connect-with-options
- } else
- //#connected
- if (msg instanceof UdpConnected.Connected) {
- final UdpConnected.Connected conn = (UdpConnected.Connected) msg;
- connectionActor = sender(); // Save the worker ref for later use
- }
- //#connected
- else
- //#received
- if (msg instanceof UdpConnected.Received) {
- final UdpConnected.Received recv = (UdpConnected.Received) msg;
- final ByteString data = recv.data();
- // and do something with the received data ...
- } else if (msg instanceof UdpConnected.CommandFailed) {
- final UdpConnected.CommandFailed failed = (UdpConnected.CommandFailed) msg;
- final UdpConnected.Command command = failed.cmd();
- // react to failed connect, etc.
- } else if (msg instanceof UdpConnected.Disconnected) {
- // do something on disconnect
- }
- //#received
- else
- if ("send".equals(msg)) {
- ByteString data = ByteString.empty();
- //#send
- connectionActor.tell(UdpConnectedMessage.send(data), self());
- //#send
- }
+ });
+ //#connected
+ builder.match(UdpConnected.Connected.class, conn -> {
+ connectionActor = sender(); // Save the worker ref for later use
+ });
+ //#connected
+ //#received
+ builder
+ .match(UdpConnected.Received.class, recv -> {
+ final ByteString data = recv.data();
+ // and do something with the received data ...
+ })
+ .match(UdpConnected.CommandFailed.class, failed -> {
+ final UdpConnected.Command command = failed.cmd();
+ // react to failed connect, etc.
+ })
+ .match(UdpConnected.Disconnected.class, x -> {
+ // do something on disconnect
+ });
+ //#received
+ builder.matchEquals("send", x -> {
+ ByteString data = ByteString.empty();
+ //#send
+ connectionActor.tell(UdpConnectedMessage.send(data), self());
+ //#send
+ });
+ return builder.build();
}
}
diff --git a/akka-docs/rst/java/code/docs/io/UdpDocTest.java b/akka-docs/rst/java/code/docs/io/UdpDocTest.java
index 7b5cd2d540..a67b4b06cf 100644
--- a/akka-docs/rst/java/code/docs/io/UdpDocTest.java
+++ b/akka-docs/rst/java/code/docs/io/UdpDocTest.java
@@ -7,7 +7,7 @@ package docs.io;
//#imports
import akka.actor.ActorRef;
import akka.actor.PoisonPill;
-import akka.actor.UntypedActor;
+import akka.actor.AbstractActor;
import akka.io.Udp;
import akka.io.UdpConnected;
import akka.io.UdpConnectedMessage;
@@ -21,7 +21,7 @@ import java.net.InetSocketAddress;
public class UdpDocTest {
//#sender
- public static class SimpleSender extends UntypedActor {
+ public static class SimpleSender extends AbstractActor {
final InetSocketAddress remote;
public SimpleSender(InetSocketAddress remote) {
@@ -33,37 +33,34 @@ public class UdpDocTest {
}
@Override
- public void onReceive(Object msg) {
- if (msg instanceof Udp.SimpleSenderReady) {
- getContext().become(ready(sender()));
- //#sender
- sender().tell(UdpMessage.send(ByteString.fromString("hello"), remote), self());
- //#sender
- } else unhandled(msg);
+ public Receive createReceive() {
+ return receiveBuilder()
+ .match(Udp.SimpleSenderReady.class, message -> {
+ getContext().become(ready(sender()));
+ //#sender
+ sender().tell(UdpMessage.send(ByteString.fromString("hello"), remote), self());
+ //#sender
+ })
+ .build();
}
-
- private Procedure