mbien commented on code in PR #6514:
URL: https://github.com/apache/netbeans/pull/6514#discussion_r1349656909
##########
java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java:
##########
@@ -559,29 +588,131 @@ void stopHardReferencingMavenPoject() {
return newproject;
}
+ /**
+ * Task that potential project reloads should wait on. If set, a {@link
fireProjectReload}(true) will be scheduled only after this blocker finishes.
+ */
+ private RequestProcessor.Task reloadBlocker;
-
+ /**
+ * Schedules project operation that delays potential reloads. If a reload
is posted, it will be performed only after
+ * this operation compeltes (successfully, or erroneously). Multiple
project operations can be scheduled, an eventual project reload
+ * should happen after all those operations complete. It is possible to
postpone project reload indefinitely, avoid unnecessary
+ * operation schedules.
+ * <p>
+ * To avoid race condition on task startup, this method actually creates
and schedules the task so it blocks reloads from its inception.
+ * It returns the value of the worker task as the result value.
+ * wrapper.
+ * @param rp request processor that should schedule the task
+ * @param delay optional delay, use 0 for immediate run
+ * @param r operation to run
+ * @return the scheduled task
+ */
+ public RequestProcessor.Task scheduleProjectOperation(RequestProcessor rp,
Runnable r, int delay) {
+ RequestProcessor.Task t = rp.create(r);
+ if (Boolean.getBoolean("test.reload.sync")) {
+ LOG.log(Level.FINE, "Running the blocking task synchronously
(test.reload.sync set)");
+ t.run();
+ return t;
+ } else {
+ synchronized (this) {
+ if (reloadBlocker == null) {
+ LOG.log(Level.FINER, "Blocking project reload on task
{0}", t);
+ reloadBlocker = t;
+ } else {
+ // will chain after existing reload blocker AND the new
task.
+ final RequestProcessor.Task t2 = RELOAD_RP.create(() ->
{});
+ LOG.log(Level.FINER, "Creating project blocker {0}, chain
after existing blocker {1}", new Object[] { t2, t });
+ reloadBlocker.addTaskListener((e) -> {
+ t.addTaskListener((e2) -> {
+ synchronized (NbMavenProjectImpl.this) {
+ if (t2 == reloadBlocker) {
+ reloadBlocker = null;
+ }
+ }
+ t2.run();
+ });
+ });
+ reloadBlocker = t2;
+ }
+ }
+ t.schedule(delay);
+ return t;
Review Comment:
added a commit on top of this PR:
https://github.com/mbien/netbeans/commit/7d40cf67b0b2dd4077096d02bc4d067a4e57f5e7
While doing that i noticed another thing what is likely a bug: the reload
task is set to `finished` during construction, but there are places in the code
which check if its finished, for example `getFreshOriginalMavenProject` which
would essentially always return true and the else branch would never run.
(I don't know all the details of NB's concurrency classes, so this might
just be me not understanding something, however I changed that in the commit
too since i couldn't find the spot which would set the task to not finished
when it starts running)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists