X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fapi%2FAbstractBrokerAwareActivator.java;h=1bfd67671a06036fb8565a64281d4222527c18f8;hp=4fc1a517c5551f8efa1d6e9f57b10dbcdd68e5e5;hb=1c992d01fb7be6dfb310ac82839a8f1876d890de;hpb=aa1c4a51361239aeaa064eb11eb935be194b6eeb diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBrokerAwareActivator.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBrokerAwareActivator.java index 4fc1a517c5..1bfd67671a 100644 --- a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBrokerAwareActivator.java +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBrokerAwareActivator.java @@ -7,6 +7,8 @@ */ package org.opendaylight.controller.sal.binding.api; +import static java.util.Objects.requireNonNull; + import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; @@ -18,49 +20,48 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; @Deprecated public abstract class AbstractBrokerAwareActivator implements BundleActivator { + private final class Customizer implements ServiceTrackerCustomizer { + private final BundleContext context; - private static final ExecutorService MD_ACTIVATION_POOL = Executors.newCachedThreadPool(); - private BundleContext context; - private ServiceTracker tracker; - private BindingAwareBroker broker; - private final ServiceTrackerCustomizer customizer = - new ServiceTrackerCustomizer() { + Customizer(final BundleContext context) { + this.context = requireNonNull(context); + } @Override - public BindingAwareBroker addingService(ServiceReference reference) { - broker = context.getService(reference); + public BindingAwareBroker addingService(final ServiceReference reference) { + final BindingAwareBroker broker = context.getService(reference); MD_ACTIVATION_POOL.execute(() -> onBrokerAvailable(broker, context)); return broker; } @Override - public void modifiedService(ServiceReference reference, BindingAwareBroker service) { + public void modifiedService(final ServiceReference reference, + final BindingAwareBroker service) { removedService(reference, service); addingService(reference); } @Override - public void removedService(ServiceReference reference, BindingAwareBroker service) { - broker = context.getService(reference); + public void removedService(final ServiceReference reference, + final BindingAwareBroker service) { + final BindingAwareBroker broker = context.getService(reference); MD_ACTIVATION_POOL.execute(() -> onBrokerRemoved(broker, context)); } + } - }; + private static final ExecutorService MD_ACTIVATION_POOL = Executors.newCachedThreadPool(); + private ServiceTracker tracker; @Override - public final void start(BundleContext bundleContext) { - this.context = bundleContext; + public final void start(final BundleContext bundleContext) { startImpl(bundleContext); - tracker = new ServiceTracker<>(bundleContext, BindingAwareBroker.class, customizer); + tracker = new ServiceTracker<>(bundleContext, BindingAwareBroker.class, new Customizer(bundleContext)); tracker.open(); - } - - @Override - public final void stop(BundleContext bundleContext) { + public final void stop(final BundleContext bundleContext) { if (tracker != null) { tracker.close(); } @@ -85,7 +86,7 @@ public abstract class AbstractBrokerAwareActivator implements BundleActivator { * listeners, unregister all services registered by this bundle, * and release all services used by this bundle. */ - protected void startImpl(BundleContext bundleContext) { + protected void startImpl(final BundleContext bundleContext) { // NOOP } @@ -106,13 +107,13 @@ public abstract class AbstractBrokerAwareActivator implements BundleActivator { * listeners, unregister all services registered by the bundle, and * release all services used by the bundle. */ - protected void stopImpl(BundleContext bundleContext) { + protected void stopImpl(final BundleContext bundleContext) { // NOOP } protected abstract void onBrokerAvailable(BindingAwareBroker bindingBroker, BundleContext bundleContext); - protected void onBrokerRemoved(BindingAwareBroker bindingBroker, BundleContext bundleContext) { + protected void onBrokerRemoved(final BindingAwareBroker bindingBroker, final BundleContext bundleContext) { stopImpl(bundleContext); } }