Skip to content

Commit

Permalink
[#1370] Operator fails on startup
Browse files Browse the repository at this point in the history
* make cardinality explicit
* make `activate` method final for base class
* make `deactivate` method final for base class
  • Loading branch information
ruspl-afed committed May 23, 2024
1 parent 1207a61 commit 02cd27b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<provide interface="org.eclipse.passage.loc.internal.agreements.AgreementRegistry"/>
<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="bindEventAdmin" cardinality="1..1" 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"/>
<implementation class="org.eclipse.passage.loc.internal.agreements.core.AgreementDomainRegistry"/>
</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 @@ -46,6 +47,7 @@
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")
Expand All @@ -56,7 +58,17 @@ public final class AgreementDomainRegistry extends BaseDomainRegistry<AgreementG

private final Map<String, AgreementGroup> groups = new HashMap<>();
private final Map<String, Agreement> agreements = new HashMap<>();
private EventAdmin events;

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

@Reference(cardinality = ReferenceCardinality.MANDATORY)
public void bindEventAdmin(EventAdmin admin) {
this.events.add(admin);
}

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

@Activate
public void load(Map<String, Object> properties) {
Expand All @@ -81,15 +93,6 @@ public void unbindGear(OperatorGearSupplier supplier) {
super.unbindGear(supplier);
}

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

public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) {
this.events = null;
}

@Override
public String getFileExtension() {
return "agreements_xmi"; //$NON-NLS-1$
Expand Down Expand Up @@ -144,7 +147,7 @@ public void registerAgreementGroup(AgreementGroup group) {
Platform.getLog(getClass()).warn(msg);
}
brush(group);
events.postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_GROUP_CREATE, group).get());
events().postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_GROUP_CREATE, group).get());
group.getAgreements().forEach(u -> registerAgreement(u));
}

Expand All @@ -162,24 +165,28 @@ public void registerAgreement(Agreement agreement) {
agreement);
Platform.getLog(getClass()).warn(msg);
}
events.postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_CREATE, agreement).get());
events().postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_CREATE, agreement).get());
}

public void unregisterAgreementGroup(String id) {
AgreementGroup removed = groups.remove(id);
if (removed != null) {
events.postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_GROUP_DELETE, removed).get());
events().postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_GROUP_DELETE, removed).get());
removed.getAgreements().forEach(u -> unregisterAgreement(u.getIdentifier()));
}
}

public void unregisterAgreement(String id) {
Agreement removed = agreements.remove(id);
if (removed != null) {
events.postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_DELETE, removed).get());
events().postEvent(new EquinoxEvent(AgreementRegistryEvents.AGREEMENT_DELETE, removed).get());
}
}

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

@Override
public EClass getContentClassifier() {
return AgreementsPackage.eINSTANCE.getAgreementGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void unbindGear(OperatorGearSupplier supplier) {
}
}

protected void activate(Map<String, Object> properties) {
protected final void activate(Map<String, Object> properties) {
domainName = String.valueOf(properties.get(EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME));
getEditingDomain().getResourceSet().eAdapters().add(contentAdapter);
try {
Expand Down Expand Up @@ -110,7 +110,7 @@ protected void logDiagnostic(Diagnostic diagnostic) {

protected abstract DomainContentAdapter<I, ? extends EditingDomainRegistry<I>> createContentAdapter();

protected void deactivate(@SuppressWarnings("unused") Map<String, Object> properties) {
protected final void deactivate(@SuppressWarnings("unused") Map<String, Object> properties) {
try {
gear.stream()//
.findFirst()//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<provide interface="org.eclipse.passage.loc.internal.features.FeatureRegistry"/>
<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="bindEventAdmin" cardinality="1..1" 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"/>
<implementation class="org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
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")
Expand All @@ -61,7 +62,7 @@ public final class FeatureDomainRegistry extends BaseDomainRegistry<FeatureSet>

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

@Reference
@Reference(cardinality = ReferenceCardinality.MANDATORY)
public void bindEventAdmin(EventAdmin admin) {
this.events.add(admin);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<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="bindEventAdmin" cardinality="1..1" 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"/>
<implementation class="org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;

@Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + LicensesPackage.eNAME,
Expand All @@ -56,7 +57,7 @@ public final class LicenseDomainRegistry extends BaseDomainRegistry<LicensePlan>

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

@Reference
@Reference(cardinality = ReferenceCardinality.MANDATORY)
public void bindEventAdmin(EventAdmin admin) {
this.events.add(admin);
}
Expand Down

0 comments on commit 02cd27b

Please sign in to comment.