Use osgi-core constants
[mdsal.git] / dom / mdsal-dom-schema-service-osgi / src / main / java / org / opendaylight / mdsal / dom / schema / service / osgi / OsgiBundleScanningSchemaService.java
index 859f8ffc0192fecf99192d57bc82b3224573b460..727d790ab2d7a883a809ed3ee5109ca47cec8296 100644 (file)
@@ -8,8 +8,9 @@
 package org.opendaylight.mdsal.dom.schema.service.osgi;
 
 import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.net.URL;
@@ -18,14 +19,15 @@ import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.Nonnull;
-import javax.annotation.concurrent.GuardedBy;
+import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.broker.schema.ScanningSchemaServiceProvider;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.BundleTracker;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
@@ -34,12 +36,11 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvider
+public final class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvider
         implements ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener> {
 
     private static final Logger LOG = LoggerFactory.getLogger(OsgiBundleScanningSchemaService.class);
     private static final AtomicReference<OsgiBundleScanningSchemaService> GLOBAL_INSTANCE = new AtomicReference<>();
-    private static final long FRAMEWORK_BUNDLE_ID = 0;
 
     private final BundleScanner scanner = new BundleScanner();
     private final BundleContext context;
@@ -54,12 +55,12 @@ public class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvid
     private volatile boolean stopping;
 
     private OsgiBundleScanningSchemaService(final BundleContext context) {
-        this.context = Preconditions.checkNotNull(context);
+        this.context = requireNonNull(context);
     }
 
-    public static @Nonnull OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
+    public static @NonNull OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
         final OsgiBundleScanningSchemaService instance = new OsgiBundleScanningSchemaService(ctx);
-        Preconditions.checkState(GLOBAL_INSTANCE.compareAndSet(null, instance));
+        checkState(GLOBAL_INSTANCE.compareAndSet(null, instance));
         instance.start();
         return instance;
     }
@@ -90,15 +91,14 @@ public class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvid
 
     public static OsgiBundleScanningSchemaService getInstance() {
         final OsgiBundleScanningSchemaService instance = GLOBAL_INSTANCE.get();
-        Preconditions.checkState(instance != null, "Global Instance was not instantiated");
+        checkState(instance != null, "Global Instance was not instantiated");
         return instance;
     }
 
     @VisibleForTesting
-    public static void destroyInstance() throws Exception {
+    public static void destroyInstance() {
         final OsgiBundleScanningSchemaService instance = GLOBAL_INSTANCE.getAndSet(null);
         if (instance != null) {
-
             instance.closeInstance();
         }
     }
@@ -125,7 +125,7 @@ public class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvid
         @Override
         public Iterable<Registration> addingBundle(final Bundle bundle, final BundleEvent event) {
 
-            if (bundle.getBundleId() == FRAMEWORK_BUNDLE_ID) {
+            if (bundle.getBundleId() == Constants.SYSTEM_BUNDLE_ID) {
                 return Collections.emptyList();
             }
 
@@ -141,7 +141,7 @@ public class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvid
                     urls.add(u);
                     LOG.debug("Registered {}", u);
                 } catch (final Exception e) {
-                    LOG.warn("Failed to register {}, ignoring it", e);
+                    LOG.warn("Failed to register {}, ignoring it", u, e);
                 }
             }
 
@@ -158,7 +158,7 @@ public class OsgiBundleScanningSchemaService extends ScanningSchemaServiceProvid
 
         @Override
         public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Iterable<Registration> object) {
-            if (bundle.getBundleId() == FRAMEWORK_BUNDLE_ID) {
+            if (bundle.getBundleId() == Constants.SYSTEM_BUNDLE_ID) {
                 LOG.debug("Framework bundle {} got event {}", bundle, event.getType());
                 if ((event.getType() & BundleEvent.STOPPING) != 0) {
                     LOG.info("OSGi framework is being stopped, halting bundle scanning");