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 java.util.List;
12 import javax.annotation.concurrent.GuardedBy;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 import com.google.common.base.Preconditions;
19 public abstract class AbstractRIBExtensionProviderActivator implements RIBExtensionProviderActivator {
20 private static final Logger LOG = LoggerFactory.getLogger(AbstractRIBExtensionProviderActivator.class);
23 private List<AutoCloseable> registrations;
26 protected abstract List<AutoCloseable> startRIBExtensionProviderImpl(RIBExtensionProviderContext context);
29 public final synchronized void startRIBExtensionProvider(final RIBExtensionProviderContext context) {
30 Preconditions.checkState(this.registrations == null);
32 this.registrations = Preconditions.checkNotNull(startRIBExtensionProviderImpl(context));
36 public final synchronized void stopRIBExtensionProvider() {
37 Preconditions.checkState(this.registrations != null);
39 for (final AutoCloseable r : this.registrations) {
42 } catch (final Exception e) {
43 LOG.warn("Failed to close registration", e);
47 this.registrations = null;