diff --git a/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/aas/agent/AasAgent.java b/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/aas/agent/AasAgent.java index 217cde4e..c172e792 100644 --- a/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/aas/agent/AasAgent.java +++ b/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/aas/agent/AasAgent.java @@ -22,7 +22,6 @@ import de.fraunhofer.iosb.app.pipeline.PipelineStep; import de.fraunhofer.iosb.dataplane.aas.spi.AasDataAddress; import de.fraunhofer.iosb.model.aas.AasProvider; -import okhttp3.Response; import okhttp3.ResponseBody; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.DeserializationException; import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer; @@ -58,28 +57,19 @@ protected Result> readElements(AasDataProcessor processor, AasProvid .path(path) .build(); - var responseResult = executeRequest(processor, dataAddress); + try (var response = processor.send(dataAddress)) { - if (responseResult.failed()) { - return Result.failure("Reading %s from %s failed: %s" - .formatted(clazz.getName(), path, responseResult.getFailureDetail())); - } - - var response = responseResult.getContent(); - - if (response.isSuccessful() && response.body() != null) { - return readList(response.body(), clazz); - } + if (response.isSuccessful() && response.body() != null) { + return readList(response.body(), clazz); + } - return Result.failure("Reading %s from %s failed: %s, %s" - .formatted(clazz.getSimpleName(), path, response.code(), response.message())); - } + return Result.failure("Reading %s from %s failed: %s, %s" + .formatted(clazz.getSimpleName(), path, response.code(), response.message())); - private Result executeRequest(AasDataProcessor processor, AasDataAddress dataAddress) { - try { - return Result.success(processor.send(dataAddress)); } catch (IOException httpIOException) { - return Result.failure(List.of(httpIOException.getClass().getSimpleName(), httpIOException.getMessage())); + return Result.failure("Reading %s from %s failed: %s %s" + .formatted(clazz.getName(), path, httpIOException.getClass().getSimpleName(), + httpIOException.getMessage())); } } diff --git a/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/util/VariableRateScheduler.java b/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/util/VariableRateScheduler.java index 84c0cc49..9045c629 100644 --- a/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/util/VariableRateScheduler.java +++ b/edc-extension4aas/src/main/java/de/fraunhofer/iosb/app/util/VariableRateScheduler.java @@ -54,7 +54,7 @@ public VariableRateScheduler(int corePoolSize, Runnable runnable, Monitor monito public void scheduleAtVariableRate(Supplier rateSupplier) { schedule(() -> { try { - runnable.run(); + runRunnable(); } catch (Exception e) { monitor.severe("VariableRateScheduler stopped execution.", e); throw new EdcException(e); @@ -63,13 +63,17 @@ public void scheduleAtVariableRate(Supplier rateSupplier) { }, (long) rateSupplier.get(), TimeUnit.SECONDS); } + private synchronized void runRunnable() { + runnable.run(); + } + @Override public void created(Registry registry) { - runnable.run(); + runRunnable(); } @Override public void created(Service service) { - runnable.run(); + runRunnable(); } }