X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2FGlobalBundleScanningSchemaServiceImpl.java;h=d8174c312ab0e9622a23f17549dd841130a633ff;hb=a6a97a57081df63432dde5a6b1613eb779b74d79;hp=430963a884b4fbaa71a7c3c12d5df9356058be0c;hpb=b80124e3f7b11cf2f5e5bd4a6b033d855ff4d0d4;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java index 430963a884..d8174c312a 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.dom.broker; import static com.google.common.base.Preconditions.checkState; +import com.google.common.annotations.VisibleForTesting; import java.net.URL; import java.util.ArrayList; import java.util.Collections; @@ -48,13 +49,31 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi private final BundleContext context; private ServiceTracker listenerTracker; - private BundleTracker>> bundleTracker; + private BundleTracker> bundleTracker; private boolean starting = true; + private static GlobalBundleScanningSchemaServiceImpl instance; - public GlobalBundleScanningSchemaServiceImpl(final BundleContext context) { + private GlobalBundleScanningSchemaServiceImpl(final BundleContext context) { this.context = Preconditions.checkNotNull(context); } + public synchronized static GlobalBundleScanningSchemaServiceImpl createInstance(final BundleContext ctx) { + Preconditions.checkState(instance == null); + instance = new GlobalBundleScanningSchemaServiceImpl(ctx); + instance.start(); + return instance; + } + + public synchronized static GlobalBundleScanningSchemaServiceImpl getInstance() { + Preconditions.checkState(instance != null, "Global Instance was not instantiated"); + return instance; + } + + @VisibleForTesting + public static synchronized void destroyInstance() { + instance = null; + } + public BundleContext getContext() { return context; } @@ -96,7 +115,7 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } @Override - public ListenerRegistration registerSchemaServiceListener(final SchemaServiceListener listener) { + public synchronized ListenerRegistration registerSchemaServiceListener(final SchemaServiceListener listener) { Optional potentialCtx = contextResolver.getSchemaContext(); if(potentialCtx.isPresent()) { listener.onGlobalContextUpdated(potentialCtx.get()); @@ -116,7 +135,7 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } - private void updateContext(final SchemaContext snapshot) { + private synchronized void updateContext(final SchemaContext snapshot) { Object[] services = listenerTracker.getServices(); for (ListenerRegistration listener : listeners) { try { @@ -137,9 +156,9 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } } - private class BundleScanner implements BundleTrackerCustomizer>> { + private class BundleScanner implements BundleTrackerCustomizer> { @Override - public Iterable> addingBundle(final Bundle bundle, final BundleEvent event) { + public Iterable addingBundle(final Bundle bundle, final BundleEvent event) { if (bundle.getBundleId() == 0) { return Collections.emptyList(); @@ -150,7 +169,7 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi return Collections.emptyList(); } - final List> urls = new ArrayList<>(); + final List urls = new ArrayList<>(); while (enumeration.hasMoreElements()) { final URL u = enumeration.nextElement(); try { @@ -170,7 +189,7 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } @Override - public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Iterable> object) { + public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Iterable object) { LOG.debug("Modified bundle {} {} {}", bundle, event, object); } @@ -181,8 +200,8 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi */ @Override - public synchronized void removedBundle(final Bundle bundle, final BundleEvent event, final Iterable> urls) { - for (Registration url : urls) { + public synchronized void removedBundle(final Bundle bundle, final BundleEvent event, final Iterable urls) { + for (Registration url : urls) { try { url.close(); } catch (Exception e) { @@ -194,7 +213,7 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } @Override - public SchemaServiceListener addingService(final ServiceReference reference) { + public synchronized SchemaServiceListener addingService(final ServiceReference reference) { SchemaServiceListener listener = context.getService(reference); SchemaContext _ctxContext = getGlobalContext();