Skip to content

Commit fc5e365

Browse files
committed
FELIX-6399 : Reduce resource consumption during component checks
1 parent 058c863 commit fc5e365

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

systemready/src/main/java/org/apache/felix/systemready/impl/ComponentsCheck.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232
import org.apache.felix.systemready.StateType;
3333
import org.apache.felix.systemready.SystemReadyCheck;
3434
import org.osgi.framework.BundleContext;
35+
import org.osgi.framework.InvalidSyntaxException;
36+
import org.osgi.framework.ServiceEvent;
37+
import org.osgi.framework.ServiceListener;
3538
import org.osgi.service.component.annotations.Activate;
3639
import org.osgi.service.component.annotations.Component;
3740
import org.osgi.service.component.annotations.ConfigurationPolicy;
41+
import org.osgi.service.component.annotations.Deactivate;
3842
import org.osgi.service.component.annotations.Reference;
3943
import org.osgi.service.component.runtime.ServiceComponentRuntime;
4044
import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
@@ -45,11 +49,12 @@
4549
import org.slf4j.LoggerFactory;
4650

4751
@Component(
52+
service = {SystemReadyCheck.class},
4853
name = ComponentsCheck.PID,
4954
configurationPolicy = ConfigurationPolicy.REQUIRE
5055
)
5156
@Designate(ocd=ComponentsCheck.Config.class)
52-
public class ComponentsCheck implements SystemReadyCheck {
57+
public class ComponentsCheck implements SystemReadyCheck, ServiceListener {
5358

5459
public static final String PID = "org.apache.felix.systemready.impl.ComponentsCheck";
5560

@@ -75,18 +80,31 @@ public class ComponentsCheck implements SystemReadyCheck {
7580

7681
private StateType type;
7782

78-
volatile ServiceComponentRuntime scr;
83+
@Reference
84+
private ServiceComponentRuntime scr;
7985

8086
private final AtomicReference<CheckStatus> cache = new AtomicReference<>();
8187

8288
private static final CheckStatus INVALID = new CheckStatus("invalid", StateType.READY, CheckStatus.State.RED, "invalid");
8389

8490
@Activate
85-
public void activate(final BundleContext ctx, final Config config) throws InterruptedException {
91+
public void activate(final BundleContext ctx, final Config config) throws InterruptedException, InvalidSyntaxException {
8692
this.analyzer = new DSRootCause(scr);
8793
this.type = config.type();
8894
this.componentsList = Arrays.asList(config.components_list());
8995
this.cache.set(INVALID);
96+
// ctx.addServiceListener(this, "(objectClass=" + ServiceComponentRuntime.class.getName() + ")");
97+
}
98+
99+
@Deactivate
100+
public void deactivate(final BundleContext ctx) {
101+
// ctx.removeServiceListener(this);
102+
}
103+
104+
@Override
105+
public void serviceChanged(ServiceEvent event) {
106+
// log.info("CALLED");
107+
this.cache.set(INVALID);
90108
}
91109

92110
@Override
@@ -109,6 +127,7 @@ private List<DSComp> getComponents(final Collection<ComponentDescriptionDTO> des
109127
@Override
110128
public CheckStatus getStatus() {
111129
CheckStatus result = null;
130+
/*
112131
while ( result == null )
113132
{
114133
this.cache.compareAndSet(INVALID, null);
@@ -119,10 +138,7 @@ public CheckStatus getStatus() {
119138
}
120139
else if ( result == null )
121140
{
122-
// get component description DTOs only once
123-
final Collection<ComponentDescriptionDTO> descriptions = scr.getComponentDescriptionDTOs();
124-
125-
final List<DSComp> watchedComps = getComponents(descriptions);
141+
*/ final List<DSComp> watchedComps = getComponents(scr.getComponentDescriptionDTOs());
126142
if (watchedComps.size() < componentsList.size()) {
127143
final List<String> missed = new ArrayList<>(this.componentsList);
128144
for(final DSComp c : watchedComps)
@@ -141,13 +157,13 @@ else if ( result == null )
141157
throw e;
142158
}
143159
}
144-
if ( !this.cache.compareAndSet(null, result) )
160+
/* if ( !this.cache.compareAndSet(null, result) )
145161
{
146162
result = null;
147163
}
148164
}
149165
}
150-
return result;
166+
*/ return result;
151167
}
152168

153169
private CheckStatus.State status(DSComp component) {
@@ -160,18 +176,4 @@ private void addDetails(final DSComp component, final StringBuilder details) {
160176
RootCausePrinter printer = new RootCausePrinter(st -> details.append(st + "\n"));
161177
printer.print(component);
162178
}
163-
164-
@Reference(updated = "updatedServiceComponentRuntime")
165-
private void setServiceComponentRuntime(final ServiceComponentRuntime c) {
166-
this.scr = c;
167-
}
168-
169-
private void unsetServiceComponentRuntime(final ServiceComponentRuntime c) {
170-
this.scr = null;
171-
}
172-
173-
private void updatedServiceComponentRuntime(final ServiceComponentRuntime c) {
174-
// change in DS - update cache
175-
this.cache.set(INVALID);
176-
}
177179
}

0 commit comments

Comments
 (0)