Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhseeberger2008-08-05 14:44:53 +0000
committerhseeberger2008-08-05 14:44:53 +0000
commitb021c231440d49aebef87cd2a5f01b9f95f795ab (patch)
tree409848c2c105ce16d811a6a81b85a87d368b139c
parent1572134fe578e89ac46ded6710e5c45861443e83 (diff)
downloadrt.equinox.bundles-b021c231440d49aebef87cd2a5f01b9f95f795ab.tar.gz
rt.equinox.bundles-b021c231440d49aebef87cd2a5f01b9f95f795ab.tar.xz
rt.equinox.bundles-b021c231440d49aebef87cd2a5f01b9f95f795ab.zip
Enhancements for service dynamics.
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java8
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java80
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java2
3 files changed, 46 insertions, 44 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java
index 425f669c7..cd21e49e4 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java
@@ -252,13 +252,17 @@ public class SupplementerRegistry {
+ bundle.getSymbolicName());
try {
- final int initialstate = (bundle.getState() | (Bundle.ACTIVE | Bundle.STARTING));
+ final int initialstate = (bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING));
// TODO Why stop? Shouldn't start again?
+ boolean wasStopped = false;
if (initialstate != 0
&& packageAdmin != null
- && packageAdmin.getBundleType(bundle) != PackageAdmin.BUNDLE_TYPE_FRAGMENT)
+ && packageAdmin.getBundleType(bundle) != PackageAdmin.BUNDLE_TYPE_FRAGMENT) {
+ wasStopped = true;
bundle.stop(Bundle.STOP_TRANSIENT);
+ }
bundle.update();
+ if (wasStopped) bundle.start(Bundle.START_TRANSIENT);
} catch (final BundleException e) {
e.printStackTrace();
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java
index 4ec4bcaf5..3fba382b9 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java
@@ -24,10 +24,13 @@ import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
public class AspectJAdaptorFactory {
@@ -39,12 +42,19 @@ public class AspectJAdaptorFactory {
private SupplementerRegistry supplementerRegistry;
+ private ServiceListener weavingServiceListener;
+
private ServiceTracker weavingServiceTracker;
public AspectJAdaptorFactory() {
}
- public void dispose() {
+ public void dispose(final BundleContext context) {
+
+ context.removeServiceListener(weavingServiceListener);
+ if (Debug.DEBUG_WEAVE)
+ Debug.println("> Removed service listener for weaving service.");
+
weavingServiceTracker.close();
if (Debug.DEBUG_WEAVE)
Debug.println("> Closed service tracker for weaving service.");
@@ -78,49 +88,37 @@ public class AspectJAdaptorFactory {
// Service tracker for weaving service
weavingServiceTracker = new ServiceTracker(context,
- IWeavingService.class.getName(),
- new ServiceTrackerCustomizer() {
-
- public Object addingService(final ServiceReference reference) {
- updateSupplementedBundles(context, supplementerRegistry);
- return context.getService(reference);
- }
-
- public void modifiedService(
- final ServiceReference reference,
- final Object service) {
- // Nothing to be done!
- }
-
- public void removedService(
- final ServiceReference reference,
- final Object service) {
- updateSupplementedBundles(context, supplementerRegistry);
- context.ungetService(reference);
- }
-
- private void updateSupplementedBundles(
- final BundleContext context,
- final SupplementerRegistry supplementerRegistry) {
- final Iterator supplementedBundlesIterator = supplementerRegistry
- .getSupplementedBundles().iterator();
- while (supplementedBundlesIterator.hasNext()) {
- final Bundle supplementedBundle = (Bundle) supplementedBundlesIterator
- .next();
- supplementerRegistry
- .updateInstalledBundle(supplementedBundle);
- if (Debug.DEBUG_WEAVE)
- Debug.println("> Updated supplemented bundle "
- + supplementedBundle.getSymbolicName());
- System.err.println("> Updated supplemented bundle "
- + supplementedBundle.getSymbolicName());
- }
- }
- });
+ IWeavingService.class.getName(), null);
weavingServiceTracker.open();
if (Debug.DEBUG_WEAVE)
Debug.println("> Opened service tracker for weaving service.");
+ // Service listener for weaving service
+ weavingServiceListener = new ServiceListener() {
+
+ public void serviceChanged(final ServiceEvent event) {
+ if (event.getType() != ServiceEvent.MODIFIED) {
+ final Iterator supplementedBundlesIterator = supplementerRegistry
+ .getSupplementedBundles().iterator();
+ while (supplementedBundlesIterator.hasNext()) {
+ final Bundle supplementedBundle = (Bundle) supplementedBundlesIterator
+ .next();
+ supplementerRegistry
+ .updateInstalledBundle(supplementedBundle);
+ if (Debug.DEBUG_WEAVE)
+ Debug.println("> Updated supplemented bundle "
+ + supplementedBundle.getSymbolicName());
+ }
+ }
+ }
+ };
+ try {
+ context.addServiceListener(weavingServiceListener, "("
+ + Constants.OBJECTCLASS + "="
+ + IWeavingService.class.getName() + ")");
+ } catch (final InvalidSyntaxException e) { // This is correct!
+ }
+
// Service tracker for caching service
cachingServiceTracker = new ServiceTracker(context,
ICachingService.class.getName(), null);
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java
index 0ba68fbd4..1609a8ee4 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java
@@ -50,7 +50,7 @@ public class AspectJHook extends AbstractAspectJHook {
public void frameworkStop(final BundleContext context)
throws BundleException {
- adaptorFactory.dispose();
+ adaptorFactory.dispose(context);
}
public void initializedClassLoader(final BaseClassLoader baseClassLoader,

Back to the top