Skip to content

Commit

Permalink
No timers needed anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren committed Dec 14, 2023
1 parent d168ecd commit 096d463
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.TimerScheduler;
import akka.pattern.StatusReply;
import akka.persistence.typed.ReplicaId;
import akka.persistence.typed.javadsl.*;
Expand Down Expand Up @@ -174,28 +173,20 @@ public static Behavior<Command> create(
ReplicatedBehaviors<Command, Event, State> replicatedBehaviors) {
return Behaviors.setup(
(ActorContext<Command> context) ->
Behaviors.withTimers(
(TimerScheduler<Command> timers) ->
replicatedBehaviors.setup(
replicationContext -> {
context
.getLog()
.info(
"Charging Station {} starting up", replicationContext.entityId());
return new ChargingStation(context, replicationContext, timers);
})));
replicatedBehaviors.setup(
replicationContext -> {
context
.getLog()
.info("Charging Station {} starting up", replicationContext.entityId());
return new ChargingStation(context, replicationContext);
}));
}

private final ActorContext<Command> context;
private final TimerScheduler<Command> timers;

public ChargingStation(
ActorContext<Command> context,
ReplicationContext replicationContext,
TimerScheduler<Command> timers) {
public ChargingStation(ActorContext<Command> context, ReplicationContext replicationContext) {
super(replicationContext);
this.context = context;
this.timers = timers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import akka.actor.typed.ActorSystem
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.ActorContext
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.scaladsl.TimerScheduler
import akka.pattern.StatusReply
import akka.persistence.typed.ReplicaId
import akka.persistence.typed.scaladsl.Effect
Expand All @@ -29,7 +28,7 @@ import scala.concurrent.duration._
object ChargingStation {

// commands and replies
sealed trait Command extends CborSerializable {}
sealed trait Command extends CborSerializable
case class Create(
locationId: String,
chargingSlots: Int,
Expand All @@ -52,7 +51,7 @@ object ChargingStation {
extends Command

// events
sealed trait Event extends CborSerializable {}
sealed trait Event extends CborSerializable
case class Created(locationId: String, chargingSlots: Int) extends Event
case class ChargingStarted(droneId: String, chargeComplete: Instant)
extends Event
Expand Down Expand Up @@ -106,13 +105,10 @@ object ChargingStation {
replicatedBehaviors: ReplicatedBehaviors[Command, Event, Option[State]])
: Behavior[Command] = {
Behaviors.setup[Command] { context =>
Behaviors.withTimers { timers =>
replicatedBehaviors.setup { replicationContext =>
context.log.info(
"Charging Station {} starting up",
replicationContext.entityId)
new ChargingStation(context, replicationContext, timers).behavior()
}
replicatedBehaviors.setup { replicationContext =>
context.log
.info("Charging Station {} starting up", replicationContext.entityId)
new ChargingStation(context, replicationContext).behavior()
}
}
}
Expand All @@ -121,8 +117,7 @@ object ChargingStation {

class ChargingStation(
context: ActorContext[ChargingStation.Command],
replicationContext: ReplicationContext,
timers: TimerScheduler[ChargingStation.Command]) {
replicationContext: ReplicationContext) {

import ChargingStation._

Expand Down
Loading

0 comments on commit 096d463

Please sign in to comment.