Untangle BindingCodecContext/BindingNormalizedNodeCodecRegistry 39/88039/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Feb 2020 11:15:01 +0000 (12:15 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Feb 2020 11:16:18 +0000 (12:16 +0100)
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 <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java

index 352193bb1d01f607741deb36fa182e57eca34edf..edde979cb8623aad87591c77a3b66e259b6541cb 100644 (file)
@@ -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
index 6a7f94b8135adc4d4243cd09543f04b0475a7456..3fcf645351065acb43b4fab300c63a0e60dc00cc 100644 (file)
@@ -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());
index 50da721adb9b1429ba21c03f9103f164aa2b1061..d2bc737fc6a6a95f7626d8f18013b6140612e16d 100644 (file)
@@ -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