package org.opendaylight.mdsal.dom.broker.osgi;
import static com.google.common.base.Preconditions.checkState;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OsgiBundleScanningSchemaService implements SchemaContextProvider, DOMSchemaService, ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
+public class OsgiBundleScanningSchemaService implements SchemaContextProvider, DOMSchemaService,
+ ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(OsgiBundleScanningSchemaService.class);
private final ListenerRegistry<SchemaContextListener> listeners = new ListenerRegistry<>();
this.context = Preconditions.checkNotNull(context);
}
- public synchronized static OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
+ public static synchronized OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
Preconditions.checkState(instance == null);
instance = new OsgiBundleScanningSchemaService(ctx);
instance.start();
return instance;
}
- public synchronized static OsgiBundleScanningSchemaService getInstance() {
+ public static synchronized OsgiBundleScanningSchemaService getInstance() {
Preconditions.checkState(instance != null, "Global Instance was not instantiated");
return instance;
}
checkState(context != null);
LOG.debug("start() starting");
- listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class, OsgiBundleScanningSchemaService.this);
- bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING |
+ listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class,
+ OsgiBundleScanningSchemaService.this);
+ bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING
+ |
Bundle.STOPPING | Bundle.ACTIVE, scanner);
bundleTracker.open();
}
@Override
- public synchronized ListenerRegistration<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener listener) {
+ public synchronized ListenerRegistration<SchemaContextListener>
+ registerSchemaContextListener(final SchemaContextListener listener) {
final Optional<SchemaContext> potentialCtx = contextResolver.getSchemaContext();
- if(potentialCtx.isPresent()) {
+ if (potentialCtx.isPresent()) {
listener.onGlobalContextUpdated(potentialCtx.get());
}
return listeners.register(listener);
}
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private synchronized void updateContext(final SchemaContext snapshot) {
final Object[] services = listenerTracker.getServices();
for (final ListenerRegistration<SchemaContextListener> listener : listeners) {
}
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private class BundleScanner implements BundleTrackerCustomizer<Iterable<Registration>> {
@Override
public Iterable<Registration> addingBundle(final Bundle bundle, final BundleEvent event) {
* {@link #getYangStoreSnapshot()} will throw exception. There is no
* rollback.
*/
-
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
- public synchronized void removedBundle(final Bundle bundle, final BundleEvent event, final Iterable<Registration> urls) {
+ public synchronized void removedBundle(final Bundle bundle, final BundleEvent event,
+ final Iterable<Registration> urls) {
for (final Registration url : urls) {
try {
url.close();
}
final int numUrls = Iterables.size(urls);
- if(numUrls > 0 ) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("removedBundle: {}, state: {}, # urls: {}", bundle.getSymbolicName(), bundle.getState(), numUrls);
+ if (numUrls > 0 ) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("removedBundle: {}, state: {}, # urls: {}", bundle.getSymbolicName(),
+ bundle.getState(), numUrls);
}
tryToUpdateSchemaContext();
return;
}
final Optional<SchemaContext> schema = contextResolver.getSchemaContext();
- if(schema.isPresent()) {
- if(LOG.isDebugEnabled()) {
+ if (schema.isPresent()) {
+ if (LOG.isDebugEnabled()) {
LOG.debug("Got new SchemaContext: # of modules {}", schema.get().getAllModuleIdentifiers().size());
}
}
@Override
- public void modifiedService(final ServiceReference<SchemaContextListener> reference, final SchemaContextListener service) {
+ public void modifiedService(final ServiceReference<SchemaContextListener> reference,
+ final SchemaContextListener service) {
// NOOP
}
@Override
- public void removedService(final ServiceReference<SchemaContextListener> reference, final SchemaContextListener service) {
+ public void removedService(final ServiceReference<SchemaContextListener> reference,
+ final SchemaContextListener service) {
context.ungetService(reference);
}
}