aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/service/CurrentContainer.java
blob: dc78146433970fea84c3fd47ab1d071f2dae034a (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.service;

import com.yahoo.jdisc.Container;
import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.application.BindingSet;
import com.yahoo.jdisc.application.BindingSetSelector;
import com.yahoo.jdisc.handler.RequestHandler;

import java.net.URI;

/**
 * This interface declares a method to retrieve a reference to the current {@link Container}. Note that a {@link
 * Container} which has <em>not</em> been {@link Container#release() closed} will actively keep it alive, preventing it
 * from shutting down when expired. Failure to call close() will eventually lead to an {@link OutOfMemoryError}. A
 * {@link ServerProvider} should have an instance of this class injected in its constructor, and simply use the {@link
 * Request#Request(CurrentContainer, URI) appropriate Request constructor} to avoid having to worry about the keep-alive
 * issue.
 *
 * @author Simon Thoresen Hult
 */
public interface CurrentContainer {

    /**
     * Returns a reference to the currently active {@link Container}. Until {@link Container#release()} has been called,
     * the Container can not shut down.
     *
     * @param uri The identifier used to match this Request to an appropriate {@link ClientProvider} or {@link
     *            RequestHandler}. The hostname must be "localhost" or a fully qualified domain name.
     * @param context that can be attached for reference tracking
     * @return A reference to the current Container.
     * @throws NoBindingSetSelectedException If no {@link BindingSet} was selected by the {@link BindingSetSelector}.
     * @throws BindingSetNotFoundException   If the named BindingSet was not found.
     * @throws ContainerNotReadyException    If no active Container was found, this can only happen during initial
     *                                       setup.
     */
    default Container newReference(URI uri, Object context) {
        return newReference(uri);
    }

    default Container newReference(URI uri) {
        return newReference(uri, null);
    }

}