Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkuppe2008-06-12 05:33:27 -0400
committermkuppe2008-06-12 05:33:27 -0400
commitf1add4aa8a8500a8f3c437214f247b8961fb4c6e (patch)
treec8ca56c5cbae214fb337fb9ea22daeadc343b7ec
parente64060e068e5819cc5a43710beb49165050c02c3 (diff)
downloadorg.eclipse.ecf-f1add4aa8a8500a8f3c437214f247b8961fb4c6e.tar.gz
org.eclipse.ecf-f1add4aa8a8500a8f3c437214f247b8961fb4c6e.tar.xz
org.eclipse.ecf-f1add4aa8a8500a8f3c437214f247b8961fb4c6e.zip
RESOLVED - bug 236819: [Discovery] Composite container doesn't register itself as an OSGi service
https://bugs.eclipse.org/bugs/show_bug.cgi?id=236819
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.discovery/META-INF/MANIFEST.MF5
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/internal/provider/discovery/Activator.java50
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/provider/discovery/CompositeDiscoveryContainer.java63
3 files changed, 90 insertions, 28 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.discovery/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.discovery/META-INF/MANIFEST.MF
index c020f8d68..60cc09d51 100644
--- a/providers/bundles/org.eclipse.ecf.provider.discovery/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.discovery/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ecf.provider.discovery;singleton:=true
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 2.1.0.qualifier
Bundle-Vendor: %pluginProvider
Import-Package: org.eclipse.osgi.util;version="1.1.0"
Bundle-Localization: plugin
@@ -12,5 +12,4 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
Bundle-Activator: org.eclipse.ecf.internal.provider.discovery.Activator
-Eclipse-LazyStart: true
-Bundle-ActivationPolicy: lazy
+Eclipse-LazyStart: false
diff --git a/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/internal/provider/discovery/Activator.java b/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/internal/provider/discovery/Activator.java
index 30cf46a1d..6cbe620da 100644
--- a/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/internal/provider/discovery/Activator.java
+++ b/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/internal/provider/discovery/Activator.java
@@ -10,8 +10,11 @@
******************************************************************************/
package org.eclipse.ecf.internal.provider.discovery;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
+import java.util.*;
+import org.eclipse.ecf.discovery.service.IDiscoveryService;
+import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
+import org.osgi.framework.*;
+import org.osgi.util.tracker.ServiceTracker;
/**
*
@@ -30,6 +33,8 @@ public class Activator implements BundleActivator {
return plugin;
}
+ private ServiceTracker tracker;
+
/**
* The constructor
*/
@@ -41,8 +46,41 @@ public class Activator implements BundleActivator {
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
*/
- public void start(BundleContext context) throws Exception {
- // do nothing
+ public void start(final BundleContext context) throws Exception {
+ // get all previously registered IDS from OSGi
+ tracker = new ServiceTracker(context, IDiscoveryService.class.getName(), null);
+ tracker.open();
+ Object[] services = tracker.getServices();
+ List discoveries = services == null ? new ArrayList() : new ArrayList(Arrays.asList(services));
+
+ // register the composite discovery service)
+ final CompositeDiscoveryContainer cdc = new CompositeDiscoveryContainer(discoveries);
+ cdc.connect(null, null);
+ Properties props = new Properties();
+ props.put(IDiscoveryService.CONTAINER_ID, cdc.getID());
+ props.put(IDiscoveryService.CONTAINER_NAME, CompositeDiscoveryContainer.NAME);
+ context.registerService(IDiscoveryService.class.getName(), cdc, props);
+
+ // add a service listener to add/remove IDS dynamically
+ context.addServiceListener(new ServiceListener() {
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent arg0) {
+ IDiscoveryService anIDS = (IDiscoveryService) context.getService(arg0.getServiceReference());
+ switch (arg0.getType()) {
+ case ServiceEvent.REGISTERED :
+ cdc.addContainer(anIDS);
+ break;
+ case ServiceEvent.UNREGISTERING :
+ cdc.removeContainer(anIDS);
+ break;
+ default :
+ break;
+ }
+ }
+
+ }, "(" + Constants.OBJECTCLASS + "=" + IDiscoveryService.class.getName() + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
/*
@@ -50,6 +88,10 @@ public class Activator implements BundleActivator {
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ if (tracker != null) {
+ tracker.close();
+ tracker = null;
+ }
plugin = null;
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/provider/discovery/CompositeDiscoveryContainer.java b/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/provider/discovery/CompositeDiscoveryContainer.java
index 1158d572d..d8cf6139c 100644
--- a/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/provider/discovery/CompositeDiscoveryContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.discovery/src/org/eclipse/ecf/provider/discovery/CompositeDiscoveryContainer.java
@@ -20,12 +20,16 @@ import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.discovery.*;
-import org.eclipse.ecf.discovery.identity.IServiceID;
-import org.eclipse.ecf.discovery.identity.IServiceTypeID;
+import org.eclipse.ecf.discovery.identity.*;
+import org.eclipse.ecf.discovery.service.IDiscoveryService;
import org.eclipse.ecf.internal.provider.discovery.Activator;
+import org.eclipse.ecf.internal.provider.discovery.CompositeNamespace;
-public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
- private class CompositeContainerServiceListener implements IServiceListener {
+public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapter implements IDiscoveryService {
+
+ public static final String NAME = "ecf.discovery.composite"; //$NON-NLS-1$
+
+ protected class CompositeContainerServiceListener implements IServiceListener {
/* (non-Javadoc)
* @see org.eclipse.ecf.discovery.IServiceListener#serviceDiscovered(org.eclipse.ecf.discovery.IServiceEvent)
@@ -66,7 +70,7 @@ public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapt
}
}
- private class CompositeContainerServiceTypeListener implements IServiceTypeListener {
+ protected class CompositeContainerServiceTypeListener implements IServiceTypeListener {
/* (non-Javadoc)
* @see org.eclipse.ecf.discovery.IServiceTypeListener#serviceTypeDiscovered(org.eclipse.ecf.discovery.IServiceEvent)
@@ -112,8 +116,7 @@ public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapt
* @throws IDCreateException
*/
public CompositeDiscoveryContainer(List containers) throws IDCreateException {
- super("CompositeDiscoveryNonExistingNS", new DiscoveryContainerConfig(IDFactory.getDefault().createStringID( //$NON-NLS-1$
- CompositeDiscoveryContainer.class.getName())));
+ super(CompositeNamespace.NAME, new DiscoveryContainerConfig(IDFactory.getDefault().createStringID(CompositeDiscoveryContainer.class.getName())));
this.containers = containers;
}
@@ -124,7 +127,9 @@ public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapt
synchronized (containers) {
for (Iterator itr = containers.iterator(); itr.hasNext();) {
IContainer container = (IContainer) itr.next();
- container.connect(targetID, connectContext);
+ if (container.getConnectedID() == null) {
+ container.connect(targetID, connectContext);
+ }
IDiscoveryContainerAdapter idca = (IDiscoveryContainerAdapter) container;
idca.addServiceListener(ccsl);
idca.addServiceTypeListener(ccstl);
@@ -176,11 +181,10 @@ public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapt
}
private IServiceID getServiceIDForDiscoveryContainer(IServiceID service, IDiscoveryContainerAdapter dca) {
- IContainer container = (IContainer) dca;
- Namespace connectNamespace = container.getConnectNamespace();
+ Namespace connectNamespace = dca.getConnectNamespace();
if (!connectNamespace.equals(service.getNamespace())) {
try {
- return (IServiceID) connectNamespace.createInstance(new Object[] {service});
+ return ServiceIDFactory.getDefault().createServiceID(connectNamespace, service.getServiceTypeID().getName(), service.getName());
} catch (IDCreateException e) {
Trace.catching(Activator.PLUGIN_ID, METHODS_CATCHING, this.getClass(), "getServiceTypeIDForDiscoveryContainer", e); //$NON-NLS-1$
}
@@ -241,17 +245,8 @@ public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapt
return (IServiceInfo[]) set.toArray(new IServiceInfo[set.size()]);
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter#getServicesNamespace()
- */
- public Namespace getServicesNamespace() {
- //TODO-mkuppe implement CompositeDiscoveryContainer#getServicesNamespace
- throw new java.lang.UnsupportedOperationException("CompositeDiscoveryContainer#getServicesNamespace not yet implemented"); //$NON-NLS-1$
- }
-
private IServiceTypeID getServiceTypeIDForDiscoveryContainer(IServiceTypeID type, IDiscoveryContainerAdapter dca) {
- IContainer container = (IContainer) dca;
- Namespace connectNamespace = container.getConnectNamespace();
+ Namespace connectNamespace = dca.getConnectNamespace();
if (!connectNamespace.equals(type.getNamespace())) {
try {
return (IServiceTypeID) connectNamespace.createInstance(new Object[] {type});
@@ -304,4 +299,30 @@ public class CompositeDiscoveryContainer extends AbstractDiscoveryContainerAdapt
}
}
}
+
+ /**
+ * @param object
+ * @return true on success
+ * @see java.util.List#add(java.lang.Object)
+ */
+ public boolean addContainer(Object object) {
+ synchronized (containers) {
+ Trace.trace(Activator.PLUGIN_ID, METHODS_TRACING, this.getClass(), "addContainer(Object)", "addContainer " //$NON-NLS-1$ //$NON-NLS-2$
+ + object.toString());
+ return containers.add(object);
+ }
+ }
+
+ /**
+ * @param object
+ * @return true on success
+ * @see java.util.List#remove(java.lang.Object)
+ */
+ public boolean removeContainer(Object object) {
+ synchronized (containers) {
+ Trace.trace(Activator.PLUGIN_ID, METHODS_TRACING, this.getClass(), "removeContainer(Object)", "removeContainer " //$NON-NLS-1$ //$NON-NLS-2$
+ + object.toString());
+ return containers.remove(object);
+ }
+ }
}

Back to the top