Migrate AbstractRegistration/AutoCloseable
[bgpcep.git] / rsvp / spi / src / main / java / org / opendaylight / protocol / rsvp / parser / spi / AbstractRSVPExtensionProviderActivator.java
index da801497e128a4cb6e073b299ecf19c5966403cd..3e386824aaa0523c2c636755c9431a31a7849f7c 100644 (file)
@@ -5,53 +5,39 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.rsvp.parser.spi;
 
+import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import java.util.List;
 import javax.annotation.concurrent.GuardedBy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.opendaylight.yangtools.concepts.Registration;
 
 public abstract class AbstractRSVPExtensionProviderActivator implements AutoCloseable, RSVPExtensionProviderActivator {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractRSVPExtensionProviderActivator.class);
-
     @GuardedBy("this")
-    private List<AutoCloseable> registrations;
+    private List<? extends Registration> registrations;
 
     @GuardedBy("this")
-    protected abstract List<AutoCloseable> startImpl(RSVPExtensionProviderContext context);
+    protected abstract List<? extends Registration> startImpl(RSVPExtensionProviderContext context);
 
     @Override
     public final synchronized void start(final RSVPExtensionProviderContext context) {
-        Preconditions.checkState(this.registrations == null);
+        checkState(this.registrations == null);
 
         this.registrations = requireNonNull(startImpl(context));
     }
 
     @Override
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public final synchronized void stop() {
-        if (this.registrations == null) {
-            return;
+        if (this.registrations != null) {
+            this.registrations.forEach(Registration::close);
+            this.registrations = null;
         }
-
-        for (final AutoCloseable r : this.registrations) {
-            try {
-                r.close();
-            } catch (final Exception e) {
-                LOG.warn("Failed to close registration", e);
-            }
-        }
-
-        this.registrations = null;
     }
 
     @Override
     public final void close() {
         stop();
     }
-}
\ No newline at end of file
+}