Basic configuration infrastructure available

This commit is contained in:
Florian Reimair 2018-12-10 14:18:39 +01:00
parent df5b2dc15e
commit 86d642596e
4 changed files with 34 additions and 8 deletions

View file

@ -31,7 +31,7 @@ import bisq.monitor.metric.Metric;
*/
public class Monitor {
public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) throws Exception {
new Monitor().start();
}
@ -43,11 +43,14 @@ public class Monitor {
/**
* Starts up all configured Metrics.
*
* @throws InterruptedException
* @throws Exception
*/
private void start() throws InterruptedException {
private void start() throws Exception {
Properties properties = new Properties();
properties.load(this.getClass().getClassLoader().getResourceAsStream("metrics.properties"));
// assemble Metrics
metrics.add(new Dummy(new Properties()));
metrics.add(new Dummy(properties));
// fire up all Metrics
for (Metric current : metrics)

View file

@ -26,8 +26,10 @@ import java.util.Properties;
*/
public class Dummy extends Metric {
public Dummy(Properties properties) {
public Dummy(final Properties properties) {
super(properties);
System.out.println(this.configuration.toString());
}
@Override

View file

@ -27,11 +27,26 @@ import java.util.Properties;
public abstract class Metric extends Thread {
private volatile boolean shutdown = false;
protected Properties properties;
public Metric(Properties properties) {
/**
* The properties of this very {@link Metric}
*/
protected Properties configuration;
protected Metric(final Properties properties) {
// set as daemon, so that the jvm does not terminate the thread
setDaemon(true);
configure(properties);
// only configure the Properties which belong to us
final Properties myProperties = new Properties();
properties.forEach((k, v) -> {
String key = (String) k;
if (key.startsWith(this.getClass().getSimpleName()))
myProperties.put(key.substring(key.indexOf(".") + 1), v);
});
configure(myProperties);
super.setName(this.getClass().getSimpleName());
}
@ -41,7 +56,7 @@ public abstract class Metric extends Thread {
* @param properties
*/
public void configure(Properties properties) {
this.properties = properties;
}
@Override

View file

@ -0,0 +1,6 @@
#Dummy Metric
Dummy.setup.message=Dummy is here
Dummy.run.interval=5
#Another Metric
Another.run.interval=5