2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.rib.spi;
10 import com.google.common.base.Preconditions;
11 import java.util.List;
12 import javax.annotation.concurrent.GuardedBy;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public abstract class AbstractRIBExtensionProviderActivator implements AutoCloseable, RIBExtensionProviderActivator {
17 private static final Logger LOG = LoggerFactory.getLogger(AbstractRIBExtensionProviderActivator.class);
20 private List<AutoCloseable> registrations;
23 protected abstract List<AutoCloseable> startRIBExtensionProviderImpl(RIBExtensionProviderContext context);
26 public final synchronized void startRIBExtensionProvider(final RIBExtensionProviderContext context) {
27 Preconditions.checkState(this.registrations == null);
29 this.registrations = Preconditions.checkNotNull(startRIBExtensionProviderImpl(context));
33 public final synchronized void stopRIBExtensionProvider() {
34 if (this.registrations == null) {
38 for (final AutoCloseable r : this.registrations) {
41 } catch (final Exception e) {
42 LOG.warn("Failed to close registration", e);
46 this.registrations = null;
50 public final void close() {
51 stopRIBExtensionProvider();