Added conf file for configuring server ports

Former-commit-id: 16f48cef9ddfdf3722bff863eb520e807d7c0c37
This commit is contained in:
Ziver Koc 2015-12-07 21:20:47 +01:00
parent 46728b4768
commit 8cd81766a0
6 changed files with 37 additions and 11 deletions

2
hal.conf Executable file
View file

@ -0,0 +1,2 @@
http_port=8080
sync_port=6666

38
src/se/koc/hal/HalContext.java Normal file → Executable file
View file

@ -2,15 +2,41 @@ package se.koc.hal;
import zutil.db.DBConnection;
import java.io.FileReader;
import java.util.Properties;
public class HalContext {
// Constants
private static final String CONF_FILE = "hal.conf";
// Variables
public static DBConnection db;
public static DBConnection db;
public static Properties conf;
private static Properties defaultConf;
static {
defaultConf = new Properties();
defaultConf.setProperty("http_port", ""+8080);
defaultConf.setProperty("sync_port", ""+6666);
HalContext.initialize();
}
public static void initialize() throws Exception{
db = new DBConnection(DBConnection.DBMS.SQLite, "hal.db");
public static void initialize(){
try {
// Read conf
conf = new Properties(defaultConf);
FileReader in = new FileReader(CONF_FILE);
conf.load(in);
in.close();
// Init DB
db = new DBConnection(DBConnection.DBMS.SQLite, "hal.db");
} catch (Exception e){
throw new RuntimeException(e);
}
}
}

View file

@ -31,8 +31,6 @@ public class PowerChallenge {
public static void main(String[] args) throws Exception {
HalContext.initialize();
// init logging
LogUtil.setGlobalLevel(Level.ALL);
LogUtil.setGlobalFormatter(new CompactLogFormatter());
@ -43,7 +41,8 @@ public class PowerChallenge {
daemon.initiate(daemonTimer);
}
HttpServer http = new HttpServer(80);
HttpServer http = new HttpServer(
Integer.parseInt(HalContext.conf.getProperty("http_port")));
http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/")));
http.setPage("/", new PCOverviewHttpPage());
http.setPage("/configure", new PCConfigureHttpPage());

View file

@ -21,11 +21,10 @@ import zutil.net.threaded.ThreadedTCPNetworkServerThread;
public class DataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon{
private static final Logger logger = LogUtil.getLogger();
public static final int SERVER_PORT = 6666;
public DataSynchronizationDaemon() {
super(SERVER_PORT);
super(Integer.parseInt(HalContext.conf.getProperty("sync_port")));
}
@Override

0
src/se/koc/hal/page/PCConfigureHttpPage.java Normal file → Executable file
View file

0
src/se/koc/hal/page/PCHeatMapHttpPage.java Normal file → Executable file
View file