-import java.util.function.Predicate;
-
-public class Component {
- private final static AtomicBoolean started = new AtomicBoolean(false);
- private final static IdentityHashMap<Object, Component> components = new IdentityHashMap<>();
-
- private static synchronized void registerComponent(Component component) {
- if (started.get()) // TODO make it rellay dynamic
- throw new IllegalStateException("Already activated");
- if (components.containsKey(component.instance))
- throw new IllegalArgumentException("Already registered as component");
- components.put(component.instance, component);
- }
-
- static synchronized Component get(Object instance) {
- if (!components.containsKey(instance))
- throw new IllegalArgumentException("Not registered as component");
- return components.get(instance);
- }
-
- public synchronized static void activate() {
- if (started.get())
- throw new IllegalStateException("Already activated");
- for (Component component : components.values()) {
- component.activationStarted.complete(null);
- }
- started.set(true);
- }