From 2095d232b11cbff040a72d3eb62ee8e39ab78463 Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Thu, 23 May 2024 14:34:12 +0300 Subject: [PATCH] [#1370] Operator fails on startup Rework UserDomainRegistry --- ...internal.users.core.UserDomainRegistry.xml | 4 +-- .../users/core/UserDomainRegistry.java | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml b/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml index d8d16c0ac..047f82b59 100644 --- a/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml @@ -1,12 +1,12 @@ - + - + \ No newline at end of file diff --git a/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java b/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java index 09c480b9b..889235c65 100644 --- a/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -45,26 +46,27 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.event.EventAdmin; @SuppressWarnings("restriction") @Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + UsersPackage.eNAME, EditingDomainRegistryAccess.PROPERTY_FILE_EXTENSION + '=' + "users_xmi" }) -public class UserDomainRegistry extends BaseDomainRegistry +public final class UserDomainRegistry extends BaseDomainRegistry implements UserRegistry, EditingDomainRegistry { private final Map origins = new HashMap<>(); private final Map users = new HashMap<>(); - private EventAdmin events; + private final List events = new ArrayList<>(); - @Reference + @Reference(cardinality = ReferenceCardinality.MANDATORY) public void bindEventAdmin(EventAdmin admin) { - this.events = admin; + this.events.add(admin); } - public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) { - this.events = null; + public void unbindEventAdmin(EventAdmin admin) { + this.events.remove(admin); } @Override @@ -78,15 +80,13 @@ public void unbindGear(OperatorGearSupplier supplier) { super.unbindGear(supplier); } - @Override @Activate - public void activate(Map properties) { + public void load(Map properties) { super.activate(properties); } @Deactivate - @Override - public void deactivate(Map properties) { + public void unload(Map properties) { users.clear(); origins.clear(); super.deactivate(properties); @@ -138,7 +138,7 @@ void registerUserOrigin(UserOrigin origin) { Platform.getLog(getClass()) .warn(NLS.bind(UsersCoreMessages.UserDomain_instance_duplication_message, existing, origin)); } - events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_CREATE, origin).get()); + events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_CREATE, origin).get()); origin.getUsers().forEach(u -> registerUser(u)); } @@ -148,13 +148,13 @@ void registerUser(User user) { Platform.getLog(getClass()) .warn(NLS.bind(UsersCoreMessages.UserDomain_instance_duplication_message, existing, user)); } - events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_CREATE, user).get()); + events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_CREATE, user).get()); } void unregisterUserOrigin(String id) { UserOrigin removed = origins.remove(id); if (removed != null) { - events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_DELETE, removed).get()); + events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_DELETE, removed).get()); removed.getUsers().forEach(u -> unregisterUser(u.getContact().getEmail())); } } @@ -162,10 +162,14 @@ void unregisterUserOrigin(String id) { void unregisterUser(String userId) { User removed = users.remove(userId); if (removed != null) { - events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_DELETE, removed).get()); + events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_DELETE, removed).get()); } } + private EventAdmin events() { + return events.stream().findAny().get(); + } + @Override public EClass getContentClassifier() { return UsersPackage.eINSTANCE.getUserOrigin();