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