Skip to content

Adjust to latest spec changes #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions runtime/registrar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
<artifactId>org.osgi.namespace.implementation</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.namespace.service</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
package org.eclipse.osgi.technology.webservices.registrar;

import java.lang.annotation.Annotation;
import java.util.Dictionary;
import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

import org.eclipse.osgi.technology.webservices.spi.EndpointPublisher;
import org.osgi.annotation.bundle.Capability;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.dto.ServiceReferenceDTO;
import org.osgi.namespace.implementation.ImplementationNamespace;
import org.osgi.namespace.service.ServiceNamespace;
import org.osgi.service.component.AnyService;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -50,10 +55,12 @@
/**
* Endpoint registrar implementation
*/
@Component(immediate = true, service = { WebserviceServiceRuntime.class })
@Component(immediate = true, service = {})
@Capability(namespace = ImplementationNamespace.IMPLEMENTATION_NAMESPACE, //
name = WebserviceWhiteboardConstants.WEBSERVICE, //
version = WebserviceWhiteboardConstants.WEBSERVICE_SPECIFICATION_VERSION)
@Capability(namespace = ServiceNamespace.SERVICE_NAMESPACE, attribute = {ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE
+ ":List<String>=\"org.osgi.service.webservice.runtime.WebserviceServiceRuntime\";uses:=\"org.osgi.service.webservice.runtime\"" })
public class EndpointRegistrar implements WebserviceServiceRuntime {

private Logger logger;
Expand All @@ -63,6 +70,9 @@ public class EndpointRegistrar implements WebserviceServiceRuntime {
private Map<ServiceReference<?>, EndpointRegistration> endpointRegistrations = new ConcurrentHashMap<>();
private Map<EndpointPublisher, ServiceRanking> endpointPublisherMap = new ConcurrentHashMap<>();
private ComponentContext context;
private final AtomicLong changeCount = new AtomicLong();

private ServiceRegistration<WebserviceServiceRuntime> registerService;

/**
* contructor
Expand All @@ -74,6 +84,14 @@ public class EndpointRegistrar implements WebserviceServiceRuntime {
public EndpointRegistrar(@Reference(service = LoggerFactory.class) Logger logger, ComponentContext context) {
this.logger = logger;
this.context = context;
// WORKAROUND for https://github.com/osgi/osgi/issues/809
registerService = context.getBundleContext().registerService(WebserviceServiceRuntime.class, this,
getProperties());

}

private Dictionary<String, Long> getProperties() {
return FrameworkUtil.asDictionary(Map.of(Constants.SERVICE_CHANGECOUNT, changeCount.getAndIncrement()));
}

/**
Expand Down Expand Up @@ -103,6 +121,7 @@ public int value() {
logger.debug("BINDING publisher={} with ranking={}", publisher, ranking);
endpointPublisherMap.put(publisher, ranking);
updateAll();
registerService.setProperties(getProperties());
}

/**
Expand All @@ -114,6 +133,7 @@ public void removeEndpointPublisher(EndpointPublisher publisher) {
ServiceRanking ranking = endpointPublisherMap.remove(publisher);
logger.debug("UNBINDING publisher={} with ranking={}", publisher, ranking);
updateAll();
registerService.setProperties(getProperties());
}

/**
Expand All @@ -131,6 +151,7 @@ public void bindEndpointImplementor(ServiceReference<?> endpointImplementorRefer
replaced.dispose();
}
registration.refresh();
registerService.setProperties(getProperties());
}

/**
Expand All @@ -143,6 +164,7 @@ public void unbindEndpointImplementor(ServiceReference<?> endpointImplementorRef
EndpointRegistration registration = endpointRegistrations.remove(endpointImplementorReference);
if (registration != null) {
registration.dispose();
registerService.setProperties(getProperties());
}
}

Expand All @@ -159,6 +181,7 @@ public void addHandler(ServiceReference<Handler<? extends MessageContext>> handl
info.dispose();
}
updateAll();
registerService.setProperties(getProperties());
}

/**
Expand All @@ -173,6 +196,7 @@ public void updateHandler(ServiceReference<Handler<? extends MessageContext>> ha
info.dispose();
}
updateAll();
registerService.setProperties(getProperties());
}

/**
Expand All @@ -186,6 +210,7 @@ public void removeHandler(ServiceReference<Handler<? extends MessageContext>> ha
if (info != null) {
info.dispose();
updateAll();
registerService.setProperties(getProperties());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@

final class HandlerInfo {

static final Comparator<HandlerInfo> SORT_BY_PRIORITY = Comparator.comparingInt(HandlerInfo::getPriority)
.reversed();
static final Comparator<HandlerInfo> SORT_BY_PRIORITY = Comparator.comparingInt(HandlerInfo::getServiceRank)
.reversed().thenComparing(HandlerInfo::getServiceId);
private final ServiceReference<Handler<? extends MessageContext>> reference;
private final int priority;
private final int serviceRank;
private BundleContext bundleContext;
private Handler<? extends MessageContext> service;
private Exception lookupError;
private Exception filterError;
private long serviceId;

HandlerInfo(ServiceReference<Handler<? extends MessageContext>> reference, BundleContext bundleContext) {
this.reference = reference;
this.bundleContext = bundleContext;
Integer p = (Integer) reference.getProperty(Constants.SERVICE_RANKING);
if (p == null) {
this.priority = 0;
this.serviceRank = 0;
} else {
this.priority = p.intValue();
this.serviceRank = p.intValue();
}
serviceId = (Long) reference.getProperty(Constants.SERVICE_ID);
}

synchronized boolean matches(ServiceReference<?> endpointImplementor) {
Expand All @@ -73,8 +75,12 @@ synchronized boolean matches(ServiceReference<?> endpointImplementor) {
return false;
}

int getPriority() {
return priority;
public int getServiceRank() {
return serviceRank;
}

public long getServiceId() {
return serviceId;
}

synchronized void dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private WebserviceWhiteboardConstants() {
/**
* Base namespace for the Webservice Whiteboard specification
*/
public static final String WEBSERVICE = "osgi.jakarta.xml.ws";
public static final String WEBSERVICE = "osgi.service.webservice";
/**
* Base prefix used in component property types
*/
Expand Down
Loading