Skip to content

Commit

Permalink
allow creation of pre-enforcer without reply address for error responses
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yufei (INST/ECS1) <yufei.cai@bosch-si.com>
  • Loading branch information
yufei-cai committed Apr 13, 2018
1 parent 295aa2f commit 4dddde1
Showing 1 changed file with 17 additions and 2 deletions.
Expand Up @@ -15,6 +15,8 @@
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

import javax.annotation.Nullable;

import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.base.headers.WithDittoHeaders;
Expand Down Expand Up @@ -48,14 +50,27 @@ public final class PreEnforcer {

private PreEnforcer() {}

/**
* Create a processing unit from a function without reply address for errors.
*
* @param processor function to call.
* @return Akka stream graph.
*/
public static Graph<FlowShape<WithSender, WithSender>, NotUsed> fromFunction(
final Function<WithDittoHeaders, CompletionStage<WithDittoHeaders>> processor) {

return fromFunction(ActorRef.noSender(), processor);
}

/**
* Create a processing unit from a function.
*
* @param self reference to the actor carrying the pre-enforcement.
* @param processor function to call.
* @return Akka stream graph.
*/
public static Graph<FlowShape<WithSender, WithSender>, NotUsed> fromFunction(
final ActorRef self,
@Nullable final ActorRef self,
final Function<WithDittoHeaders, CompletionStage<WithDittoHeaders>> processor) {

final Attributes logLevels =
Expand Down Expand Up @@ -94,7 +109,7 @@ private static Graph<SourceShape<WithSender>, NotUsed> keepResultAndLogErrors(fi

private static Object handleError(final Throwable error,
final WithSender<WithDittoHeaders> wrapped,
final ActorRef self) {
@Nullable final ActorRef self) {

final Throwable rootCause = extractRootCause(error);
final ActorRef sender = wrapped.sender();
Expand Down

0 comments on commit 4dddde1

Please sign in to comment.