mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 22:45:21 +01:00
Basic configuration infrastructure available
This commit is contained in:
parent
df5b2dc15e
commit
86d642596e
4 changed files with 34 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
6
monitor/src/main/resources/metrics.properties
Normal file
6
monitor/src/main/resources/metrics.properties
Normal file
|
@ -0,0 +1,6 @@
|
|||
#Dummy Metric
|
||||
Dummy.setup.message=Dummy is here
|
||||
Dummy.run.interval=5
|
||||
|
||||
#Another Metric
|
||||
Another.run.interval=5
|
Loading…
Add table
Reference in a new issue