aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/main/java/com/yahoo/config/subscription/impl/RawConfigSubscription.java
blob: 22939c375ae1ca2c81dab6b65cbd1160fcebecfd (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
// 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.CfgConfigPayloadBuilder;
import com.yahoo.config.subscription.ConfigInterruptedException;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.ConfigPayload;
import com.yahoo.vespa.config.PayloadChecksums;

import java.util.Arrays;

/**
 * Subscription used when config id is raw:...
 * <p>
 * Config is the actual text given after the config id, with newlines
 *
 * @author Vegard Havdal
 */
public class RawConfigSubscription<T extends ConfigInstance> extends ConfigSubscription<T> {

    final String inputPayload;
    String payload;

    RawConfigSubscription(ConfigKey<T> key, String payload) {
        super(key);
        this.inputPayload = payload;
    }

    @Override
    public boolean nextConfig(long timeout) {
        if (checkReloaded()) {
            return true;
        }
        if (payload == null) {
            payload = inputPayload;
            ConfigPayload configPayload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(payload.split("\n")));
            setConfig(0L, false, configPayload.toInstance(configClass, key.getConfigId()), PayloadChecksums.empty());
            return true;
        }
        try {
            Thread.sleep(timeout);
        } catch (InterruptedException e) {
            throw new ConfigInterruptedException(e);
        }
        return false;
    }

    @Override
    public boolean subscribe(long timeout) {
        return true;
    }

}