Skip to content
Snippets Groups Projects
Commit dea3cc8d authored by jkerdreu's avatar jkerdreu
Browse files

Switch Config to a Singleton => Loading default timer value in Device

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Java/branches/0.7@2606 b32b6428-25c9-4566-ad07-03861ab6144f
parent 3c0038e0
No related branches found
No related tags found
No related merge requests found
......@@ -11,9 +11,11 @@ public class Config {
/* As this API clone the Python one, I decided to reuse the same config file */
private final static Logger LOGGER = Logger.getLogger(Device.class.getName());
private Properties cfg = null;
private static Properties cfg = null;
public Config() {
private static Config INSTANCE = new Config();
private Config() {
String fileName = getFileName();
LOGGER.info("Loading config" + fileName);
......@@ -30,35 +32,39 @@ public class Config {
}
}
public static Config getInstance() {
return INSTANCE;
}
public String getFileName() {
var path = Paths.get(System.getProperty("user.home"),".xaal", "xaal.ini");
return path.toString();
}
private Object getValue(String key,Object def) {
private String getValue(String key,String def) {
if (cfg==null) return null;
Object value = cfg.get(key);
String value = (String)cfg.get(key);
if (value==null) return def;
return value;
}
public String getAddress() {
return (String) getValue("address", "224.0.29.200");
return getValue("address", "224.0.29.200");
}
public Integer getPort() {
return (Integer) getValue("poirt", 1236);
return Integer.parseInt(getValue("port", "1236")) ;
}
public Integer getHops() {
return (Integer) getValue("hops", 10);
return Integer.parseInt(getValue("hops", "10"));
}
public Integer getAliveTimer() {
return (Integer) getValue("alive_timer", 300);
return Integer.parseInt(getValue("alive_timer","300"));
}
public String getKey() {
return (String) getValue("key", null);
return getValue("key", "");
}
}
......@@ -34,7 +34,7 @@ public abstract class Device {
private List<Attribute> attributes = new ArrayList<Attribute>();
// internal stuff
private int alivePeriod = 120;
private int alivePeriod = Config.getInstance().getAliveTimer();
private long aliveTimeOut = 0;
public Device(String devType, UUID address) {
......
......@@ -14,7 +14,7 @@ public class Test {
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
Engine eng = new Engine(new Config());
Engine eng = new Engine(Config.getInstance());
eng.init();
Lamp l1 = new Lamp("lamp.dimmer", UUID.fromString("6265eb30-8c59-11e9-98b1-b827ebe99201"));
Lamp l2 = new Lamp("lamp.dimmer", UUID.fromString("6265eb30-8c59-11e9-98b1-b827ebe99202"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment