1 package org.opendaylight.controller.sal.binding.api;
3 import java.util.concurrent.ExecutorService;
4 import java.util.concurrent.Executors;
6 import org.osgi.framework.BundleActivator;
7 import org.osgi.framework.BundleContext;
8 import org.osgi.framework.ServiceReference;
9 import org.osgi.util.tracker.ServiceTracker;
10 import org.osgi.util.tracker.ServiceTrackerCustomizer;
12 public abstract class AbstractBrokerAwareActivator implements BundleActivator {
14 private static final ExecutorService mdActivationPool = Executors.newCachedThreadPool();
15 private BundleContext context;
16 private ServiceTracker<BindingAwareBroker, BindingAwareBroker> tracker;
17 private BindingAwareBroker broker;
18 private ServiceTrackerCustomizer<BindingAwareBroker, BindingAwareBroker> customizer = new ServiceTrackerCustomizer<BindingAwareBroker, BindingAwareBroker>() {
21 public BindingAwareBroker addingService(ServiceReference<BindingAwareBroker> reference) {
22 broker = context.getService(reference);
23 mdActivationPool.execute(new Runnable() {
27 onBrokerAvailable(broker, context);;
34 public void modifiedService(ServiceReference<BindingAwareBroker> reference, BindingAwareBroker service) {
35 // TODO Auto-generated method stub
40 public void removedService(ServiceReference<BindingAwareBroker> reference, BindingAwareBroker service) {
41 // TODO Auto-generated method stub
49 public final void start(BundleContext context) throws Exception {
50 this.context = context;
52 tracker = new ServiceTracker<>(context, BindingAwareBroker.class, customizer);
60 public final void stop(BundleContext context) throws Exception {
67 * Called when this bundle is started (before
68 * {@link #onSessionInitiated(ProviderContext)} so the Framework can perform
69 * the bundle-specific activities necessary to start this bundle. This
70 * method can be used to register services or to allocate any resources that
74 * This method must complete and return to its caller in a timely manner.
77 * The execution context of the bundle being started.
79 * If this method throws an exception, this bundle is marked as
80 * stopped and the Framework will remove this bundle's
81 * listeners, unregister all services registered by this bundle,
82 * and release all services used by this bundle.
84 protected void startImpl(BundleContext context) {
89 * Called when this bundle is stopped so the Framework can perform the
90 * bundle-specific activities necessary to stop the bundle. In general, this
91 * method should undo the work that the {@code BundleActivator.start} method
92 * started. There should be no active threads that were started by this
93 * bundle when this bundle returns. A stopped bundle must not call any
97 * This method must complete and return to its caller in a timely manner.
99 * @param context The execution context of the bundle being stopped.
100 * @throws Exception If this method throws an exception, the bundle is still
101 * marked as stopped, and the Framework will remove the bundle's
102 * listeners, unregister all services registered by the bundle, and
103 * release all services used by the bundle.
105 protected void stopImpl(BundleContext context) {
110 protected abstract void onBrokerAvailable(BindingAwareBroker broker, BundleContext context);
112 protected void onBrokerRemoved(BindingAwareBroker broker, BundleContext context) {