mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-07 01:08:26 +08:00
update dynamic properties
This commit is contained in:
parent
b14c53b81d
commit
fdd84b85b6
@ -136,24 +136,9 @@ public class LoadConfig {
|
|||||||
public void loadPropertyFile() {
|
public void loadPropertyFile() {
|
||||||
ClassPathResource classPathResource = new ClassPathResource(Context.getConfig().getPropertyFile());
|
ClassPathResource classPathResource = new ClassPathResource(Context.getConfig().getPropertyFile());
|
||||||
try (
|
try (
|
||||||
InputStream inputStream = classPathResource.getInputStream();
|
InputStream inputStream = classPathResource.getInputStream()
|
||||||
InputStreamReader streamReader = new InputStreamReader(inputStream, "utf-8");
|
) {
|
||||||
BufferedReader reader = new BufferedReader(streamReader)) {
|
Context.getDynamicProperties().load(inputStream);
|
||||||
String line = "";
|
|
||||||
Map<String, String> dynamicProperties = Context.getDynamicProperties();
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
line = line.trim();
|
|
||||||
if (line.length()==0 || line.startsWith("#") || line.startsWith("//")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int i = line.indexOf("=");
|
|
||||||
if (i<1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String propertyStr = line.substring(0, i).trim();
|
|
||||||
String valueStr = line.substring(i+1).trim();
|
|
||||||
dynamicProperties.put(propertyStr,valueStr);
|
|
||||||
}
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
log.severe("kotime=>dynamic.properties requires utf-8");
|
log.severe("kotime=>dynamic.properties requires utf-8");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@ -394,7 +394,7 @@ public class KoTimeController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String[] textSplit = textParam.getText().trim().split("\n");
|
String[] textSplit = textParam.getText().trim().split("\n");
|
||||||
Map<String, String> dynamicProperties = Context.getDynamicProperties();
|
Properties dynamicProperties = Context.getDynamicProperties();
|
||||||
for (String line : textSplit) {
|
for (String line : textSplit) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.length()==0 || line.startsWith("#") || line.startsWith("//")) {
|
if (line.length()==0 || line.startsWith("#") || line.startsWith("//")) {
|
||||||
@ -407,7 +407,7 @@ public class KoTimeController {
|
|||||||
String propertyStr = line.substring(0, i).trim();
|
String propertyStr = line.substring(0, i).trim();
|
||||||
String valueStr = line.substring(i+1).trim();
|
String valueStr = line.substring(i+1).trim();
|
||||||
log.info("updated property: "+propertyStr+"=("+dynamicProperties.get(propertyStr)+"->"+valueStr+")");
|
log.info("updated property: "+propertyStr+"=("+dynamicProperties.get(propertyStr)+"->"+valueStr+")");
|
||||||
dynamicProperties.put(propertyStr,valueStr);
|
dynamicProperties.setProperty(propertyStr,valueStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -420,10 +420,10 @@ public class KoTimeController {
|
|||||||
Map map = new HashMap();
|
Map map = new HashMap();
|
||||||
map.put("state", 0);
|
map.put("state", 0);
|
||||||
map.put("message", "文件不能为空");
|
map.put("message", "文件不能为空");
|
||||||
Map<String, String> dynamicProperties = Context.getDynamicProperties();
|
Properties dynamicProperties = Context.getDynamicProperties();
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (String key : dynamicProperties.keySet()) {
|
for (String key : dynamicProperties.stringPropertyNames()) {
|
||||||
String value = dynamicProperties.get(key);
|
String value = dynamicProperties.getProperty(key);
|
||||||
if (value!=null) {
|
if (value!=null) {
|
||||||
stringBuilder.append(key+"="+value+"\n");
|
stringBuilder.append(key+"="+value+"\n");
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/main/java/cn/langpy/kotime/model/OrderlyProperties.java
Normal file
24
src/main/java/cn/langpy/kotime/model/OrderlyProperties.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package cn.langpy.kotime.model;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orderly Properties
|
||||||
|
* create an orderly Properties by extending Properties
|
||||||
|
*/
|
||||||
|
public class OrderlyProperties extends Properties {
|
||||||
|
private final LinkedHashSet<String> propertyNames = new LinkedHashSet<String>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> stringPropertyNames() {
|
||||||
|
return propertyNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Object put(Object key, Object value) {
|
||||||
|
propertyNames.add(key+"");
|
||||||
|
return super.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package cn.langpy.kotime.util;
|
|||||||
|
|
||||||
import cn.langpy.kotime.config.DefaultConfig;
|
import cn.langpy.kotime.config.DefaultConfig;
|
||||||
import cn.langpy.kotime.handler.InvokedHandler;
|
import cn.langpy.kotime.handler.InvokedHandler;
|
||||||
|
import cn.langpy.kotime.model.OrderlyProperties;
|
||||||
import cn.langpy.kotime.service.GraphService;
|
import cn.langpy.kotime.service.GraphService;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
@ -9,8 +10,7 @@ import javax.sql.DataSource;
|
|||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zhangchang
|
* zhangchang
|
||||||
@ -22,7 +22,7 @@ public class Context {
|
|||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static StringRedisTemplate stringRedisTemplate;
|
private static StringRedisTemplate stringRedisTemplate;
|
||||||
private static GraphService saver;
|
private static GraphService saver;
|
||||||
private static Map<String,String> dynamicProperties;
|
private static Properties dynamicProperties;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
config = new DefaultConfig();
|
config = new DefaultConfig();
|
||||||
@ -30,7 +30,7 @@ public class Context {
|
|||||||
config.setEnable(true);
|
config.setEnable(true);
|
||||||
config.setLogLanguage("chinese");
|
config.setLogLanguage("chinese");
|
||||||
invokedHandlers = new ArrayList<>();
|
invokedHandlers = new ArrayList<>();
|
||||||
dynamicProperties = new ConcurrentHashMap<>();
|
dynamicProperties = new OrderlyProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,11 +82,11 @@ public class Context {
|
|||||||
Context.saver = saver;
|
Context.saver = saver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> getDynamicProperties() {
|
public static Properties getDynamicProperties() {
|
||||||
return dynamicProperties;
|
return dynamicProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDynamicProperties(Map<String, String> dynamicProperties) {
|
public static void setDynamicProperties(Properties dynamicProperties) {
|
||||||
Context.dynamicProperties = dynamicProperties;
|
Context.dynamicProperties = dynamicProperties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -175,11 +175,11 @@ public class KoUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setProperty(String propertyName, String propertyValue) {
|
public static void setProperty(String propertyName, String propertyValue) {
|
||||||
Context.getDynamicProperties().put(propertyName, propertyValue);
|
Context.getDynamicProperties().setProperty(propertyName, propertyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getProperty(String propertyName) {
|
public static String getProperty(String propertyName) {
|
||||||
String value = Context.getDynamicProperties().get(propertyName);
|
String value = Context.getDynamicProperties().getProperty(propertyName);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user