aboutsummaryrefslogtreecommitdiffstats
path: root/application/src/main/java/com/yahoo/application/container/Processing.java
blob: c3fababb8fc80b1f4de6a098aa2525b96a36e0eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container;

import com.yahoo.api.annotations.Beta;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.chain.Chain;
import com.yahoo.processing.Processor;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
import com.yahoo.processing.execution.chain.ChainRegistry;
import com.yahoo.processing.handler.ProcessingHandler;
import com.yahoo.processing.rendering.Renderer;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;

/**
 * @author Einar M R Rosenvinge
 * @author gjoranv
*/
@Beta
public final class Processing extends ProcessingBase<Request, Response, Processor> {

    private final ProcessingHandler handler;

    Processing(ProcessingHandler handler) {
        this.handler = handler;
    }

    @Override
    public ChainRegistry<Processor> getChains() {
        return handler.getChainRegistry();
    }

    @Override
    protected Response doProcess(Chain<Processor> chain, Request request) {
        Execution execution = handler.createExecution(chain, request);
        return execution.process(request);
    }

    @Override
    protected CompletableFuture<Boolean> doProcessAndRender(ComponentSpecification chainSpec,
                                                            Request request,
                                                            Renderer<Response> renderer,
                                                            ByteArrayOutputStream stream) throws IOException {
        Execution execution = handler.createExecution(getChain(chainSpec), request);
        Response response = execution.process(request);

        return renderer.renderResponse(stream, response, execution, request);
    }

    @Override
    protected Renderer<Response> doGetRenderer(ComponentSpecification spec) {
        return handler.getRendererCopy(spec);
    }

}