Optimize path selectors 22/78522/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Dec 2018 11:48:15 +0000 (12:48 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 7 Dec 2018 10:03:50 +0000 (10:03 +0000)
Creating multiple object just for the purposes of LOG.trace() is
utterly wasteful. Guard the LOG.trace() with isTraceEnabled() and
also expose a String-only formatter.

Change-Id: If6f3011e89772f82948816a975034a38a82a7922
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathSelector.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelector.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RouterIds.java

index 021885c358d08caf61cf89997269cb0f48457723..86a3242b027c8a8652b0e41cb0b0ea98803f1b6b 100644 (file)
@@ -39,7 +39,9 @@ public final class AddPathSelector extends AbstractBestPathSelector {
              */
             final BestPathState state = new BestPathStateImpl(attrs);
             if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
-                LOG.trace("Selecting path from router {}", RouterIds.createPeerId(routerId).getValue());
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Selecting path from router {}", RouterIds.createPeerIdString(routerId));
+                }
                 this.bestOriginatorId = originatorId;
                 this.bestState = state;
                 this.bestRouteKey = key;
index 43738b0c3dc5a48c57a6ab352c95b10d0d6b2feb..e1bb58157bdaefed0c3569ed548161a4d4eb8972 100644 (file)
@@ -39,7 +39,9 @@ final class BasePathSelector extends AbstractBestPathSelector {
              */
             final BestPathState state = new BestPathStateImpl(attrs);
             if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
-                LOG.trace("Selecting path from router {}", RouterIds.createPeerId(routerId).getValue());
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Selecting path from router {}", RouterIds.createPeerIdString(routerId));
+                }
                 this.bestOriginatorId = originatorId;
                 this.bestRouterId = routerId;
                 this.bestState = state;
@@ -47,7 +49,6 @@ final class BasePathSelector extends AbstractBestPathSelector {
         }
     }
 
-
     BaseBestPath result() {
         return this.bestRouterId == null ? null : new BaseBestPath(this.bestRouterId, this.bestState);
     }
index a7fb36b246cc9d8e2734301f9a29c2eb2e58b5ba..dad049948c6fefbb82b4034e91520b72661e0884 100644 (file)
@@ -68,8 +68,12 @@ public final class RouterIds {
     }
 
     public static PeerId createPeerId(@Nonnull final UnsignedInteger intAddress) {
+        return new PeerId(createPeerIdString(intAddress));
+    }
+
+    public static String createPeerIdString(@Nonnull final UnsignedInteger intAddress) {
         final String inet4Address = InetAddresses.fromInteger(intAddress.intValue()).getHostAddress();
-        return new PeerId(BGP_PREFIX.concat(inet4Address));
+        return BGP_PREFIX.concat(inet4Address);
     }
 
     public static Ipv4Address inetFromPeerId(@Nonnull final PeerId peerId) {