sdedic commented on code in PR #6514:
URL: https://github.com/apache/netbeans/pull/6514#discussion_r1348310706
##########
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:
> Are project ops allowed to run in parallel? If yes then `reloadBlocker`
won't be sufficient as marker, since there can be multiple blockers at the same
time and they can finish in arbitrary order.
>
Who knows, I've just invented that concept ... but I'd say yes: there may be
many operations having known (destructive :)) impact on loaded metadata, so it
makes sense to delay the reloads.
Re. sufficiency: Pls. elaborate, I am not sure I've got the point.
> I wonder if this would be simpler with a queue instead of events. Since
this listener chain essentially imitates a queue.
Pls. elaborate -- do you think something like:
- have a List<Task>, each having a TaskListener
- listener removes its Task from list, checks emptiness and if so, schedules
a reload ?
--
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