- return contextResolver.getSource(sourceIdentifier);
- }
-
- private class BundleScanner implements BundleTrackerCustomizer<Iterable<Registration>> {
- @Override
- public Iterable<Registration> addingBundle(final Bundle bundle, final BundleEvent event) {
- if (bundle.getBundleId() == FRAMEWORK_BUNDLE_ID) {
- return Collections.emptyList();
- }
-
- final Enumeration<URL> enumeration = bundle.findEntries("META-INF/yang", "*.yang", false);
- if (enumeration == null) {
- return Collections.emptyList();
- }
-
- final List<Registration> urls = new ArrayList<>();
- while (enumeration.hasMoreElements()) {
- final URL u = enumeration.nextElement();
- try {
- urls.add(contextResolver.registerSource(u));
- LOG.debug("Registered {}", u);
- } catch (Exception e) {
- LOG.warn("Failed to register {}, ignoring it", e);
- }
- }
-
- if (!urls.isEmpty()) {
- LOG.debug("Loaded {} new URLs from bundle {}, attempting to rebuild schema context",
- urls.size(), bundle.getSymbolicName());
- tryToUpdateSchemaContext();
- }
-
- return ImmutableList.copyOf(urls);
- }
-
- @Override
- public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Iterable<Registration> object) {
- if (bundle.getBundleId() == FRAMEWORK_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");
- stopping = true;
- }
- }
- }
-
- /**
- * If removing YANG files makes yang store inconsistent, method
- * {@link #getYangStoreSnapshot()} will throw exception. There is no
- * rollback.
- */
- @Override
- public void removedBundle(final Bundle bundle, final BundleEvent event, final Iterable<Registration> urls) {
- for (Registration url : urls) {
- try {
- url.close();
- } catch (Exception e) {
- LOG.warn("Failed do unregister URL {}, proceeding", url, e);
- }
- }
-
- int numUrls = Iterables.size(urls);
- if(numUrls > 0 ) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("removedBundle: {}, state: {}, # urls: {}", bundle.getSymbolicName(), bundle.getState(),
- numUrls);
- }
-
- tryToUpdateSchemaContext();
- }