Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Local drone control sample in Java #974

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some small issues with jackson fixed
johanandren committed Aug 29, 2023
commit 054e0835902407a0d25b8c0765cc0d22999b2c2d
2 changes: 1 addition & 1 deletion samples/grpc/local-drone-control-java/README.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ Drones interact with the closest control service in the following ways:
* Mark a delivery as completed

The control service interacts with the global cloud service, represented by the separate
restaurant-drone-deliveries-service sample, in the following ways:
restaurant-drone-deliveries-service-java sample, in the following ways:

* Replicates a coarse grained location of each drone to the cloud, at a lower frequency,
only when they change location at a coarse grained grid
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import akka.persistence.typed.state.javadsl.CommandHandler;
import akka.persistence.typed.state.javadsl.DurableStateBehavior;
import akka.persistence.typed.state.javadsl.Effect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.google.rpc.context.AttributeContext;

import java.time.Instant;
@@ -60,6 +61,7 @@ public CompleteDelivery(String deliveryId, ActorRef<StatusReply<Done>> replyTo)
public static final class GetCurrentState implements Command {
public final ActorRef<State> replyTo;

@JsonCreator
public GetCurrentState(ActorRef<State> replyTo) {
this.replyTo = replyTo;
}
@@ -68,7 +70,7 @@ public GetCurrentState(ActorRef<State> replyTo) {



final class State {
public static final class State implements CborSerializable {
public final List<WaitingDelivery> waitingDeliveries;
public final List<DeliveryInProgress> deliveriesInProgress;

Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import akka.persistence.typed.javadsl.Effect;
import akka.persistence.typed.javadsl.EventHandler;
import akka.persistence.typed.javadsl.EventSourcedBehavior;
import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.ArrayList;
import java.util.Arrays;
@@ -49,6 +50,7 @@ interface Event extends CborSerializable {}
public static final class PositionUpdated implements Event {
public final Position position;

@JsonCreator
public PositionUpdated(Position position) {
this.position = position;
}
@@ -57,6 +59,7 @@ public PositionUpdated(Position position) {
public static final class CoarseGrainedLocationChanged implements Event {
public final CoarseGrainedCoordinates coordinates;

@JsonCreator
public CoarseGrainedLocationChanged(CoarseGrainedCoordinates coordinates) {
this.coordinates = coordinates;
}
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public static Behavior<ProjectionBehavior.Command> eventToCloudPushBehavior(Acto
Transformation.empty().registerAsyncEnvelopeMapper(Drone.CoarseGrainedLocationChanged.class, (EventEnvelope<Drone.CoarseGrainedLocationChanged> envelope) -> {
var event = envelope.event();
return CompletableFuture.completedFuture(
Optional.of(local.drones.proto.CoarseDroneLocation.newBuilder().setCoordinates(event.coordinates.toProto())));
Optional.of(local.drones.proto.CoarseDroneLocation.newBuilder().setCoordinates(event.coordinates.toProto()).build()));
});

var eventProducer = EventProducerPush.create(
Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@

public class LocalDroneControlServer {

public static void start( String host,
int port,
ActorSystem<?> system,
DroneService droneService,
DeliveriesQueueService deliveriesQueueService) {
public static void start(String host,
int port,
ActorSystem<?> system,
DroneService droneService,
DeliveriesQueueService deliveriesQueueService) {
var service =
ServiceHandler.concatOrNotFound(
DroneServiceHandlerFactory.create(droneService, system),
@@ -30,7 +30,7 @@ public static void start( String host,
var bound =
Http.get(system)
.newServerAt(host, port)
.bind(service);
.bind(service);

bound.whenComplete((binding, error) -> {
if (error == null) {