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 static java.util.Objects.requireNonNull;
12 import com.google.common.base.Preconditions;
13 import java.util.List;
14 import javax.annotation.concurrent.GuardedBy;
15 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
16 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public abstract class AbstractPCEPExtensionProviderActivator implements AutoCloseable, PCEPExtensionProviderActivator {
21 private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPExtensionProviderActivator.class);
24 private List<AutoCloseable> registrations;
27 protected abstract List<AutoCloseable> startImpl(PCEPExtensionProviderContext context);
30 public final synchronized void start(final PCEPExtensionProviderContext context) {
31 Preconditions.checkState(this.registrations == null);
33 this.registrations = requireNonNull(startImpl(context));
37 public final synchronized void stop() {
38 if (this.registrations == null) {
42 for (final AutoCloseable r : this.registrations) {
45 } catch (final Exception e) {
46 LOG.warn("Failed to close registration", e);
50 this.registrations = null;
54 public final void close() {