Skip to content

Commit

Permalink
[#1370] Operator fails on startup
Browse files Browse the repository at this point in the history
Rework LicenseDomainRegistry
  • Loading branch information
ruspl-afed committed May 23, 2024
1 parent 234433b commit 33207bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?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.licenses.core.LicenseDomainRegistry">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="load" deactivate="unload" name="org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry">
<property name="org.eclipse.passage.lic.emf.edit.domain.name" value="licenses"/>
<property name="org.eclipse.passage.lic.emf.edit.file.extension" value="licenses_xmi"/>
<service>
<provide interface="org.eclipse.passage.loc.internal.licenses.LicenseRegistry"/>
<provide interface="org.eclipse.passage.loc.internal.emf.EditingDomainRegistry"/>
</service>
<reference bind="bindEventAdmin" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" unbind="unbindEventAdmin"/>
<reference bind="bindGear" interface="org.eclipse.passage.loc.internal.api.OperatorGearSupplier" name="Gear" unbind="unbindGear"/>
<reference cardinality="1..1" field="events" interface="org.osgi.service.event.EventAdmin" name="events"/>
<implementation class="org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry"/>
</scr:component>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,13 +49,21 @@

@Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + LicensesPackage.eNAME,
EditingDomainRegistryAccess.PROPERTY_FILE_EXTENSION + '=' + "licenses_xmi" })
public class LicenseDomainRegistry extends BaseDomainRegistry<LicensePlan>
public final class LicenseDomainRegistry extends BaseDomainRegistry<LicensePlan>
implements LicenseRegistry, EditingDomainRegistry<LicensePlan> {

private final Map<String, LicensePlan> plans = new HashMap<>();

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

@Reference
private EventAdmin events;
public void bindEventAdmin(EventAdmin admin) {
this.events.add(admin);
}

public void unbindEventAdmin(EventAdmin admin) {
this.events.remove(admin);
}

@Override
@Reference
Expand All @@ -68,14 +77,12 @@ public void unbindGear(OperatorGearSupplier supplier) {
}

@Activate
@Override
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) {
plans.clear();
super.deactivate(properties);
}
Expand Down Expand Up @@ -113,17 +120,20 @@ void registerLicensePlan(LicensePlan licensePlan) {
licensePlan);
Platform.getLog(getClass()).warn(msg);
}
events.postEvent(new EquinoxEvent(LicenseRegistryEvents.LICENSE_PLAN_CREATE, licensePlan).get());
events().postEvent(new EquinoxEvent(LicenseRegistryEvents.LICENSE_PLAN_CREATE, licensePlan).get());
}

void unregisterLicensePlan(String identifier) {
LicensePlan removed = plans.remove(identifier);
if (removed != null) {
events.postEvent(new EquinoxEvent(LicenseRegistryEvents.LICENSE_PLAN_DELETE, removed).get());

events().postEvent(new EquinoxEvent(LicenseRegistryEvents.LICENSE_PLAN_DELETE, removed).get());
}
}

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

@Override
protected DomainContentAdapter<LicensePlan, LicenseDomainRegistry> createContentAdapter() {
return new LicensesDomainRegistryTracker(this);
Expand Down

0 comments on commit 33207bc

Please sign in to comment.