Why isn't it possible to send a cancel request to a JobGroup by calling IProgressMonitor::setCanceled from one of its Jobs? #654
-
Hello all, If I do something like this: IProgressMonitor progressGroup = Job.getJobManager().createProgressGroup();
progressGroup.beginTask("", 2);
job1.setProgressGroup(progressGroup, 1);
job2.setProgressGroup(progressGroup, 1);
JobGroup jobGroup = new JobGroup("The group", 0, 0);
job1.setJobGroup(jobGroup);
job2.setJobGroup(jobGroup);
job1.schedule(); // this one cancels its monitor
job1.join();
job2.schedule(); // here, monitor.isCanceled() == false Since both jobs have completely unrelated monitors, they can not "pass" the state of their monitor to one other. This means that to cancel all jobs in the group one can only call Wouldn't it be better to have all |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Note that In addition, a Maybe (at least from a functional perspective) |
Beta Was this translation helpful? Give feedback.
-
Thank you for pointing that out, I updated the text and the title. The point is that there is no way to communicate the cancel requests that happened in one On the other hand, if I try something similar with public void testCancelParentMonitor_childMonitorIsCanceled() {
NullProgressMonitor parent = new NullProgressMonitor();
SubMonitor child1 = SubMonitor.convert(parent);
parent.setCanceled(true);
assertTrue(child1.isCanceled());
}
public void testCancelChildMonitor_allMonitorsAreCanceled() {
NullProgressMonitor parent = new NullProgressMonitor();
SubMonitor child1 = SubMonitor.convert(parent);
SubMonitor child2 = SubMonitor.convert(parent);
child1.setCanceled(true);
assertTrue(parent.isCanceled());
assertTrue(child2.isCanceled());
} |
Beta Was this translation helpful? Give feedback.
-
Okay, I agree that one would expect monitors of Jobs within one From my point of view, the current implementation of the This always overwrites a monitor that may have already been set when assigning the Job to a progress group. This also conflicts with the specification of the called method, which says that it may only be called when the Job is not part of a job group. So I would expect this line of code to be wrapped inside a check for the Job being part of a progress group (i.e., for no monitor being already set, which happens when assigning the job to a progress group). I think this probably incorrect default behavior will usually not be perceived, because the Eclipse workbench uses a custom |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late reply: I provided a PR to fix the first issue (#666) i.e. cancelation of the jobs when canceling the whole progress group. Regarding the second issue (cancelation of "sibling jobs") IMO the desired behavior wasn't really specified in the JavaDocs and I think I know why: in the UI, jobs in a group are bundled together in the same ... and the cancelation occurs via the method This means that, when working via the UI, one never really cancels one of the jobs but the whole group (
This means that there is no need to really change the current API in order to cancel "sibling" jobs, one can simply provide the desired cancelation policy in the |
Beta Was this translation helpful? Give feedback.
Sorry for the late reply: I provided a PR to fix the first issue (#666) i.e. cancelation of the jobs when canceling the whole progress group.
Regarding the second issue (cancelation of "sibling jobs") IMO the desired behavior wasn't really specified in the JavaDocs and I think I know why: in the UI, jobs in a group are bundled together in the same
ProgressInfoItem
...... and the cancelation occurs via the method
org.eclipse.ui.internal.progress.ProgressInfoItem.cancelOrRemove()
, which callsorg.eclipse.ui.internal.progress.GroupInfo.cancel()
.https://github.com/eclipse-platform/eclipse.platform.ui/blob/73307cb811a2dbdc8023522e1fda6fcee6dba4d0/bundles/org.eclipse.ui.workbench/Eclipse%20U…