Bug 8746: Multi-threading improvements 09/59509/6
authorLorand Jakab <lojakab@cisco.com>
Mon, 26 Jun 2017 07:52:35 +0000 (10:52 +0300)
committerLorand Jakab <lojakab@cisco.com>
Tue, 8 Aug 2017 08:52:45 +0000 (11:52 +0300)
- Remove non-concurrent statistics class
- Make some variables 'volatile'
- Make some methods 'synchronized'

Change-Id: I83471fe7a422e63c2ab90e4c5fbc97b69c187247
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundStats.java [deleted file]
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/AuthenticationKeyDataListener.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/cache/MapRegisterCache.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/ConcurrentLispSouthboundStatsTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundStatsTest.java with 77% similarity]

diff --git a/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundStats.java b/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundStats.java
deleted file mode 100644 (file)
index 3779d95..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.lispflowmapping.southbound;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
-
-/**
- * Object to hold statistics about LISP southbound events.
- *
- * @author Lorand Jakab
- *
- */
-public class LispSouthboundStats {
-    public static final int MAX_LISP_TYPES = getMaxMessageTypeValue();
-
-    private long[] rx = new long[MAX_LISP_TYPES + 1];
-    private long[] tx = new long[MAX_LISP_TYPES + 1];
-    private long rxUnknown = 0;
-    private long txErrors = 0;
-    private long cacheHits = 0;
-    private long cacheMisses = 0;
-
-    public LispSouthboundStats() {
-        resetStats();
-    }
-
-    public void resetStats() {
-        for (int i = 0; i <= MAX_LISP_TYPES; i++) {
-            rx[i] = 0;
-            tx[i] = 0;
-        }
-    }
-
-    public long[] getRx() {
-        return rx;
-    }
-
-    public void incrementRx(int type) {
-        this.rx[type] = incrementWithWrap(rx[type]);
-    }
-
-    public long[] getTx() {
-        return tx;
-    }
-
-    public void incrementTx(int type) {
-        this.tx[type] = incrementWithWrap(tx[type]);
-    }
-
-    public long getRxUnknown() {
-        return rxUnknown;
-    }
-
-    public void incrementRxUnknown() {
-        this.rxUnknown = incrementWithWrap(rxUnknown);
-    }
-
-    public long getTxErrors() {
-        return txErrors;
-    }
-
-    public void incrementTxErrors() {
-        this.txErrors = incrementWithWrap(txErrors);
-    }
-
-    public long getCacheHits() {
-        return cacheHits;
-    }
-
-    public void incrementCacheHits() {
-        this.cacheHits = incrementWithWrap(cacheHits);
-    }
-
-    public long getCacheMisses() {
-        return cacheMisses;
-    }
-
-    public void incrementCacheMisses() {
-        this.cacheMisses = incrementWithWrap(cacheMisses);
-    }
-
-    private static long incrementWithWrap(long value) {
-        if (value == Long.MAX_VALUE) {
-            return 0;
-        } else {
-            return value + 1;
-        }
-    }
-
-    // TODO move this method to the appropriate helper class if we start using MessageType in other places
-    public static int getMaxMessageTypeValue() {
-        int max = 0;
-        for (MessageType mt : MessageType.values()) {
-            if (mt.getIntValue() > max) {
-                max = mt.getIntValue();
-            }
-        }
-        return max;
-    }
-}
index 79bb3ab89e8f3c2c11dc726ac315436c63af5f9b..036c85768a4612775a5dd9133c56cc441b8cfb81 100644 (file)
@@ -38,8 +38,8 @@ public class AuthenticationKeyDataListener implements ClusteredDataTreeChangeLis
     private final DataBroker broker;
     private final InstanceIdentifier<AuthenticationKey> path;
     private ListenerRegistration<ClusteredDataTreeChangeListener<AuthenticationKey>> registration;
-    private boolean authKeyRefreshing = false;
-    private long authKeyRefreshingDate;
+    private volatile boolean authKeyRefreshing = false;
+    private volatile long authKeyRefreshingDate;
 
 
     public AuthenticationKeyDataListener(final DataBroker broker, final AuthKeyDb akdb) {
index 0d2d052330ce9cbc85f1ebf2d3cc5d06c7353dfe..7a32a701f634f1e1cec7f9a593428e09a97ea94a 100644 (file)
@@ -46,7 +46,7 @@ public class MapRegisterCache {
         }
     }
 
