X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fosgi%2FYangStoreService.java;h=ad771f99d88e2a4f073f0cbec7ef5117ad0f708d;hb=1a43f55c49d91816751cec1825c40d0a90f8bd8b;hp=176800fb975ba2dd7dc7fe05ad0ca03ffb301a3b;hpb=3e5bfba47ae5fe04360343073273a141730daefd;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java index 176800fb97..ad771f99d8 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java @@ -27,11 +27,13 @@ import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.notifications.BaseNetconfNotificationListener; import org.opendaylight.controller.netconf.notifications.BaseNotificationPublisherRegistration; import org.opendaylight.controller.netconf.notifications.NetconfNotificationCollector; +import org.opendaylight.controller.netconf.util.capability.YangModuleCapability; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.ChangedByBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.changed.by.server.or.user.ServerBuilder; +import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; @@ -57,7 +59,7 @@ public class YangStoreService implements YangStoreContext { * * We synchronize with GC as usual, using a SoftReference. * - * The atomic reference is used to synchronize with {@link #refresh()}, e.g. when + * The atomic reference is used to synchronize with {@link #refresh(org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext)}, e.g. when * refresh happens, it will push a SoftReference(null), e.g. simulate the GC. Now * that may happen while the getter is already busy acting on the old schema context, * so it needs to understand that a refresh has happened and retry. To do that, it @@ -70,6 +72,9 @@ public class YangStoreService implements YangStoreContext { private final AtomicReference> ref = new AtomicReference<>(new SoftReference(null)); + private final AtomicReference> refBindingContext = + new AtomicReference<>(new SoftReference(null)); + private final SchemaContextProvider schemaContextProvider; private final BaseNetconfNotificationListener notificationPublisher; @@ -97,7 +102,7 @@ public class YangStoreService implements YangStoreContext { while (ret == null) { // We need to be compute a new value - ret = new YangStoreSnapshot(schemaContextProvider.getSchemaContext()); + ret = new YangStoreSnapshot(schemaContextProvider.getSchemaContext(), refBindingContext.get().get()); if (!ref.compareAndSet(r, new SoftReference<>(ret))) { LOG.debug("Concurrent refresh detected, recomputing snapshot"); @@ -129,19 +134,28 @@ public class YangStoreService implements YangStoreContext { return getYangStoreSnapshot().getModuleSource(moduleIdentifier); } - public void refresh() { + @Override + public EnumResolver getEnumResolver() { + return getYangStoreSnapshot().getEnumResolver(); + } + + public void refresh(final BindingRuntimeContext runtimeContext) { final YangStoreSnapshot previous = ref.get().get(); ref.set(new SoftReference(null)); + refBindingContext.set(new SoftReference<>(runtimeContext)); notificationExecutor.submit(new CapabilityChangeNotifier(previous)); } public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { - if(ref.get() == null || ref.get().get() == null) { - getYangStoreSnapshot(); + + YangStoreContext context = ref.get().get(); + + if(context == null) { + context = getYangStoreSnapshot(); } this.listeners.add(listener); - listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(ref.get().get())); + listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(context)); return new AutoCloseable() { @Override @@ -154,7 +168,7 @@ public class YangStoreService implements YangStoreContext { private static final Function MODULE_TO_CAPABILITY = new Function() { @Override public Capability apply(final Module module) { - return new NetconfOperationServiceFactoryImpl.YangStoreCapability(module, module.getSource()); + return new YangModuleCapability(module, module.getSource()); } }; @@ -191,7 +205,7 @@ public class YangStoreService implements YangStoreContext { private static final Function MODULE_TO_URI = new Function() { @Override public Uri apply(final Module input) { - return new Uri(new NetconfOperationServiceFactoryImpl.YangStoreCapability(input, input.getSource()).getCapabilityUri()); + return new Uri(new YangModuleCapability(input, input.getSource()).getCapabilityUri()); } };