Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-07-20 15:53:47 +0000
committerslewis2014-07-20 15:53:47 +0000
commit4773fa57b05d468a44e8617cbd9b79a0d8d6924b (patch)
tree1f2d7e0b439acfe55d8eaa59af352bdcb3be154b /compendium
parent4a22b0dda70e3943f986ef840155f3d290e95241 (diff)
downloadorg.eclipse.ecf-4773fa57b05d468a44e8617cbd9b79a0d8d6924b.tar.gz
org.eclipse.ecf-4773fa57b05d468a44e8617cbd9b79a0d8d6924b.tar.xz
org.eclipse.ecf-4773fa57b05d468a44e8617cbd9b79a0d8d6924b.zip
Fixes for endpoint modified RSA 1.1 CT tests
Diffstat (limited to 'compendium')
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java204
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java6
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java63
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java270
4 files changed, 417 insertions, 126 deletions
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
index ea8b003dd..48102f438 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
@@ -71,6 +71,13 @@ public class Activator implements BundleActivator {
private ServiceRegistration eventListenerHookRegistration;
private ServiceRegistration eventAdminListenerRegistration;
+ private static final boolean disableBasicTopologyManager = new Boolean(
+ System.getProperty(
+ "org.eclipse.ecf.osgi.services.distribution.disableBasicTopologyManager", //$NON-NLS-1$
+ "false")).booleanValue(); //$NON-NLS-1$
+
+ private OSGiTopologyManagerImpl osgiTopologyManagerImpl;
+
public static Activator getDefault() {
return plugin;
}
@@ -236,89 +243,126 @@ public class Activator implements BundleActivator {
// Always set plugin and context
plugin = this;
this.context = ctxt;
- // Create basicTopologyManagerImpl
- basicTopologyManagerImpl = new BasicTopologyManagerImpl(context);
-
- // Register basicTopologyManagerImpl as EndpointListener always, so that
- // gets notified when Endpoints are discovered
- Properties props = new Properties();
- props.put(
- org.osgi.service.remoteserviceadmin.EndpointEventListener.ENDPOINT_LISTENER_SCOPE,
- basicTopologyManagerImpl.getScope());
-
- // Register as deprecated EndpointListener
- endpointListenerReg = getContext().registerService(
- EndpointListener.class.getName(), basicTopologyManagerImpl,
- (Dictionary) props);
- // As per section 122.6.3/Tracking providers -Tracking providers An
- // Endpoint Event
- // Listener or Endpoint Listener must track the bundles that provide it
- // with
- // Endpoint Descriptions. If a bundle that provided Endpoint
- // Descriptions is
- // stopped, all Endpoint Descriptions that were provided by that bundle
- // must
- // be removed. This can be implemented straightforwardly with a Service
- // Factory
- endpointEventListenerReg = getContext().registerService(
- EndpointEventListener.class.getName(), new ServiceFactory() {
- public Object getService(Bundle bundle,
- ServiceRegistration registration) {
- return new ProxyEndpointEventListener(bundle);
- }
+ // If BasicTopologyManager has been disabled (default), then
+ // use OSGiTopologyManager
+ if (disableBasicTopologyManager) {
+ osgiTopologyManagerImpl = new OSGiTopologyManagerImpl(context);
+
+ Properties props = new Properties();
+ props.put(
+ org.osgi.service.remoteserviceadmin.EndpointEventListener.ENDPOINT_LISTENER_SCOPE,
+ osgiTopologyManagerImpl.getScope());
+
+ // Register as deprecated EndpointListener
+ endpointListenerReg = getContext().registerService(
+ EndpointListener.class.getName(), osgiTopologyManagerImpl,
+ (Dictionary) props);
+ // Also register as EndpointEventListener
+ endpointEventListenerReg = getContext().registerService(
+ EndpointEventListener.class.getName(),
+ osgiTopologyManagerImpl, (Dictionary) props);
+
+ // export any previously registered remote services by calling
+ // activate
+ osgiTopologyManagerImpl.activate();
+
+ } else {
+ // Create basicTopologyManagerImpl
+ basicTopologyManagerImpl = new BasicTopologyManagerImpl(context);
+
+ // Register basicTopologyManagerImpl as EndpointListener always, so
+ // that
+ // gets notified when Endpoints are discovered
+ Properties props = new Properties();
+ props.put(
+ org.osgi.service.remoteserviceadmin.EndpointEventListener.ENDPOINT_LISTENER_SCOPE,
+ basicTopologyManagerImpl.getScope());
+
+ // Register as deprecated EndpointListener
+ endpointListenerReg = getContext().registerService(
+ EndpointListener.class.getName(), basicTopologyManagerImpl,
+ (Dictionary) props);
+ // As per section 122.6.3/Tracking providers -Tracking providers
+ // An
+ // Endpoint Event
+ // Listener or Endpoint Listener must track the bundles that provide
+ // it
+ // with
+ // Endpoint Descriptions. If a bundle that provided Endpoint
+ // Descriptions is
+ // stopped, all Endpoint Descriptions that were provided by that
+ // bundle
+ // must
+ // be removed. This can be implemented straightforwardly with a
+ // Service
+ // Factory
+ endpointEventListenerReg = getContext().registerService(
+ EndpointEventListener.class.getName(),
+ new ServiceFactory() {
+ public Object getService(Bundle bundle,
+ ServiceRegistration registration) {
+ return new ProxyEndpointEventListener(bundle);
+ }
- public void ungetService(Bundle bundle,
- ServiceRegistration registration, Object service) {
- ProxyEndpointEventListener peel = (service instanceof ProxyEndpointEventListener) ? (ProxyEndpointEventListener) service
- : null;
- if (peel == null)
- return;
- synchronized (bundleEndpointEventListenerMap) {
- List<EndpointEventHolder> endpointEventHolders = bundleEndpointEventListenerMap
- .get(bundle);
- if (endpointEventHolders != null)
- for (EndpointEventHolder eh : endpointEventHolders)
- peel.deliverRemoveEventForBundle(eh);
+ public void ungetService(Bundle bundle,
+ ServiceRegistration registration, Object service) {
+ ProxyEndpointEventListener peel = (service instanceof ProxyEndpointEventListener) ? (ProxyEndpointEventListener) service
+ : null;
+ if (peel == null)
+ return;
+ synchronized (bundleEndpointEventListenerMap) {
+ List<EndpointEventHolder> endpointEventHolders = bundleEndpointEventListenerMap
+ .get(bundle);
+ if (endpointEventHolders != null)
+ for (EndpointEventHolder eh : endpointEventHolders)
+ peel.deliverRemoveEventForBundle(eh);
+ }
}
- }
- }, (Dictionary) props);
-
- // Like EventAdmin, if equinox ds is running, then we simply return (no
- // more to do)
- if (Boolean.valueOf(context.getProperty(PROP_USE_DS)).booleanValue())
- return; // If this property is set we assume DS is being used.
-
- // The following code is to make sure that we don't do any more if
- // EventListenerHook has already been registered for us by DS
- // Create serviceFilter for EventListenerHook classname
- String serviceName = EventListenerHook.class.getName();
- Filter serviceFilter = context
- .createFilter("(objectclass=" + serviceName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- // if this bundle has already registered EventListenerHook service via
- // ds, then
- // we're done
- ServiceReference[] refs = context.getBundle().getRegisteredServices();
- if (refs != null) {
- for (int i = 0; i < refs.length; i++)
- if (serviceFilter.match(refs[i]))
- return; // We found a service registered by this bundle
- // already so we return
- }
+ }, (Dictionary) props);
+
+ // Like EventAdmin, if equinox ds is running, then we simply return
+ // (no
+ // more to do)
+ if (Boolean.valueOf(context.getProperty(PROP_USE_DS))
+ .booleanValue())
+ return; // If this property is set we assume DS is being used.
+
+ // The following code is to make sure that we don't do any more if
+ // EventListenerHook has already been registered for us by DS
+ // Create serviceFilter for EventListenerHook classname
+ String serviceName = EventListenerHook.class.getName();
+ Filter serviceFilter = context
+ .createFilter("(objectclass=" + serviceName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ // if this bundle has already registered EventListenerHook service
+ // via
+ // ds, then
+ // we're done
+ ServiceReference[] refs = context.getBundle()
+ .getRegisteredServices();
+ if (refs != null) {
+ for (int i = 0; i < refs.length; i++)
+ if (serviceFilter.match(refs[i]))
+ return; // We found a service registered by this bundle
+ // already so we return
+ }
- // Otherwise (no DS), we create a basicTopologyManagerComponent
- basicTopologyManagerComp = new BasicTopologyManagerComponent();
- // bind the topology manager to it
- basicTopologyManagerComp
- .bindEndpointEventListener(basicTopologyManagerImpl);
- // Register RemoteServiceAdminListener
- eventAdminListenerRegistration = this.context.registerService(
- RemoteServiceAdminListener.class, basicTopologyManagerComp,
- null);
- // register the basic topology manager as EventListenerHook service
- eventListenerHookRegistration = this.context.registerService(
- EventListenerHook.class, basicTopologyManagerComp, null);
- // export any previously registered remote services by calling activate
- basicTopologyManagerComp.activate();
+ // Otherwise (no DS), we create a basicTopologyManagerComponent
+ basicTopologyManagerComp = new BasicTopologyManagerComponent();
+ // bind the topology manager to it
+ basicTopologyManagerComp
+ .bindEndpointEventListener(basicTopologyManagerImpl);
+ // Register RemoteServiceAdminListener
+ eventAdminListenerRegistration = this.context.registerService(
+ RemoteServiceAdminListener.class, basicTopologyManagerComp,
+ null);
+ // register the basic topology manager as EventListenerHook service
+ eventListenerHookRegistration = this.context.registerService(
+ EventListenerHook.class, basicTopologyManagerComp, null);
+ // export any previously registered remote services by calling
+ // activate
+ basicTopologyManagerComp.activate();
+
+ }
}
/*
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java
index d1a14d273..1216c03bc 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java
@@ -36,6 +36,8 @@ public class BasicTopologyManagerComponent implements EventListenerHook,
}
void activate() {
+ if (basicTopologyManagerImpl == null)
+ return;
if (exportRegisteredSvcs)
basicTopologyManagerImpl.exportRegisteredServices(
exportRegisteredSvcsClassname, exportRegisteredSvcsFilter);
@@ -43,11 +45,15 @@ public class BasicTopologyManagerComponent implements EventListenerHook,
// RemoteServiceAdminListener impl
public void remoteAdminEvent(RemoteServiceAdminEvent event) {
+ if (basicTopologyManagerImpl == null)
+ return;
basicTopologyManagerImpl.handleRemoteAdminEvent(event);
}
// EventListenerHook impl
public void event(ServiceEvent event, Map listeners) {
+ if (basicTopologyManagerImpl == null)
+ return;
basicTopologyManagerImpl.event(event, listeners);
}
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java
index 91752fa83..acd569de4 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java
@@ -25,11 +25,7 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
private static final String defaultScope = System
.getProperty("org.eclipse.ecf.osgi.services.discovery.endpointListenerScope"); //$NON-NLS-1$
- private static final boolean disableDiscovery = new Boolean(
- System.getProperty(
- "org.eclipse.ecf.osgi.services.discovery.disableDiscovery", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
-
- private String endpointListenerScope;
+ private String ecfEndpointListenerScope;
private static final String ONLY_ECF_SCOPE = "(" + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*)"; //$NON-NLS-1$ //$NON-NLS-2$
private static final String NO_ECF_SCOPE = "(!(" //$NON-NLS-1$
+ RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*))"; //$NON-NLS-1$
@@ -37,11 +33,11 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
BasicTopologyManagerImpl(BundleContext context) {
super(context);
if (defaultScope != null)
- this.endpointListenerScope = defaultScope;
+ this.ecfEndpointListenerScope = defaultScope;
// If loopback is allowed, then for this endpoint listener we only
// consider those that have a namespace (only ECF endpoint descriptions)
if (allowLoopbackReference)
- endpointListenerScope = ONLY_ECF_SCOPE;
+ ecfEndpointListenerScope = ONLY_ECF_SCOPE;
else {
// If loopback not allowed, then we have our scope include
// both !frameworkUUID same, and ONLY_ECF_SCOPE
@@ -51,12 +47,12 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
elScope.append("(&(!(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(getFrameworkUUID()).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
elScope.append(ONLY_ECF_SCOPE);
elScope.append(")"); //$NON-NLS-1$
- endpointListenerScope = elScope.toString();
+ ecfEndpointListenerScope = elScope.toString();
}
}
String[] getScope() {
- return new String[] { endpointListenerScope, NO_ECF_SCOPE };
+ return new String[] { ecfEndpointListenerScope, NO_ECF_SCOPE };
}
protected String getFrameworkUUID() {
@@ -126,16 +122,10 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
protected void handleEndpointAdded(
org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
String matchedFilter) {
- if (matchedFilter.equals(endpointListenerScope))
- if (endpoint instanceof EndpointDescription)
- handleECFEndpointAdded((EndpointDescription) endpoint);
- else
- handleNonECFEndpointAdded(this, endpoint);
- else if (matchedFilter.equals(NO_ECF_SCOPE))
- if (endpoint instanceof EndpointDescription)
- handleECFEndpointAdded((EndpointDescription) endpoint);
- else
- advertiseEndpointDescription(endpoint);
+ if (matchedFilter.equals(ecfEndpointListenerScope)
+ && (endpoint instanceof EndpointDescription)) {
+ handleECFEndpointAdded((EndpointDescription) endpoint);
+ }
}
/*
@@ -155,16 +145,10 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
protected void handleEndpointRemoved(
org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
String matchedFilter) {
- if (matchedFilter.equals(endpointListenerScope))
- if (endpoint instanceof EndpointDescription)
- handleECFEndpointRemoved((EndpointDescription) endpoint);
- else
- handleNonECFEndpointRemoved(this, endpoint);
- else if (matchedFilter.equals(NO_ECF_SCOPE))
- if (endpoint instanceof EndpointDescription)
- handleECFEndpointRemoved((EndpointDescription) endpoint);
- else
- unadvertiseEndpointDescription(endpoint);
+ if (matchedFilter.equals(ecfEndpointListenerScope)
+ && (endpoint instanceof EndpointDescription)) {
+ handleECFEndpointRemoved((EndpointDescription) endpoint);
+ }
}
// EventListenerHook impl
@@ -182,12 +166,6 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
EndpointDescription endpointDescription = rsaEvent
.getEndpointDescription();
- if (disableDiscovery) {
- logWarning(
- "handleRemoteAdminEvent", "discovery disabled. RemoteServiceAdminEvent type=" + eventType + " description=" + endpointDescription); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return;
- }
-
switch (eventType) {
case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
advertiseEndpointDescription(endpointDescription);
@@ -247,16 +225,9 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
protected void handleEndpointModified(
org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
String matchedFilter) {
- if (matchedFilter.equals(endpointListenerScope))
- if (endpoint instanceof EndpointDescription)
- handleECFEndpointModified((EndpointDescription) endpoint);
- else
- handleNonECFEndpointModified(this, endpoint);
- else if (matchedFilter.equals(NO_ECF_SCOPE))
- if (endpoint instanceof EndpointDescription)
- handleECFEndpointModified((EndpointDescription) endpoint);
- else
- advertiseEndpointDescription(endpoint);
+ if (matchedFilter.equals(ecfEndpointListenerScope)
+ && (endpoint instanceof EndpointDescription)) {
+ handleECFEndpointModified((EndpointDescription) endpoint);
+ }
}
-
}
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java
new file mode 100644
index 000000000..0a5a46535
--- /dev/null
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java
@@ -0,0 +1,270 @@
+package org.eclipse.ecf.internal.osgi.services.distribution;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.AbstractTopologyManager;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointEvent;
+import org.osgi.service.remoteserviceadmin.EndpointEventListener;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+
+public class OSGiTopologyManagerImpl extends AbstractTopologyManager implements
+ EndpointListener, EndpointEventListener {
+
+ private static final boolean exportRegisteredSvcs = new Boolean(
+ System.getProperty(
+ "org.eclipse.ecf.osgi.services.osgitopologymanager.exportRegisteredSvcs", "true")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private static final String exportRegisteredSvcsFilter = System
+ .getProperty(
+ "org.eclipse.ecf.osgi.services.osgitopologymanager.exportRegisteredSvcsFilter", "(service.exported.interfaces=*)"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private static final String exportRegisteredSvcsClassname = System
+ .getProperty("org.eclipse.ecf.osgi.services.osgitopologymanager.exportRegisteredSvcsClassname"); //$NON-NLS-1$
+
+ private String ecfLocalEndpointListenerScope;
+ private String ecfNonLocalEndpointListenerScope;
+ private String osgiLocalEndpointListenerScope;
+ private String osgiNonLocalEndpointListenerScope;
+
+ private static final String ONLY_ECF_SCOPE = "(" + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*)"; //$NON-NLS-1$ //$NON-NLS-2$
+ private static final String NO_ECF_SCOPE = "(!(" //$NON-NLS-1$
+ + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*))"; //$NON-NLS-1$
+
+ OSGiTopologyManagerImpl(BundleContext context) {
+ super(context);
+ String frameworkUUID = getFrameworkUUID();
+ StringBuffer ecfLocalScope = new StringBuffer(""); //$NON-NLS-1$
+ ecfLocalScope
+ .append("(&(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ecfLocalScope.append(ONLY_ECF_SCOPE);
+ ecfLocalScope.append(")"); //$NON-NLS-1$
+
+ ecfLocalEndpointListenerScope = ecfLocalScope.toString();
+ StringBuffer ecfNonLocalScope = new StringBuffer(""); //$NON-NLS-1$
+ ecfNonLocalScope
+ .append("(&(!(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ecfNonLocalScope.append(ONLY_ECF_SCOPE);
+ ecfNonLocalScope.append(")"); //$NON-NLS-1$
+ ecfNonLocalEndpointListenerScope = ecfNonLocalScope.toString();
+
+ StringBuffer localScope = new StringBuffer(""); //$NON-NLS-1$
+ localScope
+ .append("(&(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ localScope.append(NO_ECF_SCOPE);
+ localScope.append(")"); //$NON-NLS-1$
+ osgiLocalEndpointListenerScope = localScope.toString();
+
+ StringBuffer nonlocalScope = new StringBuffer(""); //$NON-NLS-1$
+ nonlocalScope
+ .append("(&(!(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ nonlocalScope.append(NO_ECF_SCOPE);
+ nonlocalScope.append(")"); //$NON-NLS-1$
+
+ osgiNonLocalEndpointListenerScope = nonlocalScope.toString();
+ }
+
+ String[] getScope() {
+ return new String[] { ecfLocalEndpointListenerScope,
+ ecfNonLocalEndpointListenerScope,
+ osgiLocalEndpointListenerScope,
+ osgiNonLocalEndpointListenerScope };
+ }
+
+ protected String getFrameworkUUID() {
+ return super.getFrameworkUUID();
+ }
+
+ void exportRegisteredServices(String exportRegisteredSvcsClassname,
+ String exportRegisteredSvcsFilter) {
+ try {
+ final ServiceReference[] existingServiceRefs = getContext()
+ .getAllServiceReferences(exportRegisteredSvcsClassname,
+ exportRegisteredSvcsFilter);
+ // Now export as if the service was registering right now...i.e.
+ // perform
+ // export
+ if (existingServiceRefs != null && existingServiceRefs.length > 0) {
+ // After having collected all pre-registered services (with
+ // marker prop) we are going to asynchronously remote them.
+ // Registering potentially is a long-running operation (due to
+ // discovery I/O...) and thus should no be carried out in the
+ // OSGi FW thread. (https://bugs.eclipse.org/405027)
+ new Thread(new Runnable() {
+ public void run() {
+ for (int i = 0; i < existingServiceRefs.length; i++) {
+ // This method will check the service properties for
+ // remote service props. If previously registered as
+ // a
+ // remote service, it will export the remote
+ // service if not it will simply return/skip
+ handleServiceRegistering(existingServiceRefs[i]);
+ }
+ }
+ }, "BasicTopologyManagerPreRegSrvExporter").start(); //$NON-NLS-1$
+ }
+ } catch (InvalidSyntaxException e) {
+ logError(
+ "exportRegisteredServices", //$NON-NLS-1$
+ "Could not retrieve existing service references for exportRegisteredSvcsClassname=" //$NON-NLS-1$
+ + exportRegisteredSvcsClassname
+ + " and exportRegisteredSvcsFilter=" //$NON-NLS-1$
+ + exportRegisteredSvcsFilter, e);
+ }
+ }
+
+ // EndpointListener impl
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.osgi.service.remoteserviceadmin.EndpointListener#endpointAdded(org
+ * .osgi.service.remoteserviceadmin.EndpointDescription, java.lang.String)
+ *
+ *
+ * From the R5 spec page 329 section 122.6.2:
+ *
+ * Notify the Endpoint Listener of a new Endpoint Description. The second
+ * parameter is the filter that matched the Endpoint Description.
+ * Registering the same Endpoint multiple times counts as a single
+ * registration.
+ */
+ public void endpointAdded(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
+ String matchedFilter) {
+ handleEndpointAdded(endpoint, matchedFilter);
+ }
+
+ protected void handleEndpointAdded(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
+ String matchedFilter) {
+ if (matchedFilter.equals(osgiLocalEndpointListenerScope)) {
+ advertiseEndpointDescription(endpoint);
+ } else if (matchedFilter.equals(osgiNonLocalEndpointListenerScope)) {
+ EndpointDescription ed = convertEndpointDescriptionFromOSGiToECF(endpoint);
+ if (ed != null) {
+ handleECFEndpointAdded(ed);
+ }
+ } else if (matchedFilter.equals(ecfNonLocalEndpointListenerScope)) {
+ handleECFEndpointAdded((EndpointDescription) endpoint);
+ } else if (matchedFilter.equals(ecfLocalEndpointListenerScope)) {
+ advertiseEndpointDescription(endpoint);
+ }
+ }
+
+ private EndpointDescription convertEndpointDescriptionFromOSGiToECF(
+ org.osgi.service.remoteserviceadmin.EndpointDescription ed) {
+ Map<String, Object> newProps = new HashMap<String, Object>();
+ newProps.putAll(ed.getProperties());
+
+ String ecfNS = (String) newProps
+ .remove(RemoteConstants.OSGI_CONTAINER_ID_NS);
+
+ if (ecfNS == null)
+ return null;
+
+ newProps.put(RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE, ecfNS);
+
+ return new EndpointDescription(newProps);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.osgi.service.remoteserviceadmin.EndpointListener#endpointRemoved(
+ * org.osgi.service.remoteserviceadmin.EndpointDescription,
+ * java.lang.String)
+ */
+ public void endpointRemoved(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
+ String matchedFilter) {
+ handleEndpointRemoved(endpoint, matchedFilter);
+ }
+
+ protected void handleEndpointRemoved(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
+ String matchedFilter) {
+ if (matchedFilter.equals(osgiLocalEndpointListenerScope)) {
+ unadvertiseEndpointDescription(endpoint);
+ } else if (matchedFilter.equals(osgiNonLocalEndpointListenerScope)) {
+ EndpointDescription ed = convertEndpointDescriptionFromOSGiToECF(endpoint);
+ if (ed != null)
+ handleECFEndpointRemoved(ed);
+ } else if (matchedFilter.equals(ecfNonLocalEndpointListenerScope)) {
+ handleECFEndpointRemoved((EndpointDescription) endpoint);
+ } else if (matchedFilter.equals(ecfLocalEndpointListenerScope)) {
+ unadvertiseEndpointDescription(endpoint);
+ }
+ }
+
+ /**
+ * Implementation of
+ * org.osgi.service.remoteserviceadmin.EndpointEventListener for rfc 203/RSA
+ * 1.1
+ *
+ * @see EndpointEventListener#endpointChanged(EndpointEvent, String)
+ */
+ public void endpointChanged(EndpointEvent event, String matchedFilter) {
+ int eventType = event.getType();
+ org.osgi.service.remoteserviceadmin.EndpointDescription ed = event
+ .getEndpoint();
+ switch (eventType) {
+ case EndpointEvent.ADDED:
+ handleEndpointAdded(ed, matchedFilter);
+ break;
+ case EndpointEvent.REMOVED:
+ handleEndpointRemoved(ed, matchedFilter);
+ break;
+ case EndpointEvent.MODIFIED:
+ handleEndpointModified(ed, matchedFilter);
+ break;
+ case EndpointEvent.MODIFIED_ENDMATCH:
+ handleEndpointModifiedEndmatch(ed, matchedFilter);
+ break;
+ }
+ }
+
+ protected void handleEndpointModifiedEndmatch(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
+ String matchedFilter) {
+ // By default do nothing for end match. subclasses may decide
+ // to change this behavior
+ }
+
+ protected void handleEndpointModified(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpoint,
+ String matchedFilter) {
+ if (matchedFilter.equals(osgiLocalEndpointListenerScope)) {
+ Map<String, Object> edProperties = endpoint.getProperties();
+ Object modified = edProperties
+ .get(RemoteConstants.OSGI_ENDPOINT_MODIFIED);
+ Map<String, Object> newEdProperties = new HashMap<String, Object>();
+ newEdProperties.putAll(endpoint.getProperties());
+ if (modified != null) {
+ newEdProperties.remove(RemoteConstants.OSGI_ENDPOINT_MODIFIED);
+ handleNonECFEndpointModified(
+ this,
+ new org.osgi.service.remoteserviceadmin.EndpointDescription(
+ newEdProperties));
+ } else {
+ newEdProperties.put(RemoteConstants.OSGI_ENDPOINT_MODIFIED,
+ new Long(System.currentTimeMillis()));
+ advertiseModifyEndpointDescription(new org.osgi.service.remoteserviceadmin.EndpointDescription(
+ newEdProperties));
+ }
+ } else if (matchedFilter.equals(osgiNonLocalEndpointListenerScope)) {
+ handleNonECFEndpointModified(this, endpoint);
+ }
+ }
+
+ public void activate() {
+ if (exportRegisteredSvcs)
+ exportRegisteredServices(exportRegisteredSvcsClassname,
+ exportRegisteredSvcsFilter);
+ }
+}

Back to the top