-    public MapRegisterCacheValue refreshEntry(final MapRegisterCacheKey mapRegisterCacheKey) {
+    public synchronized MapRegisterCacheValue refreshEntry(final MapRegisterCacheKey mapRegisterCacheKey) {
         final MapRegisterCacheValue mapRegisterCacheValueOld = getEntry(mapRegisterCacheKey);
         final MapRegisterCacheMetadata mapRegisterCacheMetadataOld = mapRegisterCacheValueOld
                 .getMapRegisterCacheMetadata();
@@ -13,17 +13,17 @@ import java.lang.reflect.Field;
 import org.junit.Before;
 import org.junit.Test;
 
-public class LispSouthboundStatsTest {
+public class ConcurrentLispSouthboundStatsTest {
 
-    private static LispSouthboundStats lispSouthboundStats;
+    private static ConcurrentLispSouthboundStats lispSouthboundStats;
 
     @Before
     public void init() {
-        lispSouthboundStats = new LispSouthboundStats();
+        lispSouthboundStats = new ConcurrentLispSouthboundStats();
     }
 
     /**
-     * Tests {@link LispSouthboundStats#resetStats} method.
+     * Tests {@link ConcurrentLispSouthboundStats#resetStats} method.
      */
 
     @Test
@@ -37,7 +37,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementRx} method.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementRx} method.
      */
     @Test
     public void incrementRxTest() {
@@ -54,7 +54,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementRx} method.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementRx} method.
      */
     @Test
     public void incrementRxTest_withMaxValue() throws NoSuchFieldException, IllegalAccessException {
@@ -72,7 +72,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementTx} method.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementTx} method.
      */
     @Test
     public void incrementTxTest() {
@@ -89,7 +89,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementRxUnknown} method.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementRxUnknown} method.
      */
     @Test
     public void incrementRxUnknownTest() throws NoSuchFieldException, IllegalAccessException {
@@ -100,7 +100,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementRxUnknown} method with Long.MAX_VALUE.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementRxUnknown} method with Long.MAX_VALUE.
      */
     @Test
     public void incrementRxUnknownTest_withMaxValue() throws NoSuchFieldException, IllegalAccessException {
@@ -111,7 +111,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementTxErrors} method.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementTxErrors} method.
      */
     @Test
     public void incrementTxErrorsTest() throws NoSuchFieldException, IllegalAccessException {
@@ -122,7 +122,7 @@ public class LispSouthboundStatsTest {
     }
 
     /**
-     * Tests {@link LispSouthboundStats#incrementTxErrors} method with Long.MAX_VALUE.
+     * Tests {@link ConcurrentLispSouthboundStats#incrementTxErrors} method with Long.MAX_VALUE.
      */
     @Test
     public void incrementTxErrorsTest_withMaxValue() throws NoSuchFieldException, IllegalAccessException {
@@ -133,19 +133,19 @@ public class LispSouthboundStatsTest {
     }
 
     private static void setRxField(long[] array) throws NoSuchFieldException, IllegalAccessException {
-        Field rx = LispSouthboundStats.class.getDeclaredField("rx");
+        Field rx = ConcurrentLispSouthboundStats.class.getDeclaredField("rx");
         rx.setAccessible(true);
         rx.set(lispSouthboundStats, array);
     }
 
     private static void setRxUnkownField(long value) throws NoSuchFieldException, IllegalAccessException {
-        Field rxUnknown = LispSouthboundStats.class.getDeclaredField("rxUnknown");
+        Field rxUnknown = ConcurrentLispSouthboundStats.class.getDeclaredField("rxUnknown");
         rxUnknown.setAccessible(true);
         rxUnknown.set(lispSouthboundStats, value);
     }
 
     private static void setTxErrorsField(long value) throws NoSuchFieldException, IllegalAccessException {
-        Field txErrors = LispSouthboundStats.class.getDeclaredField("txErrors");
+        Field txErrors = ConcurrentLispSouthboundStats.class.getDeclaredField("txErrors");
         txErrors.setAccessible(true);
         txErrors.set(lispSouthboundStats, value);
     }