2 * Copyright (c) 2015 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
9 package org.opendaylight.protocol.rsvp.parser.spi;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.Preconditions;
14 import java.util.List;
15 import javax.annotation.concurrent.GuardedBy;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public abstract class AbstractRSVPExtensionProviderActivator implements AutoCloseable, RSVPExtensionProviderActivator {
20 private static final Logger LOG = LoggerFactory.getLogger(AbstractRSVPExtensionProviderActivator.class);
23 private List<AutoCloseable> registrations;
26 protected abstract List<AutoCloseable> startImpl(RSVPExtensionProviderContext context);
29 public final synchronized void start(final RSVPExtensionProviderContext context) {
30 Preconditions.checkState(this.registrations == null);
32 this.registrations = requireNonNull(startImpl(context));
36 @SuppressWarnings("checkstyle:IllegalCatch")
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() {