Skip to content

Commit 45db41c

Browse files
laeubistbischof
authored andcommitted
Adjust to latest spec changes
1 parent 9852731 commit 45db41c

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

runtime/registrar/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@
4646
<artifactId>org.osgi.namespace.implementation</artifactId>
4747
<version>1.0.0</version>
4848
</dependency>
49+
<dependency>
50+
<groupId>org.osgi</groupId>
51+
<artifactId>org.osgi.namespace.service</artifactId>
52+
<version>1.0.0</version>
53+
</dependency>
4954
</dependencies>
5055
</project>

runtime/registrar/src/main/java/org/eclipse/osgi/technology/webservices/registrar/EndpointRegistrar.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@
1313
package org.eclipse.osgi.technology.webservices.registrar;
1414

1515
import java.lang.annotation.Annotation;
16+
import java.util.Dictionary;
1617
import java.util.Map;
1718
import java.util.Objects;
1819
import java.util.WeakHashMap;
1920
import java.util.concurrent.ConcurrentHashMap;
21+
import java.util.concurrent.atomic.AtomicLong;
2022

2123
import org.eclipse.osgi.technology.webservices.spi.EndpointPublisher;
2224
import org.osgi.annotation.bundle.Capability;
2325
import org.osgi.framework.Bundle;
2426
import org.osgi.framework.Constants;
27+
import org.osgi.framework.FrameworkUtil;
2528
import org.osgi.framework.ServiceReference;
29+
import org.osgi.framework.ServiceRegistration;
2630
import org.osgi.framework.dto.ServiceReferenceDTO;
2731
import org.osgi.namespace.implementation.ImplementationNamespace;
32+
import org.osgi.namespace.service.ServiceNamespace;
2833
import org.osgi.service.component.AnyService;
2934
import org.osgi.service.component.ComponentContext;
3035
import org.osgi.service.component.annotations.Activate;
@@ -50,10 +55,12 @@
5055
/**
5156
* Endpoint registrar implementation
5257
*/
53-
@Component(immediate = true, service = { WebserviceServiceRuntime.class })
58+
@Component(immediate = true, service = {})
5459
@Capability(namespace = ImplementationNamespace.IMPLEMENTATION_NAMESPACE, //
5560
name = WebserviceWhiteboardConstants.WEBSERVICE, //
5661
version = WebserviceWhiteboardConstants.WEBSERVICE_SPECIFICATION_VERSION)
62+
@Capability(namespace = ServiceNamespace.SERVICE_NAMESPACE, attribute = {ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE
63+
+ ":List<String>=\"org.osgi.service.webservice.runtime.WebserviceServiceRuntime\";uses:=\"org.osgi.service.webservice.runtime\"" })
5764
public class EndpointRegistrar implements WebserviceServiceRuntime {
5865

5966
private Logger logger;
@@ -63,6 +70,9 @@ public class EndpointRegistrar implements WebserviceServiceRuntime {
6370
private Map<ServiceReference<?>, EndpointRegistration> endpointRegistrations = new ConcurrentHashMap<>();
6471
private Map<EndpointPublisher, ServiceRanking> endpointPublisherMap = new ConcurrentHashMap<>();
6572
private ComponentContext context;
73+
private final AtomicLong changeCount = new AtomicLong();
74+
75+
private ServiceRegistration<WebserviceServiceRuntime> registerService;
6676

6777
/**
6878
* contructor
@@ -74,6 +84,14 @@ public class EndpointRegistrar implements WebserviceServiceRuntime {
7484
public EndpointRegistrar(@Reference(service = LoggerFactory.class) Logger logger, ComponentContext context) {
7585
this.logger = logger;
7686
this.context = context;
87+
// WORKAROUND for https://github.com/osgi/osgi/issues/809
88+
registerService = context.getBundleContext().registerService(WebserviceServiceRuntime.class, this,
89+
getProperties());
90+
91+
}
92+
93+
private Dictionary<String, Long> getProperties() {
94+
return FrameworkUtil.asDictionary(Map.of(Constants.SERVICE_CHANGECOUNT, changeCount.getAndIncrement()));
7795
}
7896

7997
/**
@@ -103,6 +121,7 @@ public int value() {
103121
logger.debug("BINDING publisher={} with ranking={}", publisher, ranking);
104122
endpointPublisherMap.put(publisher, ranking);
105123
updateAll();
124+
registerService.setProperties(getProperties());
106125
}
107126

108127
/**
@@ -114,6 +133,7 @@ public void removeEndpointPublisher(EndpointPublisher publisher) {
114133
ServiceRanking ranking = endpointPublisherMap.remove(publisher);
115134
logger.debug("UNBINDING publisher={} with ranking={}", publisher, ranking);
116135
updateAll();
136+
registerService.setProperties(getProperties());
117137
}
118138

119139
/**
@@ -131,6 +151,7 @@ public void bindEndpointImplementor(ServiceReference<?> endpointImplementorRefer
131151
replaced.dispose();
132152
}
133153
registration.refresh();
154+
registerService.setProperties(getProperties());
134155
}
135156

136157
/**
@@ -143,6 +164,7 @@ public void unbindEndpointImplementor(ServiceReference<?> endpointImplementorRef
143164
EndpointRegistration registration = endpointRegistrations.remove(endpointImplementorReference);
144165
if (registration != null) {
145166
registration.dispose();
167+
registerService.setProperties(getProperties());
146168
}
147169
}
148170

@@ -159,6 +181,7 @@ public void addHandler(ServiceReference<Handler<? extends MessageContext>> handl
159181
info.dispose();
160182
}
161183
updateAll();
184+
registerService.setProperties(getProperties());
162185
}
163186

164187
/**
@@ -173,6 +196,7 @@ public void updateHandler(ServiceReference<Handler<? extends MessageContext>> ha
173196
info.dispose();
174197
}
175198
updateAll();
199+
registerService.setProperties(getProperties());
176200
}
177201

178202
/**
@@ -186,6 +210,7 @@ public void removeHandler(ServiceReference<Handler<? extends MessageContext>> ha
186210
if (info != null) {
187211
info.dispose();
188212
updateAll();
213+
registerService.setProperties(getProperties());
189214
}
190215
}
191216

runtime/registrar/src/main/java/org/eclipse/osgi/technology/webservices/registrar/HandlerInfo.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,26 @@
3030

3131
final class HandlerInfo {
3232

33-
static final Comparator<HandlerInfo> SORT_BY_PRIORITY = Comparator.comparingInt(HandlerInfo::getPriority)
34-
.reversed();
33+
static final Comparator<HandlerInfo> SORT_BY_PRIORITY = Comparator.comparingInt(HandlerInfo::getServiceRank)
34+
.reversed().thenComparing(HandlerInfo::getServiceId);
3535
private final ServiceReference<Handler<? extends MessageContext>> reference;
36-
private final int priority;
36+
private final int serviceRank;
3737
private BundleContext bundleContext;
3838
private Handler<? extends MessageContext> service;
3939
private Exception lookupError;
4040
private Exception filterError;
41+
private long serviceId;
4142

4243
HandlerInfo(ServiceReference<Handler<? extends MessageContext>> reference, BundleContext bundleContext) {
4344
this.reference = reference;
4445
this.bundleContext = bundleContext;
4546
Integer p = (Integer) reference.getProperty(Constants.SERVICE_RANKING);
4647
if (p == null) {
47-
this.priority = 0;
48+
this.serviceRank = 0;
4849
} else {
49-
this.priority = p.intValue();
50+
this.serviceRank = p.intValue();
5051
}
52+
serviceId = (Long) reference.getProperty(Constants.SERVICE_ID);
5153
}
5254

5355
synchronized boolean matches(ServiceReference<?> endpointImplementor) {
@@ -73,8 +75,12 @@ synchronized boolean matches(ServiceReference<?> endpointImplementor) {
7375
return false;
7476
}
7577

76-
int getPriority() {
77-
return priority;
78+
public int getServiceRank() {
79+
return serviceRank;
80+
}
81+
82+
public long getServiceId() {
83+
return serviceId;
7884
}
7985

8086
synchronized void dispose() {

runtime/registrar/src/main/java/org/osgi/service/webservice/whiteboard/WebserviceWhiteboardConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private WebserviceWhiteboardConstants() {
2626
/**
2727
* Base namespace for the Webservice Whiteboard specification
2828
*/
29-
public static final String WEBSERVICE = "osgi.jakarta.xml.ws";
29+
public static final String WEBSERVICE = "osgi.service.webservice";
3030
/**
3131
* Base prefix used in component property types
3232
*/

0 commit comments

Comments
 (0)