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