Package akka.javasdk.impl.agent.task
Class BacklogEntity
Object
akka.javasdk.eventsourcedentity.EventSourcedEntity<BacklogState,BacklogEvent>
akka.javasdk.impl.agent.task.BacklogEntity
@InternalApi
@Component(id="akka-backlog")
public final class BacklogEntity
extends EventSourcedEntity<BacklogState,BacklogEvent>
INTERNAL API Manages a shared backlog of task references with atomic claiming semantics. Multiple
agents can browse, claim, release, and transfer tasks concurrently.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordNested classes/interfaces inherited from class akka.javasdk.eventsourcedentity.EventSourcedEntity
EventSourcedEntity.Effect<T>, EventSourcedEntity.ReadOnlyEffect<T> -
Constructor Summary
ConstructorsConstructorDescriptionBacklogEntity(EventSourcedEntityContext context, NotificationPublisher<BacklogNotification> notificationPublisher) -
Method Summary
Modifier and TypeMethodDescriptionEventSourcedEntity.Effect<akka.Done> Add a task reference to this backlog.applyEvent(BacklogEvent event) This is the main event handler method.EventSourcedEntity.Effect<akka.Done> Remove all unclaimed tasks from the backlog.EventSourcedEntity.Effect<akka.Done> claim(BacklogEntity.ClaimRequest request) Atomic first-come-first-served claim.EventSourcedEntity.Effect<akka.Done> close()Close the backlog — no further modifications allowed.EventSourcedEntity.Effect<akka.Done> Create this backlog with a name.Returns the initial empty state object for this entity.getState()Get the current state of the backlog.EventSourcedEntity.Effect<akka.Done> Release a claimed task back to unclaimed.EventSourcedEntity.Effect<akka.Done> transfer(BacklogEntity.TransferRequest request) Transfer a claimed task directly to a different agent.Methods inherited from class akka.javasdk.eventsourcedentity.EventSourcedEntity
commandContext, currentState, effects, eventContext, isDeleted
-
Constructor Details
-
BacklogEntity
public BacklogEntity(EventSourcedEntityContext context, NotificationPublisher<BacklogNotification> notificationPublisher)
-
-
Method Details
-
emptyState
Description copied from class:EventSourcedEntityReturns the initial empty state object for this entity. This state is used when the entity is first created and before any events have been persisted and applied.Also known as "zero state" or "neutral state". This method is called when the entity is instantiated for the first time or when recovering from the journal without any persisted events.
The default implementation returns
null. Override this method to provide a more meaningful initial state for your entity.- Overrides:
emptyStatein classEventSourcedEntity<BacklogState,BacklogEvent> - Returns:
- the initial state object, or
nullif no initial state is needed
-
create
Create this backlog with a name. -
addTask
Add a task reference to this backlog. The task must already exist in TaskEntity. -
claim
Atomic first-come-first-served claim. -
release
Release a claimed task back to unclaimed. -
transfer
Transfer a claimed task directly to a different agent. -
cancelUnclaimed
Remove all unclaimed tasks from the backlog. -
close
Close the backlog — no further modifications allowed. -
getState
Get the current state of the backlog. -
notifications
-
applyEvent
Description copied from class:EventSourcedEntityThis is the main event handler method. Whenever an event is persisted, this handler will be called. It should return the new state of the entity.Note that this method is called in two situations:
- when one or more events are persisted by the command handler, this method is called to produce the new state of the entity.
- when instantiating an entity from the event journal, this method is called to restore the state of the entity.
Events are required to inherit from a common sealed interface, and it's recommend to implement this method using a switch statement. As such, the compiler can check if all existing events are being handled.
// example of sealed event interface with concrete events implementing it public sealed interface Event { @TypeName("created") public record UserCreated(String name, String email) implements Event {}; @TypeName("email-updated") public record EmailUpdated(String newEmail) implements Event {}; } // example of applyEvent implementation public User applyEvent(Event event) { return switch (event) { case UserCreated userCreated -> new User(userCreated.name, userCreated.email); case EmailUpdated emailUpdated -> this.copy(email = emailUpdated.newEmail); } }- Specified by:
applyEventin classEventSourcedEntity<BacklogState,BacklogEvent>
-