201 |
brianR |
1 |
package net.brutex.xservices.util;
|
|
|
2 |
|
|
|
3 |
import lombok.Data;
|
|
|
4 |
import lombok.Singular;
|
|
|
5 |
import lombok.extern.slf4j.Slf4j;
|
|
|
6 |
import org.apache.commons.configuration2.Configuration;
|
|
|
7 |
import org.apache.commons.configuration2.FileBasedConfiguration;
|
|
|
8 |
import org.apache.commons.configuration2.PropertiesConfiguration;
|
|
|
9 |
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
|
|
|
10 |
import org.apache.commons.configuration2.builder.PropertiesBuilderParametersImpl;
|
|
|
11 |
import org.apache.commons.configuration2.ex.ConfigurationException;
|
|
|
12 |
|
|
|
13 |
import javax.servlet.ServletContext;
|
|
|
14 |
|
|
|
15 |
/**
|
|
|
16 |
* A configuration object for the MiscService -> Eventmanager. Implemented as singleton.
|
|
|
17 |
* @author Brian Rosenberger, bru@brutex.de
|
|
|
18 |
**/
|
|
|
19 |
@Data
|
|
|
20 |
@Slf4j
|
|
|
21 |
public class EventmanagerConfiguration {
|
|
|
22 |
|
|
|
23 |
public static final String KEY = "net.brutex.xservices.EventmanagerConfiguration";
|
|
|
24 |
|
|
|
25 |
private static class InstanceHolder {
|
|
|
26 |
public static final EventmanagerConfiguration instance = new EventmanagerConfiguration();
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
private EventmanagerConfiguration() {
|
|
|
30 |
refreshConfig();
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public static EventmanagerConfiguration getInstance() {
|
|
|
34 |
return InstanceHolder.instance;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
private String targeturl;
|
|
|
39 |
private int interval;
|
|
|
40 |
private String jdbc_memdb;
|
|
|
41 |
private String jdbc_filedb;
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
public synchronized EventmanagerConfiguration refreshConfig() {
|
|
|
45 |
log.trace("Reading EventmanagerConfiguration from file eventmanager.properties.");
|
|
|
46 |
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
|
|
|
47 |
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
|
|
|
48 |
.configure(new PropertiesBuilderParametersImpl().setFileName("eventmanager.properties"));
|
|
|
49 |
|
|
|
50 |
try {
|
|
|
51 |
Configuration config = builder.getConfiguration();
|
|
|
52 |
|
|
|
53 |
/* Read from eventmanager.properties file */
|
|
|
54 |
this.targeturl = config.getString("target.url");
|
|
|
55 |
this.interval = config.getInt("interval", 10);
|
|
|
56 |
this.jdbc_memdb = config.getString("memdb", "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=-1;");
|
|
|
57 |
this.jdbc_filedb = config.getString("fdb", "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=-1;");
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
} catch (ConfigurationException e) {
|
|
|
61 |
log.error("Error loading configuration for event manager in XServices MiscServices: {}", e.getMessage());
|
|
|
62 |
throw new RuntimeException(e);
|
|
|
63 |
}
|
|
|
64 |
return this;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
}
|