blob: b226131120c0e6ef2ada93cd2926bb6247b91172 (
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
75
76
77
78
79
80
81
82
83
84
|
// 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 java.util.HashSet;
import java.util.Set;
/**
*
* The mode the config proxy can be running with.
*
* 'default' mode is requesting config from server, serving from cache only when known config
* and no new config having been sent from server. When in 'memorycache' mode, there is no connection
* to a config source, the proxy serves from memory cache only.
*
* @author hmusum
*/
class Mode {
private final ModeName mode;
enum ModeName {
DEFAULT, MEMORYCACHE
}
public Mode() {
this(ModeName.DEFAULT);
}
public Mode(ModeName modeName) {
mode = modeName;
}
public Mode(String modeString) {
switch (modeString.toLowerCase()) {
case "" :
mode = ModeName.DEFAULT;
break;
case "default" :
mode = ModeName.DEFAULT;
break;
case "memorycache" :
mode = ModeName.MEMORYCACHE;
break;
default:
throw new IllegalArgumentException("Unrecognized mode'" + modeString + "' supplied");
}
}
public ModeName getMode() {
return mode;
}
public boolean isDefault() {
return mode.equals(ModeName.DEFAULT);
}
public boolean isMemoryCache() {
return mode.equals(ModeName.MEMORYCACHE);
}
public boolean requiresConfigSource() {
return mode.equals(ModeName.DEFAULT);
}
public static boolean validModeName(String modeString) {
return (modeString != null) && modes().contains(modeString);
}
static Set<String> modes() {
Set<String> modes = new HashSet<>();
for (ModeName mode : ModeName.values()) {
modes.add(mode.name().toLowerCase());
}
return modes;
}
public String name() {
return mode.name().toLowerCase();
}
@Override
public String toString() {
return mode.name().toLowerCase();
}
}
|