Skip to content

Commit b71dc5c

Browse files
committed
Support cancelation during module initialization
Thanks to Richard Domander for pointing out this limitation. See: https://gitter.im/fiji/fiji/archives/2015/12/08
1 parent 9ad849d commit b71dc5c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/scijava/module/process/InitPreprocessor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
package org.scijava.module.process;
3333

34+
import org.scijava.Cancelable;
3435
import org.scijava.Priority;
3536
import org.scijava.log.LogService;
3637
import org.scijava.module.MethodCallException;
@@ -58,6 +59,7 @@ public class InitPreprocessor extends AbstractPreprocessorPlugin {
5859
public void process(final Module module) {
5960
try {
6061
module.initialize();
62+
if (isCanceled(module)) cancel(getCancelReason(module));
6163
}
6264
catch (final MethodCallException exc) {
6365
if (log != null) log.error(exc);
@@ -66,4 +68,16 @@ public void process(final Module module) {
6668
}
6769
}
6870

71+
// -- Helper methods --
72+
73+
private boolean isCanceled(final Module module) {
74+
return module instanceof Cancelable && ((Cancelable) module).isCanceled();
75+
}
76+
77+
private String getCancelReason(final Module module) {
78+
if (!(module instanceof Cancelable)) return null;
79+
final String cancelReason = ((Cancelable) module).getCancelReason();
80+
return cancelReason == null ? "" : cancelReason;
81+
}
82+
6983
}

0 commit comments

Comments
 (0)