Improve OSGiDOMSchemaService printouts 36/109836/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Jan 2024 14:34:58 +0000 (15:34 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Jan 2024 14:57:48 +0000 (15:57 +0100)
Isolate toString() interactions to ModelContextListener and establish
that it is a ForwardingObject.

Change-Id: I4baa3eff0623fd9cdc0629e50f8cbf136a5d5e04
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-schema-osgi/src/main/java/org/opendaylight/mdsal/dom/schema/osgi/impl/ModelContextListener.java
dom/mdsal-dom-schema-osgi/src/main/java/org/opendaylight/mdsal/dom/schema/osgi/impl/OSGiDOMSchemaService.java

index 14dc0e9e52cd5fc22c54146f92f8deb2a3b4c810..834c4fd77b6f75e67b97958e90688bb0fdb62732 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.mdsal.dom.schema.osgi.impl;
 import static com.google.common.base.Verify.verifyNotNull;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ForwardingObject;
 import java.util.Dictionary;
 import java.util.Map;
 import java.util.function.Consumer;
@@ -18,15 +19,19 @@ import org.osgi.framework.FrameworkUtil;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A Factory Component for OSGi SR manifestation of a {@code Consumer<EffectiveModelContext>}. Instances of this
  * component are created through by {@link OSGiDOMSchemaService} each time a listener is registered.
  */
 @Component(factory = ModelContextListener.FACTORY_NAME, service = ModelContextListener.class)
-public final class ModelContextListener {
+public final class ModelContextListener extends ForwardingObject {
     static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.SchemaSchemaContextListener";
 
+    private static final Logger LOG = LoggerFactory.getLogger(ModelContextListener.class);
+
     @VisibleForTesting
     static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.SchemaSchemaContextListener";
 
@@ -42,8 +47,19 @@ public final class ModelContextListener {
         delegate = null;
     }
 
-    void onModelContextUpdated(final EffectiveModelContext newModelContext) {
-        delegate.accept(newModelContext);
+    @Override
+    protected Object delegate() {
+        return delegate;
+    }
+
+    @SuppressWarnings("checkstyle:illegalCatch")
+    void onModelContextUpdated(final EffectiveModelContext modelContext) {
+        LOG.trace("Notifying {} of {}", delegate, modelContext);
+        try {
+            delegate.accept(modelContext);
+        } catch (RuntimeException e) {
+            LOG.warn("Failed to notify listener {}", delegate, e);
+        }
     }
 
     static Dictionary<String, ?> props(final Consumer<EffectiveModelContext> delegate) {
index d55f6a2f123e93319f07c25472c756a3f787029e..83e237cddd6f484a7da55a8165a95a0b7137090c 100644 (file)
@@ -76,7 +76,7 @@ public final class OSGiDOMSchemaService implements DOMSchemaService, DOMSchemaSe
         final var previous = currentSnapshot.getAndSet(snapshot);
         LOG.debug("Snapshot updated from {} to {}", previous, snapshot);
 
-        listeners.forEach(listener -> notifyListener(modelContext, listener));
+        listeners.forEach(listener -> listener.onModelContextUpdated(modelContext));
     }
 
     void unbindSnapshot(final OSGiModuleInfoSnapshot oldContext) {
@@ -124,13 +124,4 @@ public final class OSGiDOMSchemaService implements DOMSchemaService, DOMSchemaSe
         }
     }
 
-    @SuppressWarnings("checkstyle:illegalCatch")
-    private static void notifyListener(final @NonNull EffectiveModelContext modelContext,
-            final ModelContextListener listener) {
-        try {
-            listener.onModelContextUpdated(modelContext);
-        } catch (RuntimeException e) {
-            LOG.warn("Failed to notify listener {}", listener, e);
-        }
-    }
 }