-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.java
More file actions
98 lines (77 loc) · 2.31 KB
/
Copy pathConfiguration.java
File metadata and controls
98 lines (77 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.ashishp.dc.assignment.cl.config;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Configuration of the system.
*
* @author <a href="http://www.linkedin.com/in/aashishpanchal">Aashish</a>
*
*/
public final class Configuration {
private static Configuration instance;
private static final String CONFIG_FILE = "chandy-lamport.conf";
private final Properties properties = new Properties();
private static final Logger LOGGER = LoggerFactory.getLogger(Configuration.class);
static {
instance = new Configuration();
}
/**
* Create default configuration.
*/
private Configuration() {
super();
loadConfiguration();
}
/**
*
* @return instance of system configuration.
*/
public static Configuration getInstance() {
return instance;
}
public int getRmiPort() {
return Integer.parseInt(properties.getProperty("rmi-port"));
}
public int getInitialAmount() {
return Integer.parseInt(properties.getProperty("initial-amount"));
}
public int getMinAmount() {
return Integer.parseInt(properties.getProperty("min-amount"));
}
public int getMaxAmount() {
return Integer.parseInt(properties.getProperty("max-amount"));
}
public int getTimeoutFrequency() {
return Integer.parseInt(properties.getProperty("timeout-frequency"));
}
public String getTimeoutUnit() {
return properties.getProperty("timeout-unit");
}
/**
* loads configuration file.
*/
private void loadConfiguration() {
LOGGER.debug("Loading Configuration...");
try {
properties.load(new FileInputStream(CONFIG_FILE));
} catch (FileNotFoundException e) {
LOGGER.error("Unable to find '{}' configuration file. Make sure it is available in class path.",
CONFIG_FILE, e);
} catch (IOException e) {
LOGGER.error("Failed to load '{}' file.", CONFIG_FILE, e);
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(Configuration.class).add("RMI port", getRmiPort())
.add("INITIAL_BALANCE", getInitialAmount()).add("MIN_AMOUNT", getMinAmount())
.add("MAX_AMOUNT", getMaxAmount())
.add("TIMEOUT_FREQUENCY", getTimeoutFrequency())
.add("TIMEOUT_UNIT", getTimeoutUnit()).toString();
}
}