X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2FGlobalBundleScanningSchemaServiceImpl.java;h=c9402c62ab77c92c747183bb5ef2a7810a7dff7e;hp=430963a884b4fbaa71a7c3c12d5df9356058be0c;hb=1f6daaf007e78df276604baa4c515a50037a649d;hpb=c6ab5fdef3d0cc6fac96cb960839168ed7906b3a 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..c9402c62ab 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 @@ -50,11 +50,24 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi private ServiceTracker listenerTracker; 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; + } + public BundleContext getContext() { return context; } @@ -96,7 +109,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 +129,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 { @@ -194,7 +207,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();