org.zalando.riptide.RoutingTree Maven / Gradle / Ivy
package org.zalando.riptide;
import org.apiguardian.api.API;
import org.springframework.http.client.ClientHttpResponse;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static java.util.Arrays.asList;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.apiguardian.api.API.Status.STABLE;
/**
* A routing tree is a nested {@link Route route} that consists of a {@link Navigator navigator} and a set of
* {@link Binding bindings}. When being {@link Route#execute(ClientHttpResponse, MessageReader) executed} the navigator
* will select the attribute value of the returned {@link ClientHttpResponse response}, find the correct binding
* and execute {@link Binding#getRoute() it's route}. Since a routing tree is a route itself they can be nested
* recursively inside each other to produce complex graphs.
*
* @param generic attribute type
* @see Route
*/
@API(status = STABLE)
public interface RoutingTree extends Route {
Navigator getNavigator();
Set keySet();
Optional get(final A attribute);
Optional getWildcard();
/**
* @throws NoWildcardException if no route, not even a wildcard, exists for the given response
*/
@Override
void execute(final ClientHttpResponse response, final MessageReader reader) throws Exception;
@API(status = EXPERIMENTAL)
default RoutingTree merge(final Binding binding) {
return merge(Collections.singletonList(binding));
}
@API(status = EXPERIMENTAL)
RoutingTree merge(final List> bindings);
@SafeVarargs
static RoutingTree dispatch(final Navigator navigator, final Binding... bindings) {
return dispatch(navigator, asList(bindings));
}
static RoutingTree dispatch(final Navigator navigator, final List> bindings) {
return new DefaultRoutingTree<>(navigator, bindings);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy