Skip to content

Commit d523485

Browse files
committed
Wait for command or module execution to complete
CodeRunner plugins should fully execute their associated code, blocking until execution is complete.
1 parent 6453d2f commit d523485

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/main/java/org/scijava/command/run/CommandCodeRunner.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ public class CommandCodeRunner extends AbstractCodeRunner {
5555
// -- CodeRunner methods --
5656

5757
@Override
58-
public void run(final Object code, final Object... args) {
59-
commandService.run(getCommandClass(code), true, args);
58+
public void run(final Object code, final Object... args)
59+
throws InvocationTargetException
60+
{
61+
waitFor(commandService.run(getCommandClass(code), true, args));
6062
}
6163

6264
@Override
6365
public void run(final Object code, final Map<String, Object> inputMap)
6466
throws InvocationTargetException
6567
{
66-
commandService.run(getCommandClass(code), true, inputMap);
68+
waitFor(commandService.run(getCommandClass(code), true, inputMap));
6769
}
6870

6971
// -- Typed methods --

src/main/java/org/scijava/module/run/ModuleCodeRunner.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ public class ModuleCodeRunner extends AbstractCodeRunner {
5757
// -- CodeRunner methods --
5858

5959
@Override
60-
public void run(final Object code, final Object... args) {
61-
moduleService.run(getModuleInfo(code), true, args);
60+
public void run(final Object code, final Object... args)
61+
throws InvocationTargetException
62+
{
63+
waitFor(moduleService.run(getModuleInfo(code), true, args));
6264
}
6365

6466
@Override
6567
public void run(final Object code, final Map<String, Object> inputMap)
6668
throws InvocationTargetException
6769
{
68-
moduleService.run(getModuleInfo(code), true, inputMap);
70+
waitFor(moduleService.run(getModuleInfo(code), true, inputMap));
6971
}
7072

7173
// -- Typed methods --

src/main/java/org/scijava/run/AbstractCodeRunner.java

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

3232
package org.scijava.run;
3333

34+
import java.lang.reflect.InvocationTargetException;
35+
import java.util.concurrent.ExecutionException;
36+
import java.util.concurrent.Future;
37+
3438
import org.scijava.plugin.AbstractHandlerPlugin;
3539

3640
/**
@@ -49,4 +53,20 @@ public Class<Object> getType() {
4953
return Object.class;
5054
}
5155

56+
// -- Internal methods --
57+
58+
protected <T> T waitFor(final Future<T> future)
59+
throws InvocationTargetException
60+
{
61+
try {
62+
return future.get();
63+
}
64+
catch (final InterruptedException exc) {
65+
throw new InvocationTargetException(exc);
66+
}
67+
catch (final ExecutionException exc) {
68+
throw new InvocationTargetException(exc);
69+
}
70+
}
71+
5272
}

0 commit comments

Comments
 (0)