X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2FBlueprintBundleTracker.java;h=bc84526d76b852033b5725adad05555f119e85f4;hb=93b203c3e2223018000af3472e8eca5363152910;hp=6c267ac5fe62494793d29270420eccfe1685912d;hpb=67ff0fc78b2933b8b4f5a8544c7639499824e622;p=controller.git diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java index 6c267ac5fe..bc84526d76 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java @@ -18,6 +18,7 @@ import java.util.Hashtable; import java.util.List; import org.apache.aries.blueprint.NamespaceHandler; import org.apache.aries.blueprint.services.BlueprintExtenderService; +import org.apache.aries.quiesce.participant.QuiesceParticipant; import org.apache.aries.util.AriesFrameworkUtil; import org.opendaylight.controller.blueprint.ext.OpendaylightNamespaceHandler; import org.opendaylight.controller.config.api.ConfigSystemService; @@ -54,10 +55,12 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus private static final String BLUEPRINT_FLE_PATTERN = "*.xml"; private static final long SYSTEM_BUNDLE_ID = 0; - private ServiceTracker serviceTracker; + private ServiceTracker blueprintExtenderServiceTracker; + private ServiceTracker quiesceParticipantTracker; private BundleTracker bundleTracker; private BundleContext bundleContext; private volatile BlueprintExtenderService blueprintExtenderService; + private volatile QuiesceParticipant quiesceParticipant; private volatile ServiceRegistration blueprintContainerRestartReg; private volatile BlueprintContainerRestartServiceImpl restartService; private volatile boolean shuttingDown; @@ -68,9 +71,11 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus * Implemented from BundleActivator. */ @Override - public void start(BundleContext context) { + public void start(final BundleContext context) { LOG.info("Starting {}", getClass().getSimpleName()); + restartService = new BlueprintContainerRestartServiceImpl(); + bundleContext = context; registerBlueprintEventHandler(context); @@ -79,11 +84,11 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus bundleTracker = new BundleTracker<>(context, Bundle.ACTIVE, this); - serviceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class.getName(), + blueprintExtenderServiceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class.getName(), new ServiceTrackerCustomizer() { @Override public BlueprintExtenderService addingService( - ServiceReference reference) { + final ServiceReference reference) { blueprintExtenderService = reference.getBundle().getBundleContext().getService(reference); bundleTracker.open(); @@ -91,7 +96,8 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus LOG.debug("Got BlueprintExtenderService"); - restartService = new BlueprintContainerRestartServiceImpl(blueprintExtenderService); + restartService.setBlueprintExtenderService(blueprintExtenderService); + blueprintContainerRestartReg = context.registerService( BlueprintContainerRestartService.class.getName(), restartService, new Hashtable<>()); @@ -99,26 +105,52 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } @Override - public void modifiedService(ServiceReference reference, - BlueprintExtenderService service) { + public void modifiedService(final ServiceReference reference, + final BlueprintExtenderService service) { } @Override - public void removedService(ServiceReference reference, - BlueprintExtenderService service) { + public void removedService(final ServiceReference reference, + final BlueprintExtenderService service) { } }); - serviceTracker.open(); + blueprintExtenderServiceTracker.open(); + + quiesceParticipantTracker = new ServiceTracker<>(context, QuiesceParticipant.class.getName(), + new ServiceTrackerCustomizer() { + @Override + public QuiesceParticipant addingService( + final ServiceReference reference) { + quiesceParticipant = reference.getBundle().getBundleContext().getService(reference); + + LOG.debug("Got QuiesceParticipant"); + + restartService.setQuiesceParticipant(quiesceParticipant); + + return quiesceParticipant; + } + + @Override + public void modifiedService(final ServiceReference reference, + final QuiesceParticipant service) { + } + + @Override + public void removedService(final ServiceReference reference, + final QuiesceParticipant service) { + } + }); + quiesceParticipantTracker.open(); } - private void registerNamespaceHandler(BundleContext context) { + private void registerNamespaceHandler(final BundleContext context) { Dictionary props = new Hashtable<>(); props.put("osgi.service.blueprint.namespace", OpendaylightNamespaceHandler.NAMESPACE_1_0_0); namespaceReg = context.registerService(NamespaceHandler.class.getName(), new OpendaylightNamespaceHandler(), props); } - private void registerBlueprintEventHandler(BundleContext context) { + private void registerBlueprintEventHandler(final BundleContext context) { Dictionary props = new Hashtable<>(); props.put(org.osgi.service.event.EventConstants.EVENT_TOPIC, new String[]{EventConstants.TOPIC_CREATED, EventConstants.TOPIC_FAILURE}); @@ -129,9 +161,10 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus * Implemented from BundleActivator. */ @Override - public void stop(BundleContext context) { + public void stop(final BundleContext context) { bundleTracker.close(); - serviceTracker.close(); + blueprintExtenderServiceTracker.close(); + quiesceParticipantTracker.close(); AriesFrameworkUtil.safeUnregisterService(eventHandlerReg); AriesFrameworkUtil.safeUnregisterService(namespaceReg); @@ -142,7 +175,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus * Implemented from SynchronousBundleListener. */ @Override - public void bundleChanged(BundleEvent event) { + public void bundleChanged(final BundleEvent event) { // If the system bundle (id 0) is stopping, do an orderly shutdown of all blueprint containers. On // shutdown the system bundle is stopped first. if (event.getBundle().getBundleId() == SYSTEM_BUNDLE_ID && event.getType() == BundleEvent.STOPPING) { @@ -154,16 +187,16 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus * Implemented from BundleActivator. */ @Override - public Bundle addingBundle(Bundle bundle, BundleEvent event) { + public Bundle addingBundle(final Bundle bundle, final BundleEvent event) { modifiedBundle(bundle, event, bundle); return bundle; } /** - * Implemented from BundleActivator. + * Implemented from BundleTrackerCustomizer. */ @Override - public void modifiedBundle(Bundle bundle, BundleEvent event, Bundle object) { + public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Bundle object) { if (shuttingDown) { return; } @@ -180,10 +213,10 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } /** - * Implemented from BundleActivator. + * Implemented from BundleTrackerCustomizer. */ @Override - public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) { + public void removedBundle(final Bundle bundle, final BundleEvent event, final Bundle object) { // BlueprintExtenderService will handle this. } @@ -193,7 +226,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus * @param event the event to handle */ @Override - public void handleEvent(Event event) { + public void handleEvent(final Event event) { if (EventConstants.TOPIC_CREATED.equals(event.getTopic())) { LOG.info("Blueprint container for bundle {} was successfully created", event.getProperty(EventConstants.BUNDLE)); @@ -217,7 +250,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } @SuppressWarnings({ "rawtypes", "unchecked" }) - static List findBlueprintPaths(Bundle bundle) { + static List findBlueprintPaths(final Bundle bundle) { Enumeration rntries = bundle.findEntries(BLUEPRINT_FILE_PATH, BLUEPRINT_FLE_PATTERN, false); if (rntries == null) { return Collections.emptyList(); @@ -255,7 +288,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus LOG.info("Shutdown of blueprint containers complete"); } - private List getBundlesToDestroy(Collection containerBundles) { + private List getBundlesToDestroy(final Collection containerBundles) { List bundlesToDestroy = new ArrayList<>(); // Find all container bundles that either have no registered services or whose services are no @@ -323,12 +356,12 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus return bundlesToDestroy; } - private static int getServiceUsage(ServiceReference ref) { + private static int getServiceUsage(final ServiceReference ref) { Bundle[] usingBundles = ref.getUsingBundles(); return usingBundles != null ? usingBundles.length : 0; } - private T getOSGiService(Class serviceInterface) { + private T getOSGiService(final Class serviceInterface) { try { ServiceReference serviceReference = bundleContext.getServiceReference(serviceInterface); if (serviceReference == null) { @@ -343,7 +376,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } return service; - } catch (IllegalStateException e) { + } catch (final IllegalStateException e) { // This is thrown if the BundleContext is no longer valid which is possible on shutdown so we // log as debug. LOG.debug("Error obtaining OSGi service {}", serviceInterface.getSimpleName(), e);