Skip to content

Commit

Permalink
[#1370] Operator fails on startup
Browse files Browse the repository at this point in the history
Rework FeatureDomainRegistry
  • Loading branch information
ruspl-afed committed May 23, 2024
1 parent 011c801 commit 234433b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="load" deactivate="unload" name="org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry">
<property name="org.eclipse.passage.lic.emf.edit.domain.name" value="features"/>
<property name="org.eclipse.passage.lic.emf.edit.file.extension" value="features_xmi"/>
<service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@
@SuppressWarnings("restriction")
@Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + FeaturesPackage.eNAME,
EditingDomainRegistryAccess.PROPERTY_FILE_EXTENSION + '=' + "features_xmi" })
public class FeatureDomainRegistry extends BaseDomainRegistry<FeatureSet>
public final class FeatureDomainRegistry extends BaseDomainRegistry<FeatureSet>
implements FeatureRegistry, EditingDomainRegistry<FeatureSet> {

private final Map<String, FeatureSet> sets = new HashMap<>();
private final Map<String, Feature> features = new HashMap<>();
private final Map<String, Map<String, FeatureVersion>> versions = new HashMap<>();

private EventAdmin events;
private final List<EventAdmin> events = new ArrayList<>();

@Reference
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
Expand All @@ -81,15 +81,13 @@ public void unbindGear(OperatorGearSupplier supplier) {
super.unbindGear(supplier);
}

@Override
@Activate
public void activate(Map<String, Object> properties) {
public void load(Map<String, Object> properties) {
super.activate(properties);
}

@Deactivate
@Override
public void deactivate(Map<String, Object> properties) {
public void unload(Map<String, Object> properties) {
versions.values().forEach(Map::clear);
versions.clear();
features.clear();
Expand Down Expand Up @@ -153,7 +151,7 @@ void registerFeatureSet(FeatureSet fs) {
Platform.getLog(getClass())
.warn(NLS.bind(FeaturesCoreMessages.FeatureDomain_instance_duplication_message, existing, fs));
}
events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_CREATE, fs).get());
events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_CREATE, fs).get());
fs.getFeatures().forEach(this::registerFeature);
}

Expand All @@ -163,7 +161,7 @@ void registerFeature(Feature feature) {
Platform.getLog(getClass())
.warn(NLS.bind(FeaturesCoreMessages.FeatureDomain_instance_duplication_message, existing, feature));
}
events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_CREATE, feature).get());
events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_CREATE, feature).get());
feature.getFeatureVersions().forEach(fv -> registerFeatureVersion(feature, fv));
}

Expand All @@ -175,21 +173,21 @@ void registerFeatureVersion(Feature feature, FeatureVersion version) {
Platform.getLog(getClass())
.warn(NLS.bind(FeaturesCoreMessages.FeatureDomain_instance_duplication_message, existing, version));
}
events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_CREATE, version).get());
events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_CREATE, version).get());
}

void unregisterFeatureSet(String id) {
FeatureSet removed = sets.remove(id);
if (removed != null) {
events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_DELETE, removed).get());
events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_DELETE, removed).get());
removed.getFeatures().stream().map(Feature::getIdentifier).forEach(this::unregisterFeature);
}
}

void unregisterFeature(String id) {
Feature removed = features.remove(id);
if (removed != null) {
events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_DELETE, removed).get());
events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_DELETE, removed).get());
removed.getFeatureVersions().forEach(fv -> unregisterFeatureVersion(id, fv.getVersion()));
}
}
Expand All @@ -199,14 +197,18 @@ void unregisterFeatureVersion(String featureId, String version) {
if (map != null) {
FeatureVersion removed = map.remove(version);
if (removed != null) {
events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_DELETE, removed).get());
events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_DELETE, removed).get());
}
if (map.isEmpty()) {
versions.remove(version);
}
}
}

private EventAdmin events() {
return events.stream().findAny().get();
}

@Override
public EClass getContentClassifier() {
return FeaturesPackage.eINSTANCE.getFeatureSet();
Expand Down

0 comments on commit 234433b

Please sign in to comment.