Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: synchronize pipeline calls #167

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,28 +57,19 @@ protected <K> Result<List<K>> 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<Response> 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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public VariableRateScheduler(int corePoolSize, Runnable runnable, Monitor monito
public void scheduleAtVariableRate(Supplier<Integer> rateSupplier) {
schedule(() -> {
try {
runnable.run();
runRunnable();
} catch (Exception e) {
monitor.severe("VariableRateScheduler stopped execution.", e);
throw new EdcException(e);
Expand All @@ -63,13 +63,17 @@ public void scheduleAtVariableRate(Supplier<Integer> 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();
}
}
Loading