Browse Source

Fix bug of at times getting stuck at PAUSING state on reaching daily limit

tags/1.0.18
ymlam 3 years ago
parent
commit
2a802c659e
2 changed files with 18 additions and 7 deletions
  1. +10
    -4
      src/main/java/altk/comm/engine/Broadcast.java
  2. +8
    -3
      src/main/java/altk/comm/engine/Postback.java

+ 10
- 4
src/main/java/altk/comm/engine/Broadcast.java View File

@@ -381,7 +381,8 @@ public abstract class Broadcast
} }
finally finally
{ {
updateServiceActivityCount(-batch.size());
updateServiceActivityCount(-batch.size());
if (serviceActivityCount == 0) postback.wakeOneUp();
} }
if (sleepBetweenJobs > 0) if (sleepBetweenJobs > 0)
{ {
@@ -1242,6 +1243,7 @@ public abstract class Broadcast
synchronized (readyQueue) synchronized (readyQueue)
{ {
serviceActivityCount += increment; serviceActivityCount += increment;
myLogger.debug("serviceActivityCount = " + serviceActivityCount );
if (increment < 0 && serviceActivityCount <= 0) if (increment < 0 && serviceActivityCount <= 0)
{ {
if (state == BroadcastState.RUNNING if (state == BroadcastState.RUNNING
@@ -1249,9 +1251,6 @@ public abstract class Broadcast
|| state == BroadcastState.CANCELING || state == BroadcastState.CANCELING
) )
{ {
// TODO: investigate possibility that 0 remainingJobCount may
// not be final. It may still change because a finishing job
// may cause a job to be scheduled.
if (getRemainingJobCount() == 0) { if (getRemainingJobCount() == 0) {
setState(BroadcastState.COMPLETED); setState(BroadcastState.COMPLETED);
} }
@@ -1404,6 +1403,13 @@ public abstract class Broadcast
return broadcastType; return broadcastType;
} }


/**
* To be invoked only when postQueue is empty.
* Side effect: sets broadcast state from PAUSING to PAUSE
* when there are no active jobs being processed.
* Similarly from CANCELING to CANCELED, from ABORTING to ABORTED, from COMPLETED to ALLDONE
* @return
*/
public PostbackThreadActionOnEmpty getPostbackThreadActionOnEmpty() { public PostbackThreadActionOnEmpty getPostbackThreadActionOnEmpty() {
myLogger.debug("getPostbackThreadActionOnEmpty(): broadcast state " + state); myLogger.debug("getPostbackThreadActionOnEmpty(): broadcast state " + state);
if (state.isFinal) return PostbackThreadActionOnEmpty.STOP; if (state.isFinal) return PostbackThreadActionOnEmpty.STOP;


+ 8
- 3
src/main/java/altk/comm/engine/Postback.java View File

@@ -455,16 +455,21 @@ public class Postback
{ {
sender.join(); sender.join();
} }
// Close postback connections.
httpclient.close(); httpclient.close();
} }
catch (Exception e) catch (Exception e)
{ {
myLogger.error("Caught when closing HttpClient: " + e.getMessage()); myLogger.error("Caught when closing HttpClient: " + e.getMessage());
} }

broadcast = null; broadcast = null;
} }

public void wakeOneUp()
{
synchronized (postQueue)
{
postQueue.notify();
}
}
} }

Loading…
Cancel
Save