-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle fatal errors in dsp http dispatcher delegate (#3203)
feat: handle fatal errors in dsp http dispatcher delegate
- Loading branch information
Showing
41 changed files
with
780 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...chine/src/main/java/org/eclipse/edc/statemachine/retry/AsyncStatusResultRetryProcess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.statemachine.retry; | ||
|
||
import org.eclipse.edc.spi.EdcException; | ||
import org.eclipse.edc.spi.entity.StatefulEntity; | ||
import org.eclipse.edc.spi.monitor.Monitor; | ||
import org.eclipse.edc.spi.response.ResponseFailure; | ||
import org.eclipse.edc.spi.response.StatusResult; | ||
|
||
import java.time.Clock; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Provides retry capabilities to an asynchronous process that returns a {@link CompletableFuture} with a {@link StatusResult} content | ||
*/ | ||
public class AsyncStatusResultRetryProcess<E extends StatefulEntity<E>, C, SELF extends AsyncStatusResultRetryProcess<E, C, SELF>> | ||
extends CompletableFutureRetryProcess<E, StatusResult<C>, SELF> { | ||
private final Monitor monitor; | ||
private BiConsumer<E, ResponseFailure> onFatalError; | ||
|
||
public AsyncStatusResultRetryProcess(E entity, Supplier<CompletableFuture<StatusResult<C>>> process, Monitor monitor, Clock clock, EntityRetryProcessConfiguration configuration) { | ||
super(entity, process, monitor, clock, configuration); | ||
this.monitor = monitor; | ||
} | ||
|
||
@Override | ||
public SELF onSuccess(BiConsumer<E, StatusResult<C>> onSuccessHandler) { | ||
this.onSuccessHandler = (entity, result) -> { | ||
new StatusResultRetryProcess<>(entity, () -> result, monitor, clock, configuration) | ||
.onSuccess((e, c) -> onSuccessHandler.accept(e, StatusResult.success(c))) | ||
.onFatalError(onFatalError) | ||
.onRetryExhausted((e, failure) -> onRetryExhausted.accept(e, new EdcException(failure.getFailureDetail()))) | ||
.onFailure((e, failure) -> onFailureHandler.accept(e, new EdcException(failure.getFailureDetail()))) | ||
.process(entity, description); | ||
}; | ||
return (SELF) this; | ||
} | ||
|
||
public SELF onFatalError(BiConsumer<E, ResponseFailure> onFatalError) { | ||
this.onFatalError = onFatalError; | ||
return (SELF) this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.