Subversion Repositories XServices

Rev

Rev 201 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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