Move content from akka-docs-new into akka-docs
Now the paradox documentation is no longer functional until we update akka-docs to generate from paradox instead of sphinx
This commit is contained in:
parent
f064d1321a
commit
5507147073
96 changed files with 0 additions and 35 deletions
80
akka-docs/src/test/java/jdocs/tutorial_4/DeviceManager.java
Normal file
80
akka-docs/src/test/java/jdocs/tutorial_4/DeviceManager.java
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package jdocs.tutorial_4;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.Props;
|
||||
import akka.actor.Terminated;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceManager extends AbstractActor {
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
public static Props props() {
|
||||
return Props.create(DeviceManager.class);
|
||||
}
|
||||
|
||||
public static final class RequestTrackDevice {
|
||||
public final String groupId;
|
||||
public final String deviceId;
|
||||
|
||||
public RequestTrackDevice(String groupId, String deviceId) {
|
||||
this.groupId = groupId;
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class DeviceRegistered {
|
||||
}
|
||||
|
||||
final Map<String, ActorRef> groupIdToActor = new HashMap<>();
|
||||
final Map<ActorRef, String> actorToGroupId = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void preStart() {
|
||||
log.info("DeviceManager started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStop() {
|
||||
log.info("DeviceManager stopped");
|
||||
}
|
||||
|
||||
private void onTrackDevice(RequestTrackDevice trackMsg) {
|
||||
String groupId = trackMsg.groupId;
|
||||
ActorRef ref = groupIdToActor.get(groupId);
|
||||
if (ref != null) {
|
||||
ref.forward(trackMsg, getContext());
|
||||
} else {
|
||||
log.info("Creating device group actor for {}", groupId);
|
||||
ActorRef groupActor = getContext().actorOf(DeviceGroup.props(groupId), "group-" + groupId);
|
||||
getContext().watch(groupActor);
|
||||
groupActor.forward(trackMsg, getContext());
|
||||
groupIdToActor.put(groupId, groupActor);
|
||||
actorToGroupId.put(groupActor, groupId);
|
||||
}
|
||||
}
|
||||
|
||||
private void onTerminated(Terminated t) {
|
||||
ActorRef groupActor = t.getActor();
|
||||
String groupId = actorToGroupId.get(groupActor);
|
||||
log.info("Device group actor for {} has been terminated", groupId);
|
||||
actorToGroupId.remove(groupActor);
|
||||
groupIdToActor.remove(groupId);
|
||||
}
|
||||
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(RequestTrackDevice.class, this::onTrackDevice)
|
||||
.match(Terminated.class, this::onTerminated)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue