Skip to content

Commit

Permalink
[ISSUE alibaba#8622] 移除 environment 概念 (alibaba#8991)
Browse files Browse the repository at this point in the history
* [ISSUE alibaba#8622] 移除 environment 概念

* [ISSUE alibaba#8622] 使用尾递归优化循环

- SYS更名为ENV
- SHARED更改为PROTOTYPE

* [ISSUE alibaba#8622] rename lookingForProperties

* [ISSUE alibaba#8622] NProperties is renamed SearchableProperties and add some comments

* [ISSUE alibaba#8622] update some comments
  • Loading branch information
onewe authored Sep 22, 2022
1 parent b37d100 commit 6278e7e
Show file tree
Hide file tree
Showing 16 changed files with 732 additions and 625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class SysEnv {

public static final String JM_SNAPSHOT_PATH = "JM.SNAPSHOT.PATH";

public static final String NACOS_ENVS_SEARCH = "nacos.envs.search";
public static final String NACOS_ENV_FIRST = "nacos.env.first";

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alibaba.nacos.client.env;

import java.util.Properties;

abstract class AbstractPropertySource {

/**
Expand All @@ -31,4 +33,17 @@ abstract class AbstractPropertySource {
*/
abstract String getProperty(String key);

/**
* Tests if the specified object is a key in this propertySource.
* @param key key – possible key
* @return true if and only if the specified object is a key in this propertySource, false otherwise.
*/
abstract boolean containsKey(String key);

/**
* to properties.
* @return properties
*/
abstract Properties asProperties();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

class DefaultSettingPropertySource extends AbstractPropertySource {
Expand All @@ -33,12 +32,10 @@ class DefaultSettingPropertySource extends AbstractPropertySource {
private final Properties defaultSetting = new Properties();

DefaultSettingPropertySource() {
try {
final URL resourceUrl = ResourceUtils.getResourceUrl(DEFAULT_SETTING_PATH);
final InputStream inputStream = resourceUrl.openStream();
try (final InputStream inputStream = ResourceUtils.getResourceUrl(DEFAULT_SETTING_PATH).openStream()) {
defaultSetting.load(inputStream);
} catch (Exception e) {
LOGGER.warn("load default setting failed");
LOGGER.error("load default setting failed", e);
}
}

Expand All @@ -51,4 +48,16 @@ SourceType getType() {
String getProperty(String key) {
return defaultSetting.getProperty(key);
}

@Override
boolean containsKey(String key) {
return defaultSetting.containsKey(key);
}

@Override
Properties asProperties() {
Properties properties = new Properties();
properties.putAll(defaultSetting);
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ SourceType getType() {
String getProperty(String key) {
return properties.getProperty(key);
}

@Override
boolean containsKey(String key) {
return properties.containsKey(key);
}

@Override
Properties asProperties() {
Properties properties = new Properties();
properties.putAll(this.properties);
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,27 @@

package com.alibaba.nacos.client.env;

import java.util.Properties;

/**
* nacos env interface.
*
* NacosClientProperties interface.
* include all the properties from jvm args, system environment, default setting.
* more details you can see https://github.com/alibaba/nacos/issues/8622
* @author onewe
*/
public interface NacosEnvironment {
public interface NacosClientProperties {

/**
* all the NacosClientProperties object must be created by PROTOTYPE,
* so child NacosClientProperties can read properties from the PROTOTYPE.
* it looks like this:
* |-PROTOTYPE----------------> ip=127.0.0.1
* |---|-child1---------------> port=6379
* if you search key called "port" from child1, certainly you will get 6379
* if you search key called "ip" from child1, you will get 127.0.0.1.
* because the child can read properties from parent NacosClientProperties
*/
NacosClientProperties PROTOTYPE = SearchableProperties.INSTANCE;

/**
* get property, if the value can not be got by the special key, the null will be returned.
Expand Down Expand Up @@ -87,4 +102,42 @@ public interface NacosEnvironment {
*/
Long getLong(String key, Long defaultValue);

/**
* set property.
* @param key key
* @param value value
*/
void setProperty(String key, String value);

/**
* add properties.
* @param properties properties
*/
void addProperties(Properties properties);

/**
* Tests if the specified object is a key in this NacosClientProperties.
* @param key key – possible key
* @return true if and only if the specified object is a key in this NacosClientProperties, false otherwise.
*/
boolean containsKey(String key);

/**
* get properties from NacosClientProperties.
* @return properties
*/
Properties asProperties();

/**
* create a new NacosClientProperties which scope is itself.
* @return NacosClientProperties
*/
NacosClientProperties derive();

/**
* create a new NacosClientProperties from NacosClientProperties#PROTOTYPE and init.
* @param properties properties
* @return NacosClientProperties
*/
NacosClientProperties derive(Properties properties);
}

This file was deleted.

116 changes: 0 additions & 116 deletions client/src/main/java/com/alibaba/nacos/client/env/NacosEnvs.java

This file was deleted.

Loading

0 comments on commit 6278e7e

Please sign in to comment.