增加Environment
This commit is contained in:
@@ -111,6 +111,13 @@ public final class Application {
|
|||||||
*/
|
*/
|
||||||
public static final String RESNAME_APP_ASYNCGROUP = "APP_ASYNCGROUP";
|
public static final String RESNAME_APP_ASYNCGROUP = "APP_ASYNCGROUP";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境变量, 类型:Environment
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
public static final String RESNAME_APP_ENV = "APP_ENV";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前Service所属的SNCP Server的地址 类型: SocketAddress、InetSocketAddress、String <br>
|
* 当前Service所属的SNCP Server的地址 类型: SocketAddress、InetSocketAddress、String <br>
|
||||||
*/
|
*/
|
||||||
@@ -179,6 +186,8 @@ public final class Application {
|
|||||||
|
|
||||||
final Properties appProperties = new Properties();
|
final Properties appProperties = new Properties();
|
||||||
|
|
||||||
|
final Environment appEnvironment;
|
||||||
|
|
||||||
//第三方服务发现管理接口
|
//第三方服务发现管理接口
|
||||||
//@since 2.1.0
|
//@since 2.1.0
|
||||||
final ClusterAgent clusterAgent;
|
final ClusterAgent clusterAgent;
|
||||||
@@ -248,6 +257,7 @@ public final class Application {
|
|||||||
this.compileMode = compileMode;
|
this.compileMode = compileMode;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.configFromCache = "true".equals(config.getValue("[config-from-cache]"));
|
this.configFromCache = "true".equals(config.getValue("[config-from-cache]"));
|
||||||
|
this.appEnvironment = new Environment(this.appProperties);
|
||||||
System.setProperty("redkale.version", Redkale.getDotedVersion());
|
System.setProperty("redkale.version", Redkale.getDotedVersion());
|
||||||
|
|
||||||
final File root = new File(System.getProperty(RESNAME_APP_HOME));
|
final File root = new File(System.getProperty(RESNAME_APP_HOME));
|
||||||
@@ -291,7 +301,7 @@ public final class Application {
|
|||||||
this.resourceFactory.register(RESNAME_APP_CONF_DIR, File.class, confFile);
|
this.resourceFactory.register(RESNAME_APP_CONF_DIR, File.class, confFile);
|
||||||
this.resourceFactory.register(RESNAME_APP_CONF_DIR, Path.class, confFile.toPath());
|
this.resourceFactory.register(RESNAME_APP_CONF_DIR, Path.class, confFile.toPath());
|
||||||
}
|
}
|
||||||
|
this.resourceFactory.register(RESNAME_APP_ENV, Environment.class, appEnvironment);
|
||||||
{
|
{
|
||||||
int nid = config.getIntValue("nodeid", 0);
|
int nid = config.getIntValue("nodeid", 0);
|
||||||
this.nodeid = nid;
|
this.nodeid = nid;
|
||||||
|
|||||||
52
src/main/java/org/redkale/util/Environment.java
Normal file
52
src/main/java/org/redkale/util/Environment.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
package org.redkale.util;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境变量, 相当于只读的Properties
|
||||||
|
*
|
||||||
|
* 详情见: https://redkale.org
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
public class Environment implements java.io.Serializable {
|
||||||
|
|
||||||
|
private final Properties properties;
|
||||||
|
|
||||||
|
public Environment() {
|
||||||
|
this(new Properties());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Environment(Properties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> keySet() {
|
||||||
|
return (Set) properties.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(String key) {
|
||||||
|
return properties.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty(String key) {
|
||||||
|
return properties.getProperty(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty(String key, String defaultValue) {
|
||||||
|
return properties.getProperty(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEach(BiConsumer<String, String> action) {
|
||||||
|
properties.forEach((BiConsumer) action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return properties.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user