Update to MD-SAL APIs
[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
13 import org.osgi.framework.BundleActivator;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.ServiceReference;
16
17 public abstract class AbstractConsumer implements Consumer, BundleActivator {
18
19     Broker broker;
20     ServiceReference<Broker> brokerRef;
21     @Override
22     public final void start(BundleContext context) throws Exception {
23         this.startImpl(context);
24         brokerRef = context.getServiceReference(Broker.class);
25         broker = context.getService(brokerRef);
26         broker.registerConsumer(this,context);
27     }
28
29
30
31     @Override
32     public final void stop(BundleContext context) throws Exception {
33         stopImpl(context);
34         broker = null;
35         if(brokerRef != null) {
36             context.ungetService(brokerRef);
37         }
38     }
39
40     protected void startImpl(BundleContext context) {
41         // NOOP
42     }
43     protected void stopImpl(BundleContext context) {
44         // NOOP
45     }
46
47     @Override
48     public Collection<ConsumerFunctionality> getConsumerFunctionality() {
49         return Collections.emptySet();
50     }
51
52 }