Skip to content

Commit 941f1b4

Browse files
committed
Merge branch 'apache-3.1' into 3.1.4-release
2 parents b58a064 + 705b327 commit 941f1b4

File tree

30 files changed

+274
-440
lines changed

30 files changed

+274
-440
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/config/CompositeConfiguration.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,4 @@ public Object getInternalProperty(String key) {
8989
return null;
9090
}
9191

92-
@Override
93-
public Object getInternalProperty(String key, Object defaultValue) {
94-
for (Configuration config : configList) {
95-
try {
96-
Object value = config.getProperty(key, defaultValue);
97-
if (!ConfigurationUtils.isEmptyValue(value)) {
98-
return value;
99-
}
100-
} catch (Exception e) {
101-
logger.error("Error when trying to get value for key " + key + " from " + config + ", " +
102-
"will continue to try the next one.");
103-
}
104-
}
105-
return defaultValue;
106-
}
107-
10892
}

dubbo-common/src/main/java/org/apache/dubbo/common/config/Configuration.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,18 @@ default Object getProperty(String key) {
127127
* Gets a property from the configuration. The default value will return if the configuration doesn't contain
128128
* the mapping for the specified key.
129129
*
130-
* @param key property to retrieve
130+
* @param key property to retrieve
131131
* @param defaultValue default value
132132
* @return the value to which this configuration maps the specified key, or default value if the configuration
133133
* contains no mapping for this key.
134134
*/
135135
default Object getProperty(String key, Object defaultValue) {
136-
return getInternalProperty(key, defaultValue);
136+
Object value = getInternalProperty(key);
137+
return value != null ? value : defaultValue;
137138
}
138139

139140
Object getInternalProperty(String key);
140141

141-
Object getInternalProperty(String key, Object defaultValue);
142-
143142
/**
144143
* Check if the configuration contains the specified key.
145144
*
@@ -154,12 +153,9 @@ default boolean containsKey(String key) {
154153

155154
default <T> T convert(Class<T> cls, String key, T defaultValue) {
156155
// we only process String properties for now
157-
Object value = getProperty(key, defaultValue);
156+
String value = (String) getProperty(key);
158157

159-
if (!String.class.isInstance(value)) {
160-
if (cls.isInstance(value)) {
161-
return cls.cast(value);
162-
}
158+
if (value == null) {
163159
return defaultValue;
164160
}
165161

@@ -168,26 +164,24 @@ default <T> T convert(Class<T> cls, String key, T defaultValue) {
168164
return cls.cast(value);
169165
}
170166

171-
String str = (String) value;
172-
173167
if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
174-
obj = Boolean.valueOf(str);
168+
obj = Boolean.valueOf(value);
175169
} else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
176170
if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
177-
obj = Integer.valueOf(str);
171+
obj = Integer.valueOf(value);
178172
} else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
179-
obj = Long.valueOf(str);
173+
obj = Long.valueOf(value);
180174
} else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
181-
obj = Byte.valueOf(str);
175+
obj = Byte.valueOf(value);
182176
} else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
183-
obj = Short.valueOf(str);
177+
obj = Short.valueOf(value);
184178
} else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
185-
obj = Float.valueOf(str);
179+
obj = Float.valueOf(value);
186180
} else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
187-
obj = Double.valueOf(str);
181+
obj = Double.valueOf(value);
188182
}
189183
} else if (cls.isEnum()) {
190-
obj = Enum.valueOf(cls.asSubclass(Enum.class), str);
184+
obj = Enum.valueOf(cls.asSubclass(Enum.class), value);
191185
}
192186

193187
return cls.cast(obj);

dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Environment(ScopeModel scopeModel) {
8181
public void initialize() throws IllegalStateException {
8282
if (initialized.compareAndSet(false, true)) {
8383
this.propertiesConfiguration = new PropertiesConfiguration(scopeModel);
84-
this.systemConfiguration = new SystemConfiguration(scopeModel);
84+
this.systemConfiguration = new SystemConfiguration();
8585
this.environmentConfiguration = new EnvironmentConfiguration();
8686
this.externalConfiguration = new InmemoryConfiguration("ExternalConfig");
8787
this.appExternalConfiguration = new InmemoryConfiguration("AppExternalConfig");

dubbo-common/src/main/java/org/apache/dubbo/common/config/EnvironmentConfiguration.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ public Object getInternalProperty(String key) {
3434
return value;
3535
}
3636

37-
@Override
38-
public Object getInternalProperty(String key, Object defaultValue) {
39-
String value = System.getenv(key);
40-
if (StringUtils.isEmpty(value)) {
41-
value = System.getenv(StringUtils.toOSStyleKey(key));
42-
}
43-
44-
if (StringUtils.isEmpty(value)) {
45-
return defaultValue;
46-
}
47-
return value;
48-
}
49-
5037
public Map<String, String> getProperties() {
5138
return System.getenv();
5239
}

dubbo-common/src/main/java/org/apache/dubbo/common/config/InmemoryConfiguration.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ public Object getInternalProperty(String key) {
4545
return store.get(key);
4646
}
4747

48-
@Override
49-
public Object getInternalProperty(String key, Object defaultValue) {
50-
Object v = store.get(key);
51-
if (v != null) {
52-
return v;
53-
} else {
54-
return defaultValue;
55-
}
56-
}
57-
5848
/**
5949
* Add one property into the store, the previous value will be replaced if the key exists
6050
*/

dubbo-common/src/main/java/org/apache/dubbo/common/config/OrderedPropertiesConfiguration.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ public Object getInternalProperty(String key) {
6868
return properties.getProperty(key);
6969
}
7070

71-
@Override
72-
public Object getInternalProperty(String key, Object defaultValue) {
73-
Object v = properties.getProperty(key);
74-
if (v != null){
75-
return v;
76-
}else {
77-
return defaultValue;
78-
}
79-
}
80-
8171
public void setProperty(String key, String value) {
8272
properties.setProperty(key, value);
8373
}

dubbo-common/src/main/java/org/apache/dubbo/common/config/PrefixedConfiguration.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,4 @@ public Object getInternalProperty(String key) {
4242
return null;
4343
}
4444

45-
@Override
46-
public Object getInternalProperty(String key, Object defaultValue) {
47-
if (StringUtils.isBlank(prefix)) {
48-
return origin.getInternalProperty(key, defaultValue);
49-
}
50-
51-
Object value = origin.getInternalProperty(prefix + "." + key, defaultValue);
52-
if (!ConfigurationUtils.isEmptyValue(value)) {
53-
return value;
54-
}
55-
return null;
56-
}
57-
5845
}

dubbo-common/src/main/java/org/apache/dubbo/common/config/PropertiesConfiguration.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ public Object getInternalProperty(String key) {
4949
return properties.getProperty(key);
5050
}
5151

52-
@Override
53-
public Object getInternalProperty(String key, Object defaultValue) {
54-
Object v = properties.getProperty(key);
55-
if (v != null){
56-
return v;
57-
}else {
58-
return defaultValue;
59-
}
60-
}
61-
6252
public void setProperty(String key, String value) {
6353
properties.setProperty(key, value);
6454
}

dubbo-common/src/main/java/org/apache/dubbo/common/config/SystemConfiguration.java

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,94 +17,19 @@
1717
package org.apache.dubbo.common.config;
1818

1919

20-
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
21-
import org.apache.dubbo.common.logger.LoggerFactory;
22-
import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
23-
import org.apache.dubbo.rpc.model.ScopeModel;
24-
import org.apache.dubbo.rpc.model.ScopeModelUtil;
25-
2620
import java.util.Map;
27-
import java.util.Properties;
28-
import java.util.Set;
29-
import java.util.concurrent.ConcurrentHashMap;
30-
import java.util.concurrent.ScheduledExecutorService;
31-
import java.util.concurrent.TimeUnit;
3221

3322
/**
34-
* FIXME: is this really necessary? PropertiesConfiguration should have already covered this:
35-
*
36-
* @See ConfigUtils#getProperty(String)
37-
* @see PropertiesConfiguration
23+
* Configuration from system properties
3824
*/
3925
public class SystemConfiguration implements Configuration {
4026

41-
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(SystemConfiguration.class);
42-
43-
private final Map<String, Object> cache = new ConcurrentHashMap<>();
44-
45-
private final ScheduledExecutorService sharedScheduledExecutor;
46-
47-
public SystemConfiguration(ScopeModel scopeModel) {
48-
sharedScheduledExecutor = ScopeModelUtil.getFrameworkModel(scopeModel).getBeanFactory()
49-
.getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor();
50-
sharedScheduledExecutor.scheduleWithFixedDelay(() -> {
51-
if (!cache.isEmpty()) {
52-
Set<String> keys = cache.keySet();
53-
keys.forEach((key) -> overwriteCache(key, System.getProperty(key)));
54-
}
55-
}, 60000, 60000, TimeUnit.MILLISECONDS);
56-
}
57-
5827
@Override
5928
public Object getInternalProperty(String key) {
60-
if (cache.containsKey(key)) {
61-
return cache.get(key);
62-
} else {
63-
Object val = System.getProperty(key);
64-
if (val != null) {
65-
cache.putIfAbsent(key, val);
66-
}
67-
return val;
68-
}
29+
return System.getProperty(key);
6930
}
7031

71-
@Override
72-
public Object getInternalProperty(String key, Object defaultValue) {
73-
if (cache.containsKey(key)) {
74-
return cache.get(key);
75-
} else {
76-
Object val = System.getProperty(key);
77-
if (val != null) {
78-
cache.putIfAbsent(key, val);
79-
} else {
80-
val = defaultValue;
81-
if (defaultValue != null) {
82-
cache.putIfAbsent(key, defaultValue);
83-
}
84-
}
85-
return val;
86-
}
87-
}
88-
89-
public void overwriteCache(String key, Object value) {
90-
if (value != null) {
91-
cache.put(key, value);
92-
}
93-
}
94-
95-
public void clearCache() {
96-
cache.clear();
97-
}
98-
99-
10032
public Map<String, String> getProperties() {
101-
Properties properties = System.getProperties();
102-
Map<String, String> res = new ConcurrentHashMap<>(properties.size());
103-
try {
104-
res.putAll((Map) properties);
105-
} catch (Exception e) {
106-
logger.warn("System property get failed", e);
107-
}
108-
return res;
33+
return (Map) System.getProperties();
10934
}
11035
}

dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfiguration.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ public Object getInternalProperty(String key) {
120120
return null;
121121
}
122122

123-
@Override
124-
public Object getInternalProperty(String key, Object defaultValue) {
125-
return null;
126-
}
127-
128123
@Override
129124
public final void close() throws Exception {
130125
try {

0 commit comments

Comments
 (0)