Skip to content
Snippets Groups Projects
Commit feb55e3f authored by Kanzhe Jiang's avatar Kanzhe Jiang
Browse files

BSC-3006: make the count an tomicInteger.

parent 423c5532
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import java.util.Queue; ...@@ -10,6 +10,7 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.FloodlightModuleException;
...@@ -64,7 +65,8 @@ public class FlowReconcileManager ...@@ -64,7 +65,8 @@ public class FlowReconcileManager
/** a minimum flow reconcile rate so that it won't stave */ /** a minimum flow reconcile rate so that it won't stave */
protected static int MIN_FLOW_RECONCILE_PER_SECOND = 200; protected static int MIN_FLOW_RECONCILE_PER_SECOND = 200;
/** once per second */ /** start flow reconcile in 10ms after a new reconcile request is received.
* The max delay is 1 second. */
protected static int FLOW_RECONCILE_DELAY_MILLISEC = 10; protected static int FLOW_RECONCILE_DELAY_MILLISEC = 10;
protected Date lastReconcileTime; protected Date lastReconcileTime;
...@@ -72,7 +74,7 @@ public class FlowReconcileManager ...@@ -72,7 +74,7 @@ public class FlowReconcileManager
protected static final String EnableConfigKey = "enable"; protected static final String EnableConfigKey = "enable";
protected boolean flowReconcileEnabled; protected boolean flowReconcileEnabled;
volatile public int flowReconcileThreadRunCount; public AtomicInteger flowReconcileThreadRunCount;
@Override @Override
public synchronized void addFlowReconcileListener( public synchronized void addFlowReconcileListener(
...@@ -215,7 +217,7 @@ public class FlowReconcileManager ...@@ -215,7 +217,7 @@ public class FlowReconcileManager
flowReconcileEnabled = false; flowReconcileEnabled = false;
} }
flowReconcileThreadRunCount = 0; flowReconcileThreadRunCount = new AtomicInteger(0);
lastReconcileTime = new Date(0); lastReconcileTime = new Date(0);
logger.debug("FlowReconcile is {}", flowReconcileEnabled); logger.debug("FlowReconcile is {}", flowReconcileEnabled);
} }
...@@ -313,7 +315,7 @@ public class FlowReconcileManager ...@@ -313,7 +315,7 @@ public class FlowReconcileManager
} }
// Flush the flowCache counters. // Flush the flowCache counters.
updateFlush(); updateFlush();
flowReconcileThreadRunCount++; flowReconcileThreadRunCount.incrementAndGet();
} else { } else {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("No flow to be reconciled."); logger.trace("No flow to be reconciled.");
......
...@@ -117,7 +117,7 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { ...@@ -117,7 +117,7 @@ public class FlowReconcileMgrTest extends FloodlightTestCase {
flowReconcileMgr.addFlowReconcileListener(r3); flowReconcileMgr.addFlowReconcileListener(r3);
int pre_flowReconcileThreadRunCount = int pre_flowReconcileThreadRunCount =
flowReconcileMgr.flowReconcileThreadRunCount; flowReconcileMgr.flowReconcileThreadRunCount.get();
Date startTime = new Date(); Date startTime = new Date();
OFMatchReconcile ofmRcIn = new OFMatchReconcile(); OFMatchReconcile ofmRcIn = new OFMatchReconcile();
try { try {
...@@ -147,11 +147,11 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { ...@@ -147,11 +147,11 @@ public class FlowReconcileMgrTest extends FloodlightTestCase {
}).anyTimes(); }).anyTimes();
pre_flowReconcileThreadRunCount = pre_flowReconcileThreadRunCount =
flowReconcileMgr.flowReconcileThreadRunCount; flowReconcileMgr.flowReconcileThreadRunCount.get();
startTime = new Date(); startTime = new Date();
replay(r1, r2, r3); replay(r1, r2, r3);
flowReconcileMgr.reconcileFlow(ofmRcIn); flowReconcileMgr.reconcileFlow(ofmRcIn);
while (flowReconcileMgr.flowReconcileThreadRunCount <= while (flowReconcileMgr.flowReconcileThreadRunCount.get() <=
pre_flowReconcileThreadRunCount) { pre_flowReconcileThreadRunCount) {
Thread.sleep(10); Thread.sleep(10);
Date currTime = new Date(); Date currTime = new Date();
...@@ -174,12 +174,12 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { ...@@ -174,12 +174,12 @@ public class FlowReconcileMgrTest extends FloodlightTestCase {
}).anyTimes(); }).anyTimes();
pre_flowReconcileThreadRunCount = pre_flowReconcileThreadRunCount =
flowReconcileMgr.flowReconcileThreadRunCount; flowReconcileMgr.flowReconcileThreadRunCount.get();
startTime = new Date(); startTime = new Date();
replay(r1, r2, r3); replay(r1, r2, r3);
flowReconcileMgr.reconcileFlow(ofmRcIn); flowReconcileMgr.reconcileFlow(ofmRcIn);
while (flowReconcileMgr.flowReconcileThreadRunCount <= while (flowReconcileMgr.flowReconcileThreadRunCount.get() <=
pre_flowReconcileThreadRunCount) { pre_flowReconcileThreadRunCount) {
Thread.sleep(10); Thread.sleep(10);
Date currTime = new Date(); Date currTime = new Date();
...@@ -197,12 +197,12 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { ...@@ -197,12 +197,12 @@ public class FlowReconcileMgrTest extends FloodlightTestCase {
.andReturn(Command.STOP).times(1); .andReturn(Command.STOP).times(1);
pre_flowReconcileThreadRunCount = pre_flowReconcileThreadRunCount =
flowReconcileMgr.flowReconcileThreadRunCount; flowReconcileMgr.flowReconcileThreadRunCount.get();
startTime = new Date(); startTime = new Date();
replay(r1, r2, r3); replay(r1, r2, r3);
flowReconcileMgr.reconcileFlow(ofmRcIn); flowReconcileMgr.reconcileFlow(ofmRcIn);
while (flowReconcileMgr.flowReconcileThreadRunCount <= while (flowReconcileMgr.flowReconcileThreadRunCount.get() <=
pre_flowReconcileThreadRunCount) { pre_flowReconcileThreadRunCount) {
Thread.sleep(10); Thread.sleep(10);
Date currTime = new Date(); Date currTime = new Date();
...@@ -227,11 +227,11 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { ...@@ -227,11 +227,11 @@ public class FlowReconcileMgrTest extends FloodlightTestCase {
.andReturn(Command.STOP).times(1); .andReturn(Command.STOP).times(1);
pre_flowReconcileThreadRunCount = pre_flowReconcileThreadRunCount =
flowReconcileMgr.flowReconcileThreadRunCount; flowReconcileMgr.flowReconcileThreadRunCount.get();
startTime = new Date(); startTime = new Date();
replay(r1, r2, r3); replay(r1, r2, r3);
flowReconcileMgr.reconcileFlow(ofmRcIn); flowReconcileMgr.reconcileFlow(ofmRcIn);
while (flowReconcileMgr.flowReconcileThreadRunCount <= while (flowReconcileMgr.flowReconcileThreadRunCount.get() <=
pre_flowReconcileThreadRunCount) { pre_flowReconcileThreadRunCount) {
Thread.sleep(10); Thread.sleep(10);
Date currTime = new Date(); Date currTime = new Date();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment