Skip to content

Commit

Permalink
Migrate task crash logic into Task class
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrueden committed Oct 17, 2023
1 parent 05e80cb commit b79c624
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/org/apposed/appose/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,7 @@ private void monitorLoop() {
if (taskCount > 0) debugService("<worker process terminated with " + taskCount + " pending tasks>");

// Notify any remaining tasks about the process crash.
for (Task task : tasks.values()) {
TaskEvent event = new TaskEvent(task, ResponseType.CRASH);
task.status = TaskStatus.CRASHED;
task.listeners.forEach(l -> l.accept(event));
synchronized (task) {
task.notifyAll();
}
}
tasks.values().forEach(Task::crash);
tasks.clear();
}

Expand Down Expand Up @@ -385,6 +378,15 @@ private void handle(Map<String, Object> response) {
}
}

private void crash() {
TaskEvent event = new TaskEvent(this, ResponseType.CRASH);
status = TaskStatus.CRASHED;
listeners.forEach(l -> l.accept(event));
synchronized (this) {
notifyAll();
}
}

@Override
public String toString() {
return String.format("uuid=%s, status=%s, message=%s, current=%d, maximum=%d, error=%s",
Expand Down

0 comments on commit b79c624

Please sign in to comment.