diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany')
2 files changed, 31 insertions, 15 deletions
diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java b/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java index fa9fb03a1d..6736f9cfb4 100644 --- a/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java +++ b/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java @@ -36,9 +36,11 @@ import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser; import org.apache.tuscany.sca.extensibility.ServiceDiscoverer; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.framework.Version; +import org.osgi.util.tracker.BundleTracker; /** * A ServiceDiscoverer that find META-INF/services/... in installed bundles @@ -50,6 +52,7 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { private BundleContext context; private Version version; + private BundleTracker bundleTracker; public EquinoxServiceDiscoverer(BundleContext context) { this.context = context; @@ -58,6 +61,12 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { if (this.version.equals(Version.emptyVersion)) { this.version = Version.parseVersion("1.1"); } + bundleTracker = new ActiveBundleTracker(context); + bundleTracker.open(); + } + + public void stop() { + bundleTracker.close(); } private Version getSCAVersion(Bundle bundle) { @@ -65,25 +74,27 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { return Version.parseVersion(header); } - /* - private Map<Bundle, Object> bundles = new ConcurrentHashMap<Bundle, Object>(); + public static class ActiveBundleTracker extends BundleTracker { + + /** + * @param context + * @param stateMask + * @param customizer + */ + public ActiveBundleTracker(BundleContext context) { + super(context, Bundle.RESOLVED | Bundle.ACTIVE | Bundle.STARTING, null); + } - public Object addingBundle(Bundle bundle, BundleEvent event) { - if (isProviderBundle(bundle)) { - bundles.put(bundle, bundle); - System.out.println("Bundle added: " + toString(bundle)); - return bundle; + @Override + public Object addingBundle(Bundle bundle, BundleEvent event) { + if (event != null && event.getType() == BundleEvent.STOPPED) { + return null; + } + return super.addingBundle(bundle, event); } - return null; - } - public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) { } - public void removedBundle(Bundle bundle, BundleEvent event, Object object) { - bundles.remove(object); - } - */ public static class ServiceDeclarationImpl implements ServiceDeclaration { private Bundle bundle; diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java b/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java index 4ccaf57c19..14ad6670a8 100644 --- a/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java +++ b/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java @@ -30,15 +30,20 @@ import org.osgi.framework.BundleContext; */ public class EquinoxServiceDiscoveryActivator implements BundleActivator { // private static final Logger logger = Logger.getLogger(EquinoxServiceDiscoveryActivator.class.getName()); + private EquinoxServiceDiscoverer discoverer; public void start(BundleContext context) throws Exception { - EquinoxServiceDiscoverer discoverer = new EquinoxServiceDiscoverer(context); + discoverer = new EquinoxServiceDiscoverer(context); ServiceDiscovery.getInstance().setServiceDiscoverer(discoverer); // logger.info("Equinox-based service discoverer is now configured."); } public void stop(BundleContext context) throws Exception { ServiceDiscovery.getInstance().setServiceDiscoverer(null); + if (discoverer != null) { + discoverer.stop(); + discoverer = null; + } } } |