Skip to content

How can ServerBuilder accept a list of decorators #5257

Answered by jrhee17
evgeny-mordyasov asked this question in Q&A
Discussion options

You must be logged in to vote

For now, the only way I can think of is pre-merging all decorators:

static Function<? super HttpService, ? extends HttpService> compose(
        List<Function<? super HttpService, ? extends HttpService>> decorators) {
    assert !decorators.isEmpty();
    Function<? super HttpService, ? extends HttpService> decorated = decorators.get(0);
    for (int i = 1; i < decorators.size(); i++) {
        decorated = decorators.get(i).andThen(decorated);
    }
    return decorated;
}

Having said this, I think it's reasonable to add some APIs which allow users to add multiple decorators.

e.g.

Server.builder()
      .routeDecorator()
      .path("/decorated2")
      .build(LoggingService.newDecorator(), 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by evgeny-mordyasov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants