Use Props factory methods in getting started tutorial (#25713)

* Use Props factory methods in getting started tutorial

* deprecate Props.create without actorClass parameter, #25718
This commit is contained in:
Patrik Nordwall 2018-10-15 18:12:41 +02:00 committed by Christopher Batey
parent 4b012cc306
commit b89a7e5df5
17 changed files with 77 additions and 34 deletions

View file

@ -72,7 +72,7 @@ class MyEventsByTagJavaPublisher extends AbstractActorPublisher<EventEnvelope> {
public static Props props(Connection conn, String tag, Long offset,
Duration refreshInterval) {
return Props.create(() ->
return Props.create(MyEventsByTagJavaPublisher.class, () ->
new MyEventsByTagJavaPublisher(conn, tag, offset, refreshInterval));
}

View file

@ -195,7 +195,7 @@ public class ParentChildTest extends AbstractJavaTest {
// didn't put final on these in order to make the parent fit in one line in the html docs
//#test-fabricated-parent
TestProbe proxy = new TestProbe(system);
ActorRef parent = system.actorOf(Props.create(new FabricatedParentCreator(proxy)));
ActorRef parent = system.actorOf(Props.create(Actor.class, new FabricatedParentCreator(proxy)));
proxy.send(parent, "ping");
proxy.expectMsg("pong");

View file

@ -21,6 +21,10 @@ import akka.actor.ActorSystem;
import akka.actor.Props;
class PrintMyActorRefActor extends AbstractActor {
static Props props() {
return Props.create(PrintMyActorRefActor.class, PrintMyActorRefActor::new);
}
@Override
public Receive createReceive() {
return receiveBuilder()
@ -35,10 +39,14 @@ class PrintMyActorRefActor extends AbstractActor {
//#start-stop
class StartStopActor1 extends AbstractActor {
static Props props() {
return Props.create(StartStopActor1.class, StartStopActor1::new);
}
@Override
public void preStart() {
System.out.println("first started");
getContext().actorOf(Props.create(StartStopActor2.class), "second");
getContext().actorOf(StartStopActor2.props(), "second");
}
@Override
@ -57,6 +65,11 @@ class StartStopActor1 extends AbstractActor {
}
class StartStopActor2 extends AbstractActor {
static Props props() {
return Props.create(StartStopActor2.class, StartStopActor2::new);
}
@Override
public void preStart() {
System.out.println("second started");
@ -79,7 +92,11 @@ class StartStopActor2 extends AbstractActor {
//#supervise
class SupervisingActor extends AbstractActor {
ActorRef child = getContext().actorOf(Props.create(SupervisedActor.class), "supervised-actor");
static Props props() {
return Props.create(SupervisingActor.class, SupervisingActor::new);
}
ActorRef child = getContext().actorOf(SupervisedActor.props(), "supervised-actor");
@Override
public Receive createReceive() {
@ -92,6 +109,10 @@ class SupervisingActor extends AbstractActor {
}
class SupervisedActor extends AbstractActor {
static Props props() {
return Props.create(SupervisedActor.class, SupervisedActor::new);
}
@Override
public void preStart() {
System.out.println("supervised actor started");
@ -119,7 +140,7 @@ public class ActorHierarchyExperiments {
public static void main(String[] args) throws java.io.IOException {
ActorSystem system = ActorSystem.create("testSystem");
ActorRef firstRef = system.actorOf(Props.create(PrintMyActorRefActor.class), "first-actor");
ActorRef firstRef = system.actorOf(PrintMyActorRefActor.props(), "first-actor");
System.out.println("First: " + firstRef);
firstRef.tell("printit", ActorRef.noSender());
@ -151,7 +172,7 @@ class ActorHierarchyExperimentsTest extends JUnitSuite {
@Test
public void testStartAndStopActors() {
//#start-stop-main
ActorRef first = system.actorOf(Props.create(StartStopActor1.class), "first");
ActorRef first = system.actorOf(StartStopActor1.props(), "first");
first.tell("stop", ActorRef.noSender());
//#start-stop-main
}
@ -159,7 +180,7 @@ class ActorHierarchyExperimentsTest extends JUnitSuite {
@Test
public void testSuperviseActors() {
//#supervise-main
ActorRef supervisingActor = system.actorOf(Props.create(SupervisingActor.class), "supervising-actor");
ActorRef supervisingActor = system.actorOf(SupervisingActor.props(), "supervising-actor");
supervisingActor.tell("failChild", ActorRef.noSender());
//#supervise-main
}

View file

@ -15,7 +15,7 @@ public class IotSupervisor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public static Props props() {
return Props.create(IotSupervisor.class);
return Props.create(IotSupervisor.class, IotSupervisor::new);
}
@Override

View file

@ -27,7 +27,7 @@ public class Device extends AbstractActor {
}
public static Props props(String groupId, String deviceId) {
return Props.create(Device.class, groupId, deviceId);
return Props.create(Device.class, () -> new Device(groupId, deviceId));
}
public static final class RecordTemperature {

View file

@ -26,7 +26,7 @@ class Device extends AbstractActor {
}
public static Props props(String groupId, String deviceId) {
return Props.create(Device.class, groupId, deviceId);
return Props.create(Device.class, () -> new Device(groupId, deviceId));
}
//#read-protocol-2

View file

@ -29,7 +29,7 @@ public class Device extends AbstractActor {
}
public static Props props(String groupId, String deviceId) {
return Props.create(Device.class, groupId, deviceId);
return Props.create(Device.class, () -> new Device(groupId, deviceId));
}
public static final class RecordTemperature {

View file

@ -31,7 +31,7 @@ public class DeviceGroup extends AbstractActor {
}
public static Props props(String groupId) {
return Props.create(DeviceGroup.class, groupId);
return Props.create(DeviceGroup.class, () -> new DeviceGroup(groupId));
}
//#device-group-register
//#device-group-remove

View file

@ -19,7 +19,7 @@ public class DeviceManager extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public static Props props() {
return Props.create(DeviceManager.class);
return Props.create(DeviceManager.class, DeviceManager::new);
}
//#device-manager-msgs

View file

@ -27,7 +27,7 @@ public class Device extends AbstractActor {
}
public static Props props(String groupId, String deviceId) {
return Props.create(Device.class, groupId, deviceId);
return Props.create(Device.class, () -> new Device(groupId, deviceId));
}
public static final class RecordTemperature {

View file

@ -28,7 +28,7 @@ public class DeviceGroup extends AbstractActor {
}
public static Props props(String groupId) {
return Props.create(DeviceGroup.class, groupId);
return Props.create(DeviceGroup.class, () -> new DeviceGroup(groupId));
}
public static final class RequestDeviceList {

View file

@ -45,7 +45,7 @@ public class DeviceGroupQuery extends AbstractActor {
}
public static Props props(Map<ActorRef, String> actorToDeviceId, long requestId, ActorRef requester, FiniteDuration timeout) {
return Props.create(DeviceGroupQuery.class, actorToDeviceId, requestId, requester, timeout);
return Props.create(DeviceGroupQuery.class, () -> new DeviceGroupQuery(actorToDeviceId, requestId, requester, timeout));
}
@Override

View file

@ -18,7 +18,7 @@ public class DeviceManager extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public static Props props() {
return Props.create(DeviceManager.class);
return Props.create(DeviceManager.class, DeviceManager::new);
}
public static final class RequestTrackDevice {