use of org.scijava.module.Module in project imagej-omero by imagej.
the class ModuleAdapter method launch.
/**
* Executes the associated ImageJ module as an OMERO script.
*
* @throws IOException
* @throws ServerError
* @throws ExecutionException
* @throws CannotCreateSessionException
* @throws PermissionDeniedException
* @throws DSAccessException
* @throws DSOutOfServiceException
*/
public void launch() throws ServerError, IOException, ExecutionException, PermissionDeniedException, CannotCreateSessionException, DSOutOfServiceException, DSAccessException {
// populate inputs
log.debug(info.getTitle() + ": populating inputs");
final HashMap<String, Object> inputMap = new HashMap<>();
for (final String name : client.getInputKeys()) {
final ModuleItem<?> input = getInput(name);
final Class<?> type = input.getType();
final Object value = omeroService.toImageJ(client, client.getInput(name), type);
inputMap.put(input.getName(), value);
}
// execute ImageJ module
log.debug(info.getTitle() + ": executing module");
final Future<Module> future = moduleService.run(info, true, inputMap);
final Module module = moduleService.waitFor(future);
final HashMap<String, TableData> tables = new HashMap<>();
// populate outputs, except tables
log.debug(info.getTitle() + ": populating outputs");
for (final ModuleItem<?> item : module.getInfo().outputs()) {
final Object value = omeroService.toOMERO(client, item.getValue(module));
final String name = getOutputName(item);
if (value == null) {
log.warn(info.getTitle() + ": output '" + name + "' is null");
}
if (value instanceof omero.RType)
client.setOutput(name, (omero.RType) value);
if (value instanceof TableData)
tables.put(name, (TableData) value);
}
createOutputLinks(inputMap, tables);
gateway.disconnect();
log.debug(info.getTitle() + ": completed execution");
}
use of org.scijava.module.Module in project imagej-ops by imagej.
the class DefaultOpMatchingService method moduleConforms.
/**
* Verifies that the given candidate's module conforms.
* <p>
* Helper method of {@link #filterMatches(List)}.
* </p>
*/
private boolean moduleConforms(final OpCandidate candidate) {
// create module and assign the inputs
final Module module = createModule(candidate, candidate.getArgs());
candidate.setModule(module);
// make sure the op itself is happy with these arguments
final Object op = module.getDelegateObject();
if (op instanceof Contingent) {
final Contingent c = (Contingent) op;
if (!c.conforms()) {
candidate.setStatus(StatusCode.DOES_NOT_CONFORM);
return false;
}
}
// found a match!
return true;
}
use of org.scijava.module.Module in project imagej-omero by imagej.
the class ModuleAdapter method getJobInfo.
/**
* Converts ImageJ module metadata to OMERO job metadata.
*/
public omero.RType getJobInfo() {
// populate module metadata
final omero.grid.JobParams params = new omero.grid.JobParams();
// info.getName();
params.name = "[ImageJ] " + info.getTitle();
params.version = getVersion();
params.description = info.getDescription();
params.stdoutFormat = "text/plain";
params.stderrFormat = "text/plain";
// Instantiate and preprocess the module
final Module m = moduleService.createModule(info);
final List<PreprocessorPlugin> pre = pluginService.createInstancesOfType(PreprocessorPlugin.class);
final ModuleRunner mr = new ModuleRunner(getContext(), m, pre, null);
mr.preProcess();
// count module inputs and outputs
final int inputCount = m.getInputs().size();
final int outputCount = m.getOutputs().size();
final int inputDigits = String.valueOf(inputCount).length();
final int outputDigits = String.valueOf(outputCount).length();
// convert metadata for each module input
params.inputs = new HashMap<>();
int inputIndex = 0;
for (final ModuleItem<?> item : info.inputs()) {
if (item.getVisibility() == ItemVisibility.MESSAGE)
continue;
if (m.isInputResolved(item.getName()))
continue;
final omero.grid.Param param = omeroService.getJobParam(item);
if (param != null) {
param.grouping = pad(inputIndex++, inputDigits);
params.inputs.put(getInputName(item), param);
}
}
// convert metadata for each module output
params.outputs = new HashMap<>();
int outputIndex = 0;
for (final ModuleItem<?> item : info.outputs()) {
final omero.grid.Param param = omeroService.getJobParam(item);
if (param != null) {
param.grouping = pad(outputIndex++, outputDigits);
params.outputs.put(getOutputName(item), param);
}
}
return omero.rtypes.rinternal(params);
}
use of org.scijava.module.Module in project imagej-ops by imagej.
the class DefaultOpMatchingService method createModule.
/**
* Helper method of {@link #match(OpCandidate, Object[])}.
*/
private Module createModule(final OpCandidate candidate, final Object... args) {
// create the module
final Module module = moduleService.createModule(candidate.cInfo());
// unwrap the created op
final Op op = OpUtils.unwrap(module, candidate.getRef());
// inject the op execution environment
op.setEnvironment(candidate.ops());
// populate the inputs and return the module
return assignInputs(module, args);
}
use of org.scijava.module.Module in project imagej-ops by imagej.
the class DefaultOpMatchingService method match.
/**
* Helper method of {@link #match(OpCandidate)}.
*/
private Module match(final OpCandidate candidate, final Object[] args) {
// check that each parameter is compatible with its argument
final int badIndex = typesMatch(candidate, args);
if (badIndex >= 0) {
final String message = typeClashMessage(candidate, args, badIndex);
candidate.setStatus(StatusCode.ARG_TYPES_DO_NOT_MATCH, message);
return null;
}
// create module and assign the inputs
final Module module = createModule(candidate, args);
candidate.setModule(module);
// make sure the op itself is happy with these arguments
final Object op = module.getDelegateObject();
if (op instanceof Contingent) {
final Contingent c = (Contingent) op;
if (!c.conforms()) {
candidate.setStatus(StatusCode.DOES_NOT_CONFORM);
return null;
}
}
// found a match!
return module;
}
Aggregations