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.parser.spi;
10 import com.google.common.base.Preconditions;
12 import java.util.List;
14 import javax.annotation.concurrent.GuardedBy;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public abstract class AbstractBGPExtensionProviderActivator implements AutoCloseable, BGPExtensionProviderActivator {
20 private static final Logger LOG = LoggerFactory.getLogger(AbstractBGPExtensionProviderActivator.class);
23 private List<AutoCloseable> registrations;
26 protected abstract List<AutoCloseable> startImpl(BGPExtensionProviderContext context);
29 public final synchronized void start(final BGPExtensionProviderContext context) {
30 Preconditions.checkState(this.registrations == null);
32 this.registrations = Preconditions.checkNotNull(startImpl(context));
36 public final synchronized void stop() {
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;
51 public final void close() {