aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce/src/main/java
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-06 14:17:11 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-17 10:52:47 +0200
commit441e1e45649d7f200e03519f71a689d9b5dd7e4c (patch)
tree8470fc7b069d4d85bb350a8cee0c9c627af2cac4 /server/sonar-ce/src/main/java
parent9bf5fae306b2da2da063435fcb86b505420f46e6 (diff)
downloadsonarqube-441e1e45649d7f200e03519f71a689d9b5dd7e4c.tar.gz
sonarqube-441e1e45649d7f200e03519f71a689d9b5dd7e4c.zip
SONAR-9525 make CeWorker#call return an enum rather than a Boolean
Diffstat (limited to 'server/sonar-ce/src/main/java')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImpl.java11
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorker.java9
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java8
3 files changed, 19 insertions, 9 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImpl.java
index 44f22f74d30..7b12e6c7ee3 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImpl.java
@@ -34,6 +34,7 @@ import org.sonar.ce.configuration.CeConfiguration;
import static com.google.common.util.concurrent.Futures.addCallback;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.sonar.ce.taskprocessor.CeWorker.Result.TASK_PROCESSED;
public class CeProcessingSchedulerImpl implements CeProcessingScheduler, Startable {
private static final Logger LOG = Loggers.get(CeProcessingSchedulerImpl.class);
@@ -67,7 +68,7 @@ public class CeProcessingSchedulerImpl implements CeProcessingScheduler, Startab
@Override
public void startScheduling() {
for (ChainingCallback chainingCallback : chainingCallbacks) {
- ListenableScheduledFuture<Boolean> future = executorService.schedule(chainingCallback.worker, delayBetweenTasks, timeUnit);
+ ListenableScheduledFuture<CeWorker.Result> future = executorService.schedule(chainingCallback.worker, delayBetweenTasks, timeUnit);
addCallback(future, chainingCallback, executorService);
}
}
@@ -79,20 +80,20 @@ public class CeProcessingSchedulerImpl implements CeProcessingScheduler, Startab
}
}
- private class ChainingCallback implements FutureCallback<Boolean> {
+ private class ChainingCallback implements FutureCallback<CeWorker.Result> {
private final AtomicBoolean keepRunning = new AtomicBoolean(true);
private final CeWorker worker;
@CheckForNull
- private ListenableFuture<Boolean> workerFuture;
+ private ListenableFuture<CeWorker.Result> workerFuture;
public ChainingCallback(CeWorker worker) {
this.worker = worker;
}
@Override
- public void onSuccess(@Nullable Boolean result) {
- if (result != null && result) {
+ public void onSuccess(@Nullable CeWorker.Result result) {
+ if (result != null && result == TASK_PROCESSED) {
chainWithoutDelay();
} else {
chainWithDelay();
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorker.java b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorker.java
index f0da47fc356..96bb7df9243 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorker.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorker.java
@@ -28,7 +28,14 @@ import org.sonar.ce.queue.CeTask;
* {@link Callable#call()} returns a Boolean which is {@code true} when some a {@link CeTask} was processed,
* {@code false} otherwise.
*/
-public interface CeWorker extends Callable<Boolean> {
+public interface CeWorker extends Callable<CeWorker.Result> {
+ enum Result {
+ /** Worker found no task to process */
+ NO_TASK,
+ /** Worker found a task and processed it (either successfully or not) */
+ TASK_PROCESSED
+ }
+
/**
* Position of the current CeWorker among all the running workers.
*/
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java
index 6052abb03d6..44034a70cfc 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java
@@ -31,6 +31,8 @@ import org.sonar.core.util.logs.Profiler;
import org.sonar.db.ce.CeActivityDto;
import static java.lang.String.format;
+import static org.sonar.ce.taskprocessor.CeWorker.Result.NO_TASK;
+import static org.sonar.ce.taskprocessor.CeWorker.Result.TASK_PROCESSED;
public class CeWorkerImpl implements CeWorker {
@@ -52,10 +54,10 @@ public class CeWorkerImpl implements CeWorker {
}
@Override
- public Boolean call() throws Exception {
+ public Result call() throws Exception {
Optional<CeTask> ceTask = tryAndFindTaskToExecute();
if (!ceTask.isPresent()) {
- return false;
+ return NO_TASK;
}
try {
@@ -63,7 +65,7 @@ public class CeWorkerImpl implements CeWorker {
} catch (Exception e) {
LOG.error(format("An error occurred while executing task with uuid '%s'", ceTask.get().getUuid()), e);
}
- return true;
+ return TASK_PROCESSED;
}
private Optional<CeTask> tryAndFindTaskToExecute() {