summaryrefslogtreecommitdiffstats
path: root/config/src/main/java/com/yahoo/config/subscription/impl/GenericConfigSubscriber.java
blob: e382bab576e12267082f45271e3a863a49981304 (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
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.subscription.impl;

import com.yahoo.config.ConfigInstance;
import com.yahoo.config.subscription.ConfigHandle;
import com.yahoo.config.subscription.ConfigSubscriber;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.TimingValues;

import java.util.List;

/**
 * A subscriber that can subscribe without the class. Used by config proxy.
 *
 * @author Vegard Havdal
 */
public class GenericConfigSubscriber extends ConfigSubscriber {

    private final JRTConfigRequester requester;

    /**
     * Constructs a new subscriber using the given pool of requesters (JRTConfigRequester holds 1 connection which in
     * turn is subject to failover across the elements in the source set.)
     * The behaviour is undefined if the map key is different from the source set the requester was built with.
     * See also {@link JRTConfigRequester#JRTConfigRequester(com.yahoo.vespa.config.ConnectionPool, com.yahoo.vespa.config.TimingValues)}
     *
     * @param requester a config requester
     */
    public GenericConfigSubscriber(JRTConfigRequester requester) {
        this.requester = requester;
    }

    /**
     * Subscribes to config without using the class. For internal use in config proxy.
     *
     * @param key the {@link ConfigKey to subscribe to}
     * @param defContent the config definition content for the config to subscribe to
     * @param timingValues {@link TimingValues}
     * @return generic handle
     */
    public GenericConfigHandle subscribe(ConfigKey<RawConfig> key, List<String> defContent, TimingValues timingValues) {
        checkStateBeforeSubscribe();
        GenericJRTConfigSubscription sub = new GenericJRTConfigSubscription(key, defContent, requester, timingValues);
        GenericConfigHandle handle = new GenericConfigHandle(sub);
        subscribeAndHandleErrors(sub, key, handle, timingValues);
        return handle;
    }

    @Override
    public <T extends ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId) {
        throw new UnsupportedOperationException();
    }

    @Override
    public <T extends ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId, long timeoutMillis) {
        throw new UnsupportedOperationException();
    }

    @Override
    public <T extends ConfigInstance> ConfigHandle<T> subscribe(SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId) {
        throw new UnsupportedOperationException();
    }

    /**
     * Do nothing, since we share requesters
     */
    public void closeRequesters() {
    }

}