Remove use of CheckedFuture in clustering-it-provider
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / sal / core / api / AbstractConsumer.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.core.api;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import org.osgi.framework.BundleActivator;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.util.tracker.ServiceTracker;
16 import org.osgi.util.tracker.ServiceTrackerCustomizer;
17
18 /**
19  * Deprecated.
20  *
21  * @deprecated Use blueprint instead for code wiring.
22  */
23 @Deprecated
24 public abstract class AbstractConsumer implements Consumer, BundleActivator,ServiceTrackerCustomizer<Broker, Broker> {
25
26     private BundleContext context;
27     private ServiceTracker<Broker, Broker> tracker;
28     private Broker broker;
29
30     @Override
31     public final void start(final BundleContext bundleContext) throws Exception {
32         this.context = bundleContext;
33         this.startImpl(bundleContext);
34         tracker = new ServiceTracker<>(bundleContext, Broker.class, this);
35         tracker.open();
36     }
37
38     @Override
39     public final void stop(final BundleContext bundleContext) throws Exception {
40         stopImpl(bundleContext);
41         broker = null;
42
43         if (tracker != null) {
44             tracker.close();
45         }
46     }
47
48     protected void startImpl(final BundleContext bundleContext) {
49         // NOOP
50     }
51
52     protected void stopImpl(final BundleContext bundleContext) {
53         // NOOP
54     }
55
56     @Override
57     public Collection<ConsumerFunctionality> getConsumerFunctionality() {
58         return Collections.emptySet();
59     }
60
61
62     @Override
63     public Broker addingService(final ServiceReference<Broker> reference) {
64         if (broker == null && context != null) {
65             broker = context.getService(reference);
66             broker.registerConsumer(this, context);
67             return broker;
68         }
69
70         return null;
71     }
72
73     @Override
74     public void modifiedService(final ServiceReference<Broker> reference, final Broker service) {
75         // NOOP
76     }
77
78     @Override
79     public void removedService(final ServiceReference<Broker> reference, final Broker service) {
80         stopImpl(context);
81     }
82 }