config 파일을 모니터링하는 부분의 코드가 변경이 되었습니다.
기존의 net.sjava.config.util.Watcher 클래스를 Timer를 이용하는 TimerTask로 변경을 하였습니다.
사용법은 http://www.sjava.net/121를 참고하시면 됩니다.
설정파일을 저장하고 가져오는 라이브러리입니다.
sjava-config는 http://www.jconfig.org/ 의 jconfig를 보고 필요한 형태(xml만 지원)로만 개발했습니다.
여러형태의 설정파일을 읽어올 수 있도록 common한 기능은 추상 클래스로 빼고 설정을 읽는 코드는 하위 클래스에서 구현을 합니다.
System.out.println("- get vlaue test ---");
System.out.println(configHandler.getValue("config", "watch"));
System.out.println(configHandler.getValue("config", "interval"));
System.out.println(configHandler.getValue("log", "host"));
System.out.println(configHandler.getValue("log", "port"));
System.out.println(configHandler.getValue("auth", "host"));
System.out.println(configHandler.getValue("auth", "port"));
System.out.println("- default value test ---");
System.out.println(configHandler.getValue("config", "watch", "false"));
System.out.println(configHandler.getValue("config", "interval", "11"));
System.out.println(configHandler.getValue("log", "host", "222.222.222.222"));
System.out.println(configHandler.getValue("log", "port", "20003"));
System.out.println(configHandler.getValue("auth", "host", "222.222.222.222"));
System.out.println("- array value test ---");
for(int i = 0; i < configHandler.getValues("log", "host").length; i++) {
System.out.println(configHandler.getValues("log", "host")[i].toString());
}
for(int i = 0; i < configHandler.getValues("auth", "host").length; i++) {
System.out.println(configHandler.getValues("auth", "host")[i].toString());
}
System.out.println("- add value ---");
configHandler.addValue("test", "host", "1.1.1.1");
System.out.println(configHandler.getValue("test", "host"));
System.out.println("- modify value ---");
configHandler.setValue("test", "host", "2.2.2.2");
System.out.println(configHandler.getValue("test", "host"));