diff --git a/java/food-ordering/README.md b/java/food-ordering/README.md index 545985c1..bff99915 100644 --- a/java/food-ordering/README.md +++ b/java/food-ordering/README.md @@ -20,6 +20,12 @@ WebUI is running at http://localhost:3000 Jaeger is running at http://localhost:16686 +When you are making changes to the code, and you want to trigger a build of the Docker images: + +```shell +docker compose build --no-cache +``` + Clean up after bringing setup down: ```shell docker compose rm diff --git a/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/DriverDigitalTwin.java b/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/DriverDigitalTwin.java index c041e98c..318686fc 100644 --- a/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/DriverDigitalTwin.java +++ b/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/DriverDigitalTwin.java @@ -18,8 +18,8 @@ /** * Digital twin for the driver. Represents a driver and his status, assigned delivery, and location. - * Keyed by driver ID. The actual driver would have an application (mocked by DriverSimService) that - * calls this service. + * Keyed by driver ID. The actual driver would have an application (mocked by DriverMobileAppSimulator + * ) that calls this service. */ public class DriverDigitalTwin extends DriverDigitalTwinRestate.DriverDigitalTwinRestateImplBase { @@ -36,7 +36,7 @@ public class DriverDigitalTwin extends DriverDigitalTwinRestate.DriverDigitalTwi StateKey.of("driver-location", JacksonSerdes.of(Location.class)); /** - * When the driver starts his work day or finishes a delivery, his application (DriverSimService) + * When the driver starts his work day or finishes a delivery, his application (DriverMobileAppSimulator) * calls this method. */ @Override @@ -55,7 +55,7 @@ public void setDriverAvailable(RestateContext ctx, OrderProto.DriverAvailableNot } /** - * Gets called by the delivery service when this driver was assigned to do the delivery. Updates + * Gets called by the delivery manager when this driver was assigned to do the delivery. Updates * the status of the digital driver twin, and notifies the delivery service of its current * location. */ @@ -106,13 +106,15 @@ public void notifyDeliveryPickup(RestateContext ctx, OrderProto.DriverId request currentDelivery.notifyPickup(); ctx.set(ASSIGNED_DELIVERY, currentDelivery); - // Update the status of the delivery in the delivery service + // Update the status of the delivery in the delivery manager DeliveryManagerRestate.newClient(ctx) .oneWay() .notifyDeliveryPickup(toOrderIdProto(currentDelivery.orderId)); } - /** */ + /** + * Gets called by the driver's mobile app when he has delivered the order to the customer. + */ @Override public void notifyDeliveryDelivered(RestateContext ctx, OrderProto.DriverId request) throws TerminalException { diff --git a/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/external/DriverMobileAppSimulator.java b/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/external/DriverMobileAppSimulator.java index 698750cb..4b5d312b 100644 --- a/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/external/DriverMobileAppSimulator.java +++ b/java/food-ordering/app/restate-app/src/main/java/dev/restate/sdk/examples/external/DriverMobileAppSimulator.java @@ -21,7 +21,7 @@ * This would actually be a mobile app that drivers use to accept delivery requests, and to set * themselves as available. * - *

For simplicity, we implemented this with Restate. + * For simplicity, we implemented this with Restate. */ public class DriverMobileAppSimulator extends DriverMobileAppSimulatorRestate.DriverMobileAppSimulatorRestateImplBase { @@ -34,12 +34,14 @@ public class DriverMobileAppSimulator private final long PAUSE_BETWEEN_DELIVERIES = 2000; StateKey CURRENT_LOCATION = - StateKey.of("driversim-location", JacksonSerdes.of(Location.class)); + StateKey.of("current-location", JacksonSerdes.of(Location.class)); StateKey ASSIGNED_DELIVERY = StateKey.of("assigned-delivery", JacksonSerdes.of(AssignedDelivery.class)); - /** */ + /** + * Mimics the driver setting himself to available in the app + */ @Override public void startDriver(RestateContext ctx, OrderProto.DriverId request) throws TerminalException { @@ -74,7 +76,7 @@ public void startDriver(RestateContext ctx, OrderProto.DriverId request) @Override public void pollForWork(RestateContext ctx, OrderProto.DriverId request) throws TerminalException { - var driverSimClnt = DriverMobileAppSimulatorRestate.newClient(ctx); + var thisDriverSim = DriverMobileAppSimulatorRestate.newClient(ctx); // Ask the digital twin of the driver in the food ordering app, if he already got a job assigned var optionalAssignedDelivery = @@ -82,7 +84,7 @@ public void pollForWork(RestateContext ctx, OrderProto.DriverId request) // If there is no job, ask again after a short delay if (optionalAssignedDelivery.hasEmpty()) { - driverSimClnt.delayed(Duration.ofMillis(POLL_INTERVAL)).pollForWork(request); + thisDriverSim.delayed(Duration.ofMillis(POLL_INTERVAL)).pollForWork(request); return; } @@ -98,9 +100,12 @@ public void pollForWork(RestateContext ctx, OrderProto.DriverId request) ctx.set(ASSIGNED_DELIVERY, newAssignedDelivery); // Start moving to the delivery pickup location - driverSimClnt.delayed(Duration.ofMillis(MOVE_INTERVAL)).move(request); + thisDriverSim.delayed(Duration.ofMillis(MOVE_INTERVAL)).move(request); } + /** + * Periodically lets the food ordering app know the new location + */ @Override public void move(RestateContext ctx, OrderProto.DriverId request) throws TerminalException { var thisDriverSim = DriverMobileAppSimulatorRestate.newClient(ctx); diff --git a/java/food-ordering/docker-compose.yaml b/java/food-ordering/docker-compose.yaml index daedee0a..d4621120 100644 --- a/java/food-ordering/docker-compose.yaml +++ b/java/food-ordering/docker-compose.yaml @@ -89,6 +89,7 @@ services: ports: - "9070:9070" - "9071:9071" + - "9072:9072" - "8080:8080" volumes: - ./restate-docker.yaml:/restate.yaml