Last active
December 15, 2015 19:19
-
-
Save migue/5310926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
void activate(ComponentContext componentContext) { | |
System.out.println("Starting the metrics manager. Waiting for metrics providers . . ."); | |
_executorService.execute(new Runnable() { | |
@Override | |
public void run() { | |
while (true) { | |
// run forever and collect metrics every 2 seconds | |
List<Metric> metrics = collect(); | |
for (Metric metric : metrics) { | |
System.out.println(metric.display()); | |
} | |
try { | |
Thread.currentThread().sleep(2000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
}); | |
} | |
... | |
protected List<Metric> collect() { | |
List<Metric> metrics = new ArrayList<Metric>(); | |
for (Long extensionId : _extensions.keySet()) { | |
MetricsProvider metricsProvider = _extensions.get(extensionId); | |
metrics.add(metricsProvider.collect()); | |
} | |
return metrics; | |
} | |
private Map<Long, MetricsProvider> _extensions = new HashMap<Long, MetricsProvider>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment