org.zalando.riptide.CompositePlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riptide-core Show documentation
Show all versions of riptide-core Show documentation
Client side response routing
The newest version!
package org.zalando.riptide;
import lombok.AllArgsConstructor;
import java.util.Collection;
import java.util.Objects;
import java.util.function.BiFunction;
@AllArgsConstructor
final class CompositePlugin implements Plugin {
private final Collection plugins;
@Override
public RequestExecution aroundAsync(final RequestExecution execution) {
return combine(execution, Plugin::aroundAsync);
}
@Override
public RequestExecution aroundDispatch(final RequestExecution execution) {
return combine(execution, Plugin::aroundDispatch);
}
@Override
public RequestExecution aroundSerialization(final RequestExecution execution) {
return combine(execution, Plugin::aroundSerialization);
}
@Override
public RequestExecution aroundNetwork(final RequestExecution execution) {
return combine(execution, Plugin::aroundNetwork);
}
private RequestExecution combine(final RequestExecution execution,
final BiFunction combiner) {
RequestExecution result = execution;
for (final Plugin plugin : plugins) {
result = apply(plugin, result, combiner);
}
return result;
}
private RequestExecution apply(final Plugin plugin, final RequestExecution before,
final BiFunction combiner) {
final RequestExecution after = combiner.apply(plugin, before);
if (Objects.equals(before, after)) {
return after;
}
return new GuardedRequestExecution(after);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy