f6c9df23f2fde698c1403f806c845bba61e4a30a
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / AbstractBindingAwareConsumer.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.binding.api;
9
10 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
11 import org.osgi.framework.BundleActivator;
12 import org.osgi.framework.BundleContext;
13 import org.osgi.framework.ServiceReference;
14
15 public abstract class AbstractBindingAwareConsumer implements BindingAwareConsumer,BundleActivator {
16
17     @Override
18     public final void start(BundleContext context) throws Exception {
19         startImpl(context);
20         ServiceReference<BindingAwareBroker> brokerRef = context.getServiceReference(BindingAwareBroker.class);
21         BindingAwareBroker broker = context.getService(brokerRef);
22         broker.registerConsumer(this, context);
23         //context.ungetService(brokerRef);
24     }
25
26     /**
27      * Called when this bundle is started (before
28      * {@link #onSessionInitiated(ProviderContext)} so the Framework can perform
29      * the bundle-specific activities necessary to start this bundle. This
30      * method can be used to register services or to allocate any resources that
31      * this bundle needs.
32      * 
33      * <p>
34      * This method must complete and return to its caller in a timely manner.
35      * 
36      * @param context
37      *            The execution context of the bundle being started.
38      * @throws Exception
39      *             If this method throws an exception, this bundle is marked as
40      *             stopped and the Framework will remove this bundle's
41      *             listeners, unregister all services registered by this bundle,
42      *             and release all services used by this bundle.
43      */
44     protected void startImpl(BundleContext context) {
45         // NOOP
46     }
47
48     /**
49      * Called when this bundle is stopped so the Framework can perform the
50      * bundle-specific activities necessary to stop the bundle. In general, this
51      * method should undo the work that the {@code BundleActivator.start} method
52      * started. There should be no active threads that were started by this
53      * bundle when this bundle returns. A stopped bundle must not call any
54      * Framework objects.
55      * 
56      * <p>
57      * This method must complete and return to its caller in a timely manner.
58      * 
59      * @param context The execution context of the bundle being stopped.
60      * @throws Exception If this method throws an exception, the bundle is still
61      *         marked as stopped, and the Framework will remove the bundle's
62      *         listeners, unregister all services registered by the bundle, and
63      *         release all services used by the bundle.
64      */
65     protected void stopImpl(BundleContext context) {
66         // NOOP
67     }
68     
69     @Override
70     public final  void stop(BundleContext context) throws Exception {
71         stopImpl(context);
72     }
73
74 }