this.eventManager.notifyComponentUnregistered(componentEntry.descriptor, this); this.eventManager.notifyComponentRegistered(componentEntry.descriptor, this);
private void removeComponent(Type role, String hint) throws ComponentLifecycleException { // Make sure to remove the entry from the map before destroying it to reduce at the minimum the risk of // lookupping something invalid Map<String, ComponentEntry<?>> entries = this.componentEntries.get(role); if (entries != null) { ComponentEntry<?> componentEntry = entries.remove(hint != null ? hint : RoleHint.DEFAULT_HINT); if (componentEntry != null) { ComponentDescriptor<?> oldDescriptor = componentEntry.descriptor; // We don't want the component manager to dispose itself just because it's not registered as component* // anymore if (componentEntry.instance != this) { // clean any resource associated to the component instance and descriptor releaseComponentEntry(componentEntry); } // Send event about component unregistration if (this.eventManager != null && oldDescriptor != null) { this.eventManager.notifyComponentUnregistered(oldDescriptor, this); } } } }
private <T> void addComponent(ComponentDescriptor<T> descriptor, T instance) { ComponentEntry<T> componentEntry = new ComponentEntry<>(descriptor, instance); // Register new component Map<String, ComponentEntry<?>> entries = this.componentEntries.get(descriptor.getRoleType()); if (entries == null) { entries = new ConcurrentHashMap<>(); this.componentEntries.put(descriptor.getRoleType(), entries); } entries.put(descriptor.getRoleHint(), componentEntry); // Send event about component registration if (this.eventManager != null) { this.eventManager.notifyComponentRegistered(descriptor, this); } }