32
32
import org .apache .felix .systemready .StateType ;
33
33
import org .apache .felix .systemready .SystemReadyCheck ;
34
34
import org .osgi .framework .BundleContext ;
35
+ import org .osgi .framework .InvalidSyntaxException ;
36
+ import org .osgi .framework .ServiceEvent ;
37
+ import org .osgi .framework .ServiceListener ;
35
38
import org .osgi .service .component .annotations .Activate ;
36
39
import org .osgi .service .component .annotations .Component ;
37
40
import org .osgi .service .component .annotations .ConfigurationPolicy ;
41
+ import org .osgi .service .component .annotations .Deactivate ;
38
42
import org .osgi .service .component .annotations .Reference ;
39
43
import org .osgi .service .component .runtime .ServiceComponentRuntime ;
40
44
import org .osgi .service .component .runtime .dto .ComponentDescriptionDTO ;
45
49
import org .slf4j .LoggerFactory ;
46
50
47
51
@ Component (
52
+ service = {SystemReadyCheck .class },
48
53
name = ComponentsCheck .PID ,
49
54
configurationPolicy = ConfigurationPolicy .REQUIRE
50
55
)
51
56
@ Designate (ocd =ComponentsCheck .Config .class )
52
- public class ComponentsCheck implements SystemReadyCheck {
57
+ public class ComponentsCheck implements SystemReadyCheck , ServiceListener {
53
58
54
59
public static final String PID = "org.apache.felix.systemready.impl.ComponentsCheck" ;
55
60
@@ -75,18 +80,31 @@ public class ComponentsCheck implements SystemReadyCheck {
75
80
76
81
private StateType type ;
77
82
78
- volatile ServiceComponentRuntime scr ;
83
+ @ Reference
84
+ private ServiceComponentRuntime scr ;
79
85
80
86
private final AtomicReference <CheckStatus > cache = new AtomicReference <>();
81
87
82
88
private static final CheckStatus INVALID = new CheckStatus ("invalid" , StateType .READY , CheckStatus .State .RED , "invalid" );
83
89
84
90
@ 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 {
86
92
this .analyzer = new DSRootCause (scr );
87
93
this .type = config .type ();
88
94
this .componentsList = Arrays .asList (config .components_list ());
89
95
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 );
90
108
}
91
109
92
110
@ Override
@@ -109,6 +127,7 @@ private List<DSComp> getComponents(final Collection<ComponentDescriptionDTO> des
109
127
@ Override
110
128
public CheckStatus getStatus () {
111
129
CheckStatus result = null ;
130
+ /*
112
131
while ( result == null )
113
132
{
114
133
this.cache.compareAndSet(INVALID, null);
@@ -119,10 +138,7 @@ public CheckStatus getStatus() {
119
138
}
120
139
else if ( result == null )
121
140
{
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 ());
126
142
if (watchedComps .size () < componentsList .size ()) {
127
143
final List <String > missed = new ArrayList <>(this .componentsList );
128
144
for (final DSComp c : watchedComps )
@@ -141,13 +157,13 @@ else if ( result == null )
141
157
throw e ;
142
158
}
143
159
}
144
- if ( !this .cache .compareAndSet (null , result ) )
160
+ /* if ( !this.cache.compareAndSet(null, result) )
145
161
{
146
162
result = null;
147
163
}
148
164
}
149
165
}
150
- return result ;
166
+ */ return result ;
151
167
}
152
168
153
169
private CheckStatus .State status (DSComp component ) {
@@ -160,18 +176,4 @@ private void addDetails(final DSComp component, final StringBuilder details) {
160
176
RootCausePrinter printer = new RootCausePrinter (st -> details .append (st + "\n " ));
161
177
printer .print (component );
162
178
}
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
- }
177
179
}
0 commit comments