Skip to content

Commit f241481

Browse files
committed
feat: fix config read on k = v (#476)
1 parent e4d21fe commit f241481

2 files changed

Lines changed: 1 addition & 61 deletions

File tree

  • camellia-redis-proxy/camellia-redis-proxy-core/src/main/java/com/netease/nim/camellia/redis/proxy/conf
  • camellia-toolkits/camellia-tools/src/main/java/com/netease/nim/camellia/tools/utils

camellia-redis-proxy/camellia-redis-proxy-core/src/main/java/com/netease/nim/camellia/redis/proxy/conf/ProxyDynamicConf.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class ProxyDynamicConf {
3232
private static final ConcurrentHashMap<String, Boolean> booleanCache = new ConcurrentHashMap<>();
3333
private static final ConcurrentHashMap<String, Double> doubleCache = new ConcurrentHashMap<>();
3434
private static final ConcurrentHashMap<String, String> stringCache = new ConcurrentHashMap<>();
35-
private static final ConcurrentHashMap<String, Object> cache = new ConcurrentHashMap<>();
3635

3736

3837
/**
@@ -129,7 +128,6 @@ private static void clearCache() {
129128
booleanCache.clear();
130129
doubleCache.clear();
131130
stringCache.clear();
132-
cache.clear();
133131
}
134132

135133
/**
@@ -301,44 +299,6 @@ public static String getString(String key, Long bid, String bgroup, String defau
301299
}
302300

303301

304-
private static <T> T get(String key, T defaultValue, Class<T> tClass) {
305-
return ConfigurationUtil.get(conf, key, defaultValue, tClass);
306-
}
307-
308-
/**
309-
* Get value from {@link ProxyDynamicConf#conf}. Use caching to avoid duplicate creation.
310-
*
311-
* @param key key
312-
* @param bid id
313-
* @param bgroup group
314-
* @param defaultValue defaultValue
315-
* @param tClass the type of the return value
316-
* @param <T> T
317-
* @return value
318-
*/
319-
public static <T> T get(String key, Long bid, String bgroup, T defaultValue, Class<T> tClass) {
320-
try {
321-
if (conf.isEmpty()) return defaultValue;
322-
String confKey = buildConfKey(key, bid, bgroup);
323-
T value;
324-
T cacheValue = (T) cache.get(confKey);
325-
if (cacheValue != null) return cacheValue;
326-
value = get(confKey, null, tClass);
327-
if (value == null) {
328-
value = get(key, null, tClass);
329-
}
330-
if (value == null) {
331-
cache.put(confKey, defaultValue);
332-
return defaultValue;
333-
}
334-
cache.put(confKey, value);
335-
return value;
336-
} catch (Exception e) {
337-
return defaultValue;
338-
}
339-
}
340-
341-
342302
/**
343303
* Build config key from key,bid,bgroup. If bid == null and bgroup == null, use default.default+key
344304
*

camellia-toolkits/camellia-tools/src/main/java/com/netease/nim/camellia/tools/utils/ConfigurationUtil.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,6 @@ public static String get(Map<String, String> conf, String key, String defaultVal
6767
}
6868
}
6969

70-
public static <T> T get(Map<String, String> conf, String key, T defaultValue, Class<T> tClass) {
71-
try {
72-
String v = conf.get(key);
73-
if (v == null) return defaultValue;
74-
if (tClass == Integer.class) {
75-
return (T) Integer.valueOf(v);
76-
} else if (tClass == Boolean.class) {
77-
return (T) Boolean.valueOf(v);
78-
} else if (tClass == Long.class) {
79-
return (T) Long.valueOf(v);
80-
} else if (tClass == Double.class) {
81-
return (T) Double.valueOf(v);
82-
} else {
83-
return (T) v;
84-
}
85-
} catch (Exception e) {
86-
return defaultValue;
87-
}
88-
}
89-
9070
public static ConfigContentType configContentType(String fileName) {
9171
if (fileName == null) {
9272
return ConfigContentType.properties;
@@ -115,7 +95,7 @@ public static Map<String, String> contentToMap(String content, ConfigContentType
11595
int index = line.indexOf("=");
11696
String key = line.substring(0, index);
11797
String value = line.substring(index + 1);
118-
conf.put(key, value);
98+
conf.put(key.trim(), value.trim());
11999
}
120100
return conf;
121101
} else if (contentType == ConfigContentType.json) {

0 commit comments

Comments
 (0)