public final class Spectator
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static CompositeRegistry |
globalRegistry()
Returns the global composite registry.
|
static ExtendedRegistry |
registry()
Deprecated.
Use injection or
globalRegistry() instead. |
@Deprecated public static ExtendedRegistry registry()
globalRegistry()
instead.public static CompositeRegistry globalRegistry()
class Main { public static void main(String[] args) { // This is the preferred usage and works well with DI libraries like guice. Setup a // registry and pass it in as needed. Registry registry = new DefaultRegistry(); (new Example1(registry)).start(); // If it is desirable to get data from things using the global registry, then the // registry for the application can be added to the global context. Spectator.globalRegistry().add(registry); Example2 ex2 = new Example2(); ex2.start(); // If the lifecycle is not the same as the jvm, then the registry should be removed // when shutting down. ex2.onShutdown(() -> Spectator.globalRegistry().remove(registry)); } } class Example1 { private final Counter c; Example1(Registry registry) { c = registry.counter("example1"); } ... } class Example2 { private final Counter c; Example2() { c = Spectator.globalRegistry().counter("example1"); } ... }