From 1d02bbb6ef4f3d9bdcc0d994b9c575ebd88da9a8 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 30 Oct 2024 09:20:12 +0100 Subject: [PATCH 1/2] Add clean step after run --- .../computation/service/AbstractWorkerService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java index 3bd1155..4dc5d49 100644 --- a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java +++ b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java @@ -155,10 +155,18 @@ public Consumer> consumeRun() { } finally { futures.remove(resultContext.getResultUuid()); cancelComputationRequests.remove(resultContext.getResultUuid()); + clean(resultContext.getRunContext()); } }; } + /** + * perform cleaning some data, e.g. files generated by the computation + * @param runContext The run context of the computation + */ + protected void clean(C runContext) { + } + /** * Handle exception in consumeRun that is not a CancellationException * @param resultContext The context of the computation From 243d2be6d40381b5bbcc7f407d5e3e5475a9e5e7 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 30 Oct 2024 10:40:05 +0100 Subject: [PATCH 2/2] default implementation for clean method --- .../computation/service/AbstractWorkerService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java index 4dc5d49..4787ad4 100644 --- a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java +++ b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java @@ -153,18 +153,18 @@ public Consumer> consumeRun() { this.handleNonCancellationException(resultContext, e, rootReporter); } } finally { - futures.remove(resultContext.getResultUuid()); - cancelComputationRequests.remove(resultContext.getResultUuid()); - clean(resultContext.getRunContext()); + clean(resultContext); } }; } /** - * perform cleaning some data, e.g. files generated by the computation - * @param runContext The run context of the computation + * Perform cleaning + * @param resultContext The context of the computation */ - protected void clean(C runContext) { + protected void clean(AbstractResultContext resultContext) { + futures.remove(resultContext.getResultUuid()); + cancelComputationRequests.remove(resultContext.getResultUuid()); } /**