-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a separate ExecutorService to fix #73.
- Updated AsyncProcessor to look at the Bitbucket Server verson and choose between using the shared ExecutorService (5.9+) or creating its own ExecutorService (previous versions) - Bitbucket Server 5.9 includes a fix which prevents add-ons using the shared BucketedExecutor from blocking hook callbacks - Removed some dead code in AsyncProcessor and PullRequestListener - Simplified Maven structure and reconfigured how integration and unit tests are distinguished - Moved unit tests from src/test/java/ut to src/test/java - Added a simple UserResourceTest which requests configuration for a repository which hasn't had any applied - This verifies that the PR Harmony plugin has been installed and enabled successfully, and that its REST resource is available - Simplified some of the processing in UserUtils to use the API more efficiently and avoid various IDEA inspection warnings
- Loading branch information
Bryan Turner
committed
Mar 1, 2018
1 parent
ae997a0
commit b45a931
Showing
19 changed files
with
230 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
package com.monitorjbl.plugins; | ||
|
||
import com.atlassian.bitbucket.concurrent.BucketProcessor; | ||
import com.atlassian.bitbucket.util.Version; | ||
import com.atlassian.bitbucket.util.concurrent.ExecutorUtils; | ||
import com.atlassian.sal.api.ApplicationProperties; | ||
import com.atlassian.sal.api.lifecycle.LifecycleAware; | ||
import com.atlassian.util.concurrent.ThreadFactories; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class AsyncProcessor { | ||
private static final String PREFIX = "com.monitorjbl.plugins:pr-harmony:"; | ||
private final ExecutorService concurrencyService; | ||
public class AsyncProcessor implements LifecycleAware { | ||
|
||
public AsyncProcessor(ExecutorService concurrencyService) { | ||
this.concurrencyService = concurrencyService; | ||
} | ||
private static final Version VERSION_5_9 = new Version(5, 9); | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T extends Serializable> void dispatch(Runnable taskRequest) { | ||
concurrencyService.submit(taskRequest); | ||
} | ||
private final ExecutorService executorService; | ||
private final boolean ownsExecutor; | ||
|
||
public static abstract class TaskProcessor<T extends Serializable> implements BucketProcessor<T> { | ||
@Override | ||
public void process(@Nonnull String s, @Nonnull List<T> list) { | ||
list.forEach(this::handleTask); | ||
public AsyncProcessor(ApplicationProperties applicationProperties, ExecutorService executorService) { | ||
ownsExecutor = new Version(applicationProperties.getVersion()).compareTo(VERSION_5_9) < 0; | ||
if (ownsExecutor) { | ||
//For Bitbucket Server versions before 5.9, use our own ExecutorService to avoid starving out hook callbacks | ||
this.executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), | ||
ThreadFactories.namedThreadFactory("pr-harmony", ThreadFactories.Type.DAEMON)); | ||
} else { | ||
//Bitbucket Server 5.9 includes a fix for BSERV-10652, which moves hook callback to their own threadpool, so | ||
//for 5.9+ use the shared executor | ||
this.executorService = executorService; | ||
} | ||
} | ||
|
||
public abstract void handleTask(T task); | ||
public void dispatch(Runnable taskRequest) { | ||
executorService.execute(taskRequest); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
//No-op | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
if (ownsExecutor) { | ||
ExecutorUtils.shutdown(executorService, LoggerFactory.getLogger(getClass())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.