Bump MDSAL to 4.0.0
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / AbstractPCEPExtensionProviderActivator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.spi.pojo;
9
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
12
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.opendaylight.yangtools.concepts.Registration;
18
19 public abstract class AbstractPCEPExtensionProviderActivator implements AutoCloseable, PCEPExtensionProviderActivator {
20     @GuardedBy("this")
21     private List<? extends Registration> registrations;
22
23     @GuardedBy("this")
24     protected abstract List<? extends Registration> startImpl(PCEPExtensionProviderContext context);
25
26     @Override
27     public final synchronized void start(final PCEPExtensionProviderContext context) {
28         checkState(this.registrations == null);
29
30         this.registrations = requireNonNull(startImpl(context));
31     }
32
33     @Override
34     public final synchronized void stop() {
35         if (this.registrations == null) {
36             return;
37         }
38
39         this.registrations.forEach(Registration::close);
40         this.registrations = null;
41     }
42
43     @Override
44     public final void close() {
45         stop();
46     }
47 }