Skip to content

Commit

Permalink
Started on guide page
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren committed Dec 12, 2023
1 parent ae0f114 commit 9b9f340
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 72 deletions.
3 changes: 2 additions & 1 deletion akka-edge-docs/src/main/paradox/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ the local center to pick up available orders closest to their location.
2. [Coarse Grained Location Replication](guide/2-drone-location-to-cloud-service.md)
3. [Restaurant Deliveries Service](guide/3-restaurant-deliveries-service.md)
4. [Local Drone Delivery Selection](guide/4-local-drone-delivery-selection.md)
5. [Deploying the Services](guide/5-deploying-the-services.md)
5. [Drone Charging Station](guide/5-charging-station.md)
6. [Deploying the Services](guide/6-deploying-the-services.md)

@@@

32 changes: 32 additions & 0 deletions akka-edge-docs/src/main/paradox/guide/5-charging-station.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Drone Charging Station

To showcase active-active replication between edge and cloud we'll now add a @extref[Replicated Event Sourced Entity](akka-projection:grpc-replicated-event-sourcing-transport.html)
in the form of a charging station. The charging stations are created with a location id placing them in one of the
local-drone-control edge services where the entity is replicated. Drones in that location can request to charge in the
charging station, and be charged if there is a free charging slot.

## Charging station entity

The API for creating a replicated event sourced behavior extends the regular event sourced behavior. It accepts three
different commands from the outside `Create` to initialize a charging station, `StartCharging` to start a charging session
for a drone if possible and `GetState` to query the station for its current state. There is also a private `ChargingCompleted`
command that the entity can send to itself.

The `Create` command leads to a `Created` event which is persisted and initialized the charging station.

When a slot is free and a drone requests charging a `ChargingStarted` event is persisted and once charging a drone has
completed a `ChargingCompleted` event is persisted:

Scala
: @@snip [ChargingStation.scala](/samples/grpc/local-drone-control-scala/src/main/scala/charging/ChargingStation.scala) { #commands #events }

Java
: @@snip [ChargingStation.java](/samples/grpc/local-drone-control-java/src/main/java/charging/ChargingStation.java) { #commands #events }



The charging station is a simplified replicated entity in that it doesn't really expect any possible conflicts, stations
are created in the central cloud and replicated to the edge, updates related to drones currently charging in the station
happen at the edge and are replicated to the cloud. Akka replicated event sourcing provides APIs for both CRDTs where
conflicts are automatically handled by the data structure and business domain level conflict resolution. For more details
about see the @extref[Akka documentation](akka:replicated-eventsourcing.html).

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ChargingStation
extends ReplicatedEventSourcedBehavior<
ChargingStation.Command, ChargingStation.Event, ChargingStation.State> {

// commands and replies
// #commands
public interface Command extends CborSerializable {}

public static final class Create implements Command {
Expand Down Expand Up @@ -81,8 +81,9 @@ public CompleteCharging(String droneId) {
this.droneId = droneId;
}
}
// #commands

// events
// #events
public interface Event extends CborSerializable {}

public static final class Created implements Event {
Expand Down Expand Up @@ -125,7 +126,7 @@ public ChargingDrone(String droneId, Instant chargingDone, String replicaId) {
this.replicaId = replicaId;
}
}

// #events
public static final class State implements CborSerializable {
public final int chargingSlots;
public final Set<ChargingDrone> dronesCharging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import scala.math.Ordered.orderingToOrdered

object ChargingStation {

// commands and replies
// #commands
sealed trait Command extends CborSerializable {}
case class Create(
locationId: String,
Expand All @@ -51,15 +51,17 @@ object ChargingStation {
extends Command

private case class CompleteCharging(droneId: String) extends Command
// #commands

// events
// #events
sealed trait Event extends CborSerializable {}
case class Created(locationId: String, chargingSlots: Int) extends Event
case class ChargingStarted(droneId: String, chargeComplete: Instant)
extends Event
with StartChargingResponse

case class ChargingCompleted(droneId: String) extends Event
// #events

case class ChargingDrone(
droneId: String,
Expand Down

0 comments on commit 9b9f340

Please sign in to comment.