BUG-113: switch BGP to proper activators
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / osgi / AbstractOSGiBGPExtensionConsumerActivator.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.protocol.bgp.parser.spi.osgi;
9
10 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerActivator;
11 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
12 import org.osgi.framework.BundleActivator;
13 import org.osgi.framework.BundleContext;
14
15 import com.google.common.base.Preconditions;
16
17 public abstract class AbstractOSGiBGPExtensionConsumerActivator implements BundleActivator, BGPExtensionConsumerActivator {
18         private BGPExtensionConsumerContext consumerContext;
19
20         @Override
21         public final void start(final BundleContext context) throws Exception {
22                 Preconditions.checkState(consumerContext == null);
23                 final BGPExtensionConsumerContext consumerContext = new OSGiBGPExtensionProviderContext(context);
24                 start(consumerContext);
25                 this.consumerContext = consumerContext;
26         }
27
28         @Override
29         public final void stop(final BundleContext context) throws Exception {
30                 Preconditions.checkState(consumerContext != null);
31                 try {
32                         stop();
33                 } finally {
34                         consumerContext = null;
35                 }
36         }
37 }