Skip to content

Commit

Permalink
Merge pull request #140 from Tradeshift/race
Browse files Browse the repository at this point in the history
Allow subclasses to hold off on commands while not idle
  • Loading branch information
jypma authored Nov 27, 2019
2 parents cc3d213 + 2853a37 commit 247f3ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ protected java.time.Duration getPassivateTimeout() {
return context().system().settings().config().getDuration("ts-reaktive.actors.passivate-timeout");
}

/**
* Returns whether the asynchronous part of a Handler for this command is currently in progress
* (and, hence, further commands would currently be stashed if sent to this actor)
*/
protected boolean isCommandInProgress() {
return !idle;
}

@SuppressWarnings("unchecked")
@Override
public Receive createReceive() {
Expand Down Expand Up @@ -147,9 +155,6 @@ protected boolean canHandleCommand(C cmd) {
* Must only be invoked if {@link #canHandleCommand(Object)} has returned true for this command.
*/
protected void handleCommand(C cmd) {
// FIXME We need to uphold command ordering for the same sender (just like akka does for normal messages).
// Hence, we need to stash subsequent messages from the same sender, while one message from that sender is still
// being piped.
pipe(handlers.handle(state, cmd), context().dispatcher()).to(self(), sender());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ protected Receive justCreated() {
getContext().become(master());
if (receive.onMessage().isDefinedAt(c)) {
receive.onMessage().apply(c);
} else {
log.warning("Unhandled first write command: {}", c);
}
})
.match(Query.EventEnvelope.class, e -> {
Expand Down

0 comments on commit 247f3ee

Please sign in to comment.