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;
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;
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;
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;
}
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();
}
}
@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();
}
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);
}
}
@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");