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.pcep.spi.pojo;
10 import java.util.List;
12 import javax.annotation.concurrent.GuardedBy;
14 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
15 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import com.google.common.base.Preconditions;
21 public abstract class AbstractPCEPExtensionProviderActivator implements AutoCloseable, PCEPExtensionProviderActivator {
22 private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPExtensionProviderActivator.class);
25 private List<AutoCloseable> registrations;
28 protected abstract List<AutoCloseable> startImpl(PCEPExtensionProviderContext context);
31 public final synchronized void start(final PCEPExtensionProviderContext context) {
32 Preconditions.checkState(this.registrations == null);
34 this.registrations = Preconditions.checkNotNull(startImpl(context));
38 public final synchronized void stop() {
39 Preconditions.checkState(this.registrations != null);
41 for (final AutoCloseable r : this.registrations) {
44 } catch (final Exception e) {
45 LOG.warn("Failed to close registration", e);
49 this.registrations = null;
53 public final void close() {