Eliminate the use of ActionableResourceImpl 13/85413/15
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Oct 2019 16:25:44 +0000 (17:25 +0100)
committerKarthikeyan Krishnan <karthikeyangceb007@gmail.com>
Thu, 4 Jun 2020 06:20:05 +0000 (06:20 +0000)
These callers can easily work with the newly-provided ActionableResources
utility class, eliminating callers of InstanceIdentifier.toString()
and also eager string concatenation, which is replaced with a utility
holder class.

JIRA: GENIUS-281
Change-Id: I88059fedafe3b4cce8d32561c7918ef328f17460
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/BgpUtil.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BgpRouteVrfEntryHandler.java

index 06648f2758fc3298caf534b22ac2ebca506ebf3d..9c043cef101e9994335409e83fc1ddc588a287a3 100755 (executable)
@@ -26,7 +26,7 @@ import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.utils.batching.ActionableResource;
-import org.opendaylight.genius.utils.batching.ActionableResourceImpl;
+import org.opendaylight.genius.utils.batching.ActionableResources;
 import org.opendaylight.genius.utils.batching.DefaultBatchHandler;
 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
 import org.opendaylight.mdsal.binding.api.DataBroker;
@@ -144,27 +144,15 @@ public class BgpUtil implements AutoCloseable {
     }
 
     public <T extends DataObject> void update(final InstanceIdentifier<T> path, final T data) {
-        ActionableResourceImpl actResource = new ActionableResourceImpl(path.toString());
-        actResource.setAction(ActionableResource.UPDATE);
-        actResource.setInstanceIdentifier(path);
-        actResource.setInstance(data);
-        bgpResourcesBufferQ.add(actResource);
+        bgpResourcesBufferQ.add(ActionableResources.update(path, data));
     }
 
     public <T extends DataObject> void write(final InstanceIdentifier<T> path, final T data) {
-        ActionableResourceImpl actResource = new ActionableResourceImpl(path.toString());
-        actResource.setAction(ActionableResource.CREATE);
-        actResource.setInstanceIdentifier(path);
-        actResource.setInstance(data);
-        bgpResourcesBufferQ.add(actResource);
+        bgpResourcesBufferQ.add(ActionableResources.create(path, data));
     }
 
     public <T extends DataObject> void delete(final InstanceIdentifier<T> path) {
-        ActionableResourceImpl actResource = new ActionableResourceImpl(path.toString());
-        actResource.setAction(ActionableResource.DELETE);
-        actResource.setInstanceIdentifier(path);
-        actResource.setInstance(null);
-        bgpResourcesBufferQ.add(actResource);
+        bgpResourcesBufferQ.add(ActionableResources.delete(path));
     }
 
     // Convert ProtocolType to thrift protocol_type
index 8ebc4040dbde0876b694b893b019e9abb00ff607..1f1463246ef68dbb31b4001cb0c87acbe0d6b449 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.fibmanager;
 
+import static java.util.Objects.requireNonNull;
 import static java.util.stream.Collectors.toList;
 
 import java.util.ArrayList;
@@ -35,7 +36,7 @@ import org.opendaylight.genius.mdsalutil.actions.ActionSetFieldMplsLabel;
 import org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId;
 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
 import org.opendaylight.genius.utils.batching.ActionableResource;
-import org.opendaylight.genius.utils.batching.ActionableResourceImpl;
+import org.opendaylight.genius.utils.batching.ActionableResources;
 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
 import org.opendaylight.genius.utils.batching.ResourceHandler;
 import org.opendaylight.genius.utils.batching.SubTransaction;
@@ -58,6 +59,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes;
+import org.opendaylight.yangtools.concepts.Identifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.Uint64;
@@ -67,6 +69,39 @@ import org.slf4j.LoggerFactory;
 
 @Singleton
 public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler implements ResourceHandler {
+    private static final class ActionableResourceIdentifier implements Identifier {
+        private static final long serialVersionUID = 1L;
+
+        private final String routeDistinguisher;
+        private final String destPrefix;
+
+        ActionableResourceIdentifier(final String routeDistinguisher, final String destPrefix) {
+            this.routeDistinguisher = requireNonNull(routeDistinguisher);
+            this.destPrefix = requireNonNull(destPrefix);
+        }
+
+        @Override
+        public int hashCode() {
+            return routeDistinguisher.hashCode() * 31 + destPrefix.hashCode();
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (!(obj instanceof ActionableResourceIdentifier)) {
+                return false;
+            }
+            final ActionableResourceIdentifier other = (ActionableResourceIdentifier) obj;
+            return routeDistinguisher.equals(other.routeDistinguisher) && destPrefix.equals(other.destPrefix);
+        }
+
+        @Override
+        public String toString() {
+            return routeDistinguisher + destPrefix;
+        }
+    }
 
     private static final Logger LOG = LoggerFactory.getLogger(BgpRouteVrfEntryHandler.class);
     private static final int BATCH_INTERVAL = 500;
@@ -153,28 +188,18 @@ public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler implements Reso
     }
 
     void createFlows(InstanceIdentifier<VrfEntry> identifier, VrfEntry vrfEntry, String rd) {
-        ActionableResourceImpl actResource = new ActionableResourceImpl(rd + vrfEntry.getDestPrefix());
-        actResource.setAction(ActionableResource.CREATE);
-        actResource.setInstanceIdentifier(identifier);
-        actResource.setInstance(vrfEntry);
-        vrfEntryBufferQ.add(actResource);
+        vrfEntryBufferQ.add(ActionableResources.create(new ActionableResourceIdentifier(rd, vrfEntry.getDestPrefix()),
+            identifier, vrfEntry));
     }
 
     void removeFlows(InstanceIdentifier<VrfEntry> identifier, VrfEntry vrfEntry, String rd) {
-        ActionableResourceImpl actResource = new ActionableResourceImpl(rd + vrfEntry.getDestPrefix());
-        actResource.setAction(ActionableResource.DELETE);
-        actResource.setInstanceIdentifier(identifier);
-        actResource.setInstance(vrfEntry);
-        vrfEntryBufferQ.add(actResource);
+        vrfEntryBufferQ.add(ActionableResources.delete(new ActionableResourceIdentifier(rd, vrfEntry.getDestPrefix()),
+            identifier, vrfEntry));
     }
 
     void updateFlows(InstanceIdentifier<VrfEntry> identifier, VrfEntry original, VrfEntry update, String rd) {
-        ActionableResourceImpl actResource = new ActionableResourceImpl(rd + update.getDestPrefix());
-        actResource.setAction(ActionableResource.UPDATE);
-        actResource.setInstanceIdentifier(identifier);
-        actResource.setInstance(update);
-        actResource.setOldInstance(original);
-        vrfEntryBufferQ.add(actResource);
+        vrfEntryBufferQ.add(ActionableResources.update(new ActionableResourceIdentifier(rd, update.getDestPrefix()),
+            identifier, update, original));
     }
 
     /*