Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit 1706f71

Browse files
committed
Processing events on Bitbucket Server's event threads #78
1 parent 36aa1ce commit 1706f71

File tree

5 files changed

+107
-12
lines changed

5 files changed

+107
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Changelog of Pull Request Notifier for Stash.
44

5+
## 1.35
6+
* Processing events on Bitbucket Server's event threads
7+
58
## 1.34
69
* Url encoding evaluated values when they are used in URL invocations.
710

src/main/java/se/bjurr/prnfs/listener/PrnfsPullRequestEventListener.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static se.bjurr.prnfs.settings.SettingsStorage.getPrnfsSettings;
1919

2020
import java.util.Map;
21+
import java.util.concurrent.ExecutorService;
2122
import java.util.logging.Logger;
2223

2324
import se.bjurr.prnfs.listener.PrnfsRenderer.PrnfsVariable;
@@ -54,6 +55,7 @@ public class PrnfsPullRequestEventListener {
5455
private final RepositoryService repositoryService;
5556
private final ApplicationPropertiesService propertiesService;
5657
private final PullRequestService pullRequestService;
58+
private final ExecutorService executorService;
5759
private static final Logger logger = getLogger(PrnfsPullRequestEventListener.class.getName());
5860

5961
private static Invoker invoker = new Invoker() {
@@ -69,64 +71,75 @@ public static void setInvoker(Invoker invoker) {
6971
}
7072

7173
public PrnfsPullRequestEventListener(PluginSettingsFactory pluginSettingsFactory, RepositoryService repositoryService,
72-
ApplicationPropertiesService propertiesService, PullRequestService pullRequestService) {
74+
ApplicationPropertiesService propertiesService, PullRequestService pullRequestService,
75+
ExecutorService executorService) {
7376
this.pluginSettingsFactory = pluginSettingsFactory;
7477
this.repositoryService = repositoryService;
7578
this.propertiesService = propertiesService;
7679
this.pullRequestService = pullRequestService;
80+
this.executorService = executorService;
7781
}
7882

7983
@EventListener
8084
public void onEvent(PullRequestApprovedEvent e) {
81-
handleEvent(e);
85+
handleEventAsync(e);
8286
}
8387

8488
@EventListener
8589
public void onEvent(PullRequestCommentAddedEvent e) {
86-
handleEvent(e);
90+
handleEventAsync(e);
8791
}
8892

8993
@EventListener
9094
public void onEvent(PullRequestCommentRepliedEvent e) {
91-
handleEvent(e);
95+
handleEventAsync(e);
9296
}
9397

9498
@EventListener
9599
public void onEvent(PullRequestDeclinedEvent e) {
96-
handleEvent(e);
100+
handleEventAsync(e);
97101
}
98102

99103
@EventListener
100104
public void onEvent(PullRequestMergedEvent e) {
101-
handleEvent(e);
105+
handleEventAsync(e);
102106
}
103107

104108
@EventListener
105109
public void onEvent(PullRequestOpenedEvent e) {
106-
handleEvent(e);
110+
handleEventAsync(e);
107111
}
108112

109113
@EventListener
110114
public void onEvent(PullRequestReopenedEvent e) {
111-
handleEvent(e);
115+
handleEventAsync(e);
112116
}
113117

114118
@EventListener
115119
public void onEvent(final PullRequestRescopedEvent e) {
116-
handleEvent(e);
120+
handleEventAsync(e);
117121
}
118122

119123
@EventListener
120124
public void onEvent(PullRequestUnapprovedEvent e) {
121-
handleEvent(e);
125+
handleEventAsync(e);
122126
}
123127

124128
@EventListener
125129
public void onEvent(PullRequestUpdatedEvent e) {
126-
handleEvent(e);
130+
handleEventAsync(e);
127131
}
128132

129133
@VisibleForTesting
134+
public void handleEventAsync(final PullRequestEvent pullRequestEvent) {
135+
executorService.execute(new Runnable() {
136+
@Override
137+
public void run() {
138+
handleEvent(pullRequestEvent);
139+
}
140+
});
141+
}
142+
130143
public void handleEvent(final PullRequestEvent pullRequestEvent) {
131144
try {
132145
if (pullRequestEvent.getPullRequest().isClosed() && pullRequestEvent instanceof PullRequestCommentEvent) {

src/main/resources/atlassian-plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<component-import key="pluginSettingsFactory" interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory" />
1818
<component-import key="transactionTemplate" interface="com.atlassian.sal.api.transaction.TransactionTemplate" />
1919
<component-import key="repositoryService" interface="com.atlassian.stash.repository.RepositoryService" />
20+
<component-import key="executorService" interface="java.util.concurrent.ExecutorService"/>
2021

2122
<rest key="rest" path="/prnfs-admin" version="1.0">
2223
<description>Provides REST resources for the admin UI.</description>

src/test/java/se/bjurr/prnfs/admin/utils/PrnfsTestBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public <T> T execute(TransactionCallback<T> action) {
155155
configResource = new ConfigResource(userManager, pluginSettingsFactory, transactionTemplate, securityService);
156156
pullRequestService = mock(PullRequestService.class);
157157
listener = new PrnfsPullRequestEventListener(pluginSettingsFactory, repositoryService, propertiesService,
158-
pullRequestService);
158+
pullRequestService, new SyncExecutorService());
159159
UserService userService = mock(UserService.class);
160160
withPullRequest(pullRequestEventBuilder().build().getPullRequest());
161161
manualResouce = new ManualResource(userManager, userService, pluginSettingsFactory, pullRequestService, listener,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package se.bjurr.prnfs.admin.utils;
2+
3+
import java.util.Collection;
4+
import java.util.List;
5+
import java.util.concurrent.Callable;
6+
import java.util.concurrent.ExecutionException;
7+
import java.util.concurrent.ExecutorService;
8+
import java.util.concurrent.Future;
9+
import java.util.concurrent.TimeUnit;
10+
import java.util.concurrent.TimeoutException;
11+
12+
public class SyncExecutorService implements ExecutorService {
13+
@Override
14+
public boolean awaitTermination(final long timeout, final TimeUnit unit) throws InterruptedException {
15+
return false;
16+
}
17+
18+
@Override
19+
public void execute(final Runnable command) {
20+
command.run();
21+
}
22+
23+
@Override
24+
public <T> List<Future<T>> invokeAll(final Collection<? extends Callable<T>> tasks) throws InterruptedException {
25+
return null;
26+
}
27+
28+
@Override
29+
public <T> List<Future<T>> invokeAll(final Collection<? extends Callable<T>> tasks, final long timeout,
30+
final TimeUnit unit) throws InterruptedException {
31+
return null;
32+
}
33+
34+
@Override
35+
public <T> T invokeAny(final Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
36+
return null;
37+
}
38+
39+
@Override
40+
public <T> T invokeAny(final Collection<? extends Callable<T>> tasks, final long timeout, final TimeUnit unit)
41+
throws InterruptedException, ExecutionException, TimeoutException {
42+
return null;
43+
}
44+
45+
@Override
46+
public boolean isShutdown() {
47+
return false;
48+
}
49+
50+
@Override
51+
public boolean isTerminated() {
52+
return false;
53+
}
54+
55+
@Override
56+
public void shutdown() {
57+
}
58+
59+
@Override
60+
public List<Runnable> shutdownNow() {
61+
return null;
62+
}
63+
64+
@Override
65+
public <T> Future<T> submit(final Callable<T> task) {
66+
return null;
67+
}
68+
69+
@Override
70+
public Future<?> submit(final Runnable task) {
71+
return null;
72+
}
73+
74+
@Override
75+
public <T> Future<T> submit(final Runnable task, final T result) {
76+
return null;
77+
}
78+
}

0 commit comments

Comments
 (0)