From 7a03daabcdf60715ef565a7590d1b2c96c2d76fc Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 25 Feb 2020 12:15:01 +0100 Subject: [PATCH] Untangle BindingCodecContext/BindingNormalizedNodeCodecRegistry The relationship here should be clear -- a BindingCodecContext is self-contained and should not be subject to dynamism. The registry maintains a 'current' codec. Achieving this is very simple -- just do not perform upcalls to Registry when we are looking for a streamer, it would just loop back to BindingCodecContext and we want to be consistent, i.e. do not try to upcall to a different BindingCodecContext. JIRA: MDSAL-392 Change-Id: I720738f122ba89974e32c91ed8c7f3a059c21690 Signed-off-by: Robert Varga --- .../mdsal/binding/dom/codec/impl/BindingCodecContext.java | 7 ++----- .../dom/codec/impl/BindingNormalizedNodeCodecRegistry.java | 2 +- .../dom/codec/impl/DefaultBindingCodecTreeFactory.java | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java index 352193bb1d..edde979cb8 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java @@ -120,16 +120,14 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree private final @NonNull CodecClassLoader loader = CodecClassLoader.create(); private final InstanceIdentifierCodec instanceIdentifierCodec; private final @NonNull IdentityCodec identityCodec; - private final BindingNormalizedNodeCodecRegistry registry; private final BindingRuntimeContext context; private final SchemaRootCodecContext root; - BindingCodecContext(final BindingRuntimeContext context, final BindingNormalizedNodeCodecRegistry registry) { + BindingCodecContext(final BindingRuntimeContext context) { this.context = requireNonNull(context, "Binding Runtime Context is required."); this.root = SchemaRootCodecContext.create(this); this.identityCodec = new IdentityCodec(context); this.instanceIdentifierCodec = new InstanceIdentifierCodec(this); - this.registry = requireNonNull(registry); } @Override @@ -151,10 +149,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree return identityCodec; } - @SuppressWarnings({"rawtypes", "unchecked"}) @Override public DataObjectSerializer getEventStreamSerializer(final Class type) { - return registry.getSerializer((Class) type); + return serializers.getUnchecked(type); } @Override diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java index 6a7f94b813..3fcf645351 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java @@ -90,7 +90,7 @@ public class BindingNormalizedNodeCodecRegistry implements DataObjectSerializerR return; } - final BindingCodecContext updated = new BindingCodecContext(context, this); + final BindingCodecContext updated = new BindingCodecContext(context); if (!UPDATER.compareAndSet(this, current, updated)) { LOG.warn("Concurrent update of runtime context (expected={} current={}) detected at ", current, codecContext, new Throwable()); diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java index 50da721adb..d2bc737fc6 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java @@ -28,7 +28,7 @@ public final class DefaultBindingCodecTreeFactory implements BindingCodecTreeFac @Override public BindingCodecTree create(final BindingRuntimeContext context) { - return new BindingCodecContext(context, new BindingNormalizedNodeCodecRegistry(context)); + return new BindingCodecContext(context); } @Activate -- 2.36.6