summaryrefslogtreecommitdiffstats
path: root/config/src/main/java/com/yahoo/config/subscription/impl/GenericJRTConfigSubscription.java
blob: 5e88e86be7127e62353e21879d65850531e544bc (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
72
73
74
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.subscription.impl;

import java.util.List;

import com.yahoo.config.ConfigInstance;
import com.yahoo.config.subscription.ConfigSource;
import com.yahoo.config.subscription.ConfigSubscriber;
import com.yahoo.log.LogLevel;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.TimingValues;
import com.yahoo.vespa.config.protocol.DefContent;
import com.yahoo.vespa.config.protocol.JRTClientConfigRequest;

/**
 * A JRT subscription which does not use the config class, but {@link com.yahoo.vespa.config.RawConfig} instead.
 * Used by config proxy.
 * @author vegardh
 *
 */
@SuppressWarnings("rawtypes")
public class GenericJRTConfigSubscription extends JRTConfigSubscription {

    private RawConfig config;
    private final List<String> defContent;

    @SuppressWarnings("unchecked")
    public GenericJRTConfigSubscription(ConfigKey<?> key,
                                        List<String> defContent,
            ConfigSubscriber subscriber,
            ConfigSource source,
            TimingValues timingValues) {
        super(key, subscriber, source, timingValues);
        this.defContent = defContent;
    }

    @Override
    protected void setNewConfig(JRTClientConfigRequest jrtReq) {
        this.config = RawConfig.createFromResponseParameters(jrtReq);
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, "in setNewConfig, config=" + this.config);
        }
    }

    // This method is overridden because config needs to have its generation
    // updated if _only_ generation has changed
    @Override
    void setGeneration(Long generation) {
        super.setGeneration(generation);
        if (this.config != null) {
            this.config.setGeneration(generation);
        }
    }

    public RawConfig getRawConfig() {
        return config;
    }

    /**
     * The config definition schema
     *
     * @return the config definition for this subscription
     */
    @Override
    public DefContent getDefContent() {
        return (DefContent.fromList(defContent));
    }

    @Override
    public ConfigInstance getConfig() {
        return null;
    }
}