summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClient.java
blob: a1c07b911559c5c083bb0d63ba775430cbdee518 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.proxy;

import com.yahoo.log.LogLevel;
import com.yahoo.vespa.config.*;
import com.yahoo.vespa.config.protocol.JRTServerConfigRequest;

import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;

/**
 * @author hmusum
 * @since 5.1.10
 */
class MemoryCacheConfigClient implements ConfigSourceClient {

    private final static Logger log = Logger.getLogger(MemoryCacheConfigClient.class.getName());
    private final MemoryCache cache;

    MemoryCacheConfigClient(MemoryCache cache) {
        this.cache = cache;
    }

    /**
     * Retrieves the requested config from the cache. Used when in 'memorycache' mode.
     *
     * @param request The config to retrieve - can be empty (no payload), or have a valid payload.
     * @return A Config with a payload.
     */
    @Override
    public RawConfig getConfig(RawConfig input, JRTServerConfigRequest request) {
        log.log(LogLevel.DEBUG, "Getting config from cache");
        ConfigKey<?> key = input.getKey();
        RawConfig cached = cache.get(new ConfigCacheKey(key, input.getDefMd5()));
        if (cached != null) {
            log.log(LogLevel.DEBUG, "Found config " + key + " in cache");
            return cached;
        } else {
            return null;
        }
    }

    @Override
    public void cancel() {
    }

    @Override
    public void shutdownSourceConnections() {
    }

    @Override
    public String getActiveSourceConnection() {
        return "N/A";
    }

    @Override
    public List<String> getSourceConnections() {
        return Collections.singletonList("N/A");
    }

}