Skip to content

Commit

Permalink
Update some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gvdongen committed Jan 11, 2024
1 parent 9c3c29c commit 09bfed1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
6 changes: 6 additions & 0 deletions java/food-ordering/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* This would actually be a mobile app that drivers use to accept delivery requests, and to set
* themselves as available.
*
* <p>For simplicity, we implemented this with Restate.
* For simplicity, we implemented this with Restate.
*/
public class DriverMobileAppSimulator
extends DriverMobileAppSimulatorRestate.DriverMobileAppSimulatorRestateImplBase {
Expand All @@ -34,12 +34,14 @@ public class DriverMobileAppSimulator
private final long PAUSE_BETWEEN_DELIVERIES = 2000;

StateKey<Location> CURRENT_LOCATION =
StateKey.of("driversim-location", JacksonSerdes.of(Location.class));
StateKey.of("current-location", JacksonSerdes.of(Location.class));

StateKey<AssignedDelivery> 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 {
Expand Down Expand Up @@ -74,15 +76,15 @@ 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 =
DriverDigitalTwinRestate.newClient(ctx).getAssignedDelivery(request).await();

// 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;
}

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions java/food-ordering/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ services:
ports:
- "9070:9070"
- "9071:9071"
- "9072:9072"
- "8080:8080"
volumes:
- ./restate-docker.yaml:/restate.yaml
Expand Down

0 comments on commit 09bfed1

Please sign in to comment.