Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public abstract class Constants {
public static final String EXPORTED_INTERFACES = "service.exported.interfaces";
public static final String ENDPOINT_FRAMEWORK_UUID = "frameworkUUID";

public static final String[] NO_EXPORTED_INTERFACES = {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
Expand Down Expand Up @@ -111,10 +112,9 @@ public void exportService(ServiceReference serviceReference) {
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

String exportedServices = (String) serviceReference.getProperty(Constants.EXPORTED_INTERFACES);
if (exportedServices != null && exportedServices.length() > 0) {
LOGGER.debug("CELLAR DOSGI: registering services {} in the cluster", exportedServices);
String[] interfaces = exportedServices.split(Constants.INTERFACE_SEPARATOR);
String[] interfaces = getExportedInterfaces(serviceReference);
if (interfaces.length > 0) {
LOGGER.debug("CELLAR DOSGI: registering services {} in the cluster", (Object) interfaces);
Object service = bundleContext.getService(serviceReference);

Set<String> exportedInterfaces = getServiceInterfaces(service, interfaces);
Expand Down Expand Up @@ -159,10 +159,9 @@ public void unExportService(ServiceReference serviceReference) {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
String exportedServices = (String) serviceReference.getProperty(Constants.EXPORTED_INTERFACES);
if (exportedServices != null && exportedServices.length() > 0) {
LOGGER.debug("CELLAR DOSGI: un-register service {} from the cluster", exportedServices);
String[] interfaces = exportedServices.split(Constants.INTERFACE_SEPARATOR);
String[] interfaces = getExportedInterfaces(serviceReference);
if (interfaces.length > 0) {
LOGGER.debug("CELLAR DOSGI: un-register service {} from the cluster", (Object) interfaces);
Object service = bundleContext.getService(serviceReference);

Set<String> exportedInterfaces = getServiceInterfaces(service, interfaces);
Expand All @@ -188,6 +187,39 @@ public void unExportService(ServiceReference serviceReference) {
}
}


private String[] getExportedInterfaces(ServiceReference serviceReference) {
Object property = serviceReference.getProperty(Constants.EXPORTED_INTERFACES);
if (property != null) {
if (property instanceof String)
return ((String) property).split(Constants.INTERFACE_SEPARATOR);
if (property instanceof String[])
return (String[]) property;
if (property instanceof Class)
return getClassBinaryNames(serviceReference, property);
if (property instanceof Class[])
return getClassBinaryNames(serviceReference, (Object[]) property);
if (property instanceof Collection)
return getClassBinaryNames(serviceReference, ((Collection) property).toArray());
LOGGER.warn("CELLAR DOSGI: Illegal value type of property {} on service reference {}", Constants.EXPORTED_INTERFACES, serviceReference);
}
return Constants.NO_EXPORTED_INTERFACES;
}

private String[] getClassBinaryNames(ServiceReference serviceReference, Object... classes) {
String[] names = new String[classes.length];
for (int i = 0; i < classes.length; ++i) {
Object o = classes[i];
if (o instanceof String)
names[i] = (String) o;
else if (o instanceof Class)
names[i] = ((Class)o).getName();
else
LOGGER.warn("CELLAR DOSGI: Illegal value type of property {} on service reference {}", Constants.EXPORTED_INTERFACES, serviceReference);
}
return names;
}

/**
* Get the interfaces that match the exported service interfaces.
*
Expand Down