Package org.scijava.module
Class DefaultModuleService
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.plugin.AbstractRichPlugin
-
- org.scijava.service.AbstractService
-
- org.scijava.module.DefaultModuleService
-
- All Implemented Interfaces:
Comparable<Prioritized>,Contextual,Disposable,Identifiable,Initializable,Locatable,Logged,ModuleService,HasPluginInfo,RichPlugin,SciJavaPlugin,Prioritized,SciJavaService,Service,Versioned
public class DefaultModuleService extends AbstractService implements ModuleService
Default service for keeping track of and executing available modules.- Author:
- Curtis Rueden
- See Also:
Module,ModuleInfo
-
-
Constructor Summary
Constructors Constructor Description DefaultModuleService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddModule(ModuleInfo module)Manually registers a module with the module service.voidaddModules(Collection<? extends ModuleInfo> modules)Manually registers a list of modules with the module service.ModulecreateModule(ModuleInfo info)Creates an instance of the given module.<T> TgetDefaultValue(ModuleItem<T> item)Gets the default value of the givenModuleItem.ModuleIndexgetIndex()Gets the index of available modules.ModuleInfogetModuleById(String id)Gets the module with the given identifier string.ModuleInfogetModuleForAccelerator(Accelerator acc)Gets the module for a given keyboard shortcut.List<ModuleInfo>getModules()Gets the list of available modules.<T> ModuleItem<T>getSingleInput(Module module, Class<T> type)Checks the given module for a solitary unresolved fillable input of the given type, returning the relevantModuleItemif found, or null if not exactly one unresolved fillable input of that type.ModuleItem<?>getSingleInput(Module module, Collection<Class<?>> types)AsModuleService.getSingleInput(Module, Class)but will match with a set of potential classes, at the cost of generic parameter safety.<T> ModuleItem<T>getSingleOutput(Module module, Class<T> type)Checks the given module for a solitary unresolved output of the given type, returning the relevantModuleItemif found, or null if not exactly one unresolved output of that type.ModuleItem<?>getSingleOutput(Module module, Collection<Class<?>> types)AsModuleService.getSingleOutput(Module, Class)but will match with a set of potential classes, at the cost of generic parameter safety.voidinitialize()Performs any needed initialization when the service is first loaded.<T> Tload(ModuleItem<T> item)Returns the value, if any, stored in thePrefServicefor the givenModuleItem.voidloadInputs(Module module)Loads values from persistent storage into the givenModule.voidremoveModule(ModuleInfo module)Manually unregisters a module with the module service.voidremoveModules(Collection<? extends ModuleInfo> modules)Manually unregisters a list of modules with the module service.<M extends Module>
Future<M>run(M module, boolean process, Object... inputs)Executes the given module.<M extends Module>
Future<M>run(M module, boolean process, Map<String,Object> inputMap)Executes the given module.<M extends Module>
Future<M>run(M module, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Object... inputs)Executes the given module.<M extends Module>
Future<M>run(M module, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Map<String,Object> inputMap)Executes the given module.Future<Module>run(ModuleInfo info, boolean process, Object... inputs)Executes the given module.Future<Module>run(ModuleInfo info, boolean process, Map<String,Object> inputMap)Executes the given module.Future<Module>run(ModuleInfo info, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Object... inputs)Executes the given module.Future<Module>run(ModuleInfo info, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Map<String,Object> inputMap)Executes the given module.<T> voidsave(ModuleItem<T> item, T value)Registers the given value for the givenModuleItemusing thePrefService.voidsaveInputs(Module module)Saves values to persistent storage from the givenModule.<M extends Module>
MwaitFor(Future<M> future)Blocks until the given module is finished executing.-
Methods inherited from class org.scijava.service.AbstractService
getContext, setContext, toString
-
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
getInfo, getPriority, setInfo, setPriority
-
Methods inherited from class org.scijava.AbstractContextual
context
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.Disposable
dispose
-
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
-
Methods inherited from interface org.scijava.Locatable
getLocation
-
Methods inherited from interface org.scijava.Prioritized
compareTo, getPriority, setPriority
-
Methods inherited from interface org.scijava.plugin.RichPlugin
getIdentifier, log
-
Methods inherited from interface org.scijava.service.Service
registerEventHandlers
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
-
-
-
Method Detail
-
getIndex
public ModuleIndex getIndex()
Description copied from interface:ModuleServiceGets the index of available modules.- Specified by:
getIndexin interfaceModuleService
-
addModule
public void addModule(ModuleInfo module)
Description copied from interface:ModuleServiceManually registers a module with the module service.- Specified by:
addModulein interfaceModuleService
-
removeModule
public void removeModule(ModuleInfo module)
Description copied from interface:ModuleServiceManually unregisters a module with the module service.- Specified by:
removeModulein interfaceModuleService
-
addModules
public void addModules(Collection<? extends ModuleInfo> modules)
Description copied from interface:ModuleServiceManually registers a list of modules with the module service.- Specified by:
addModulesin interfaceModuleService
-
removeModules
public void removeModules(Collection<? extends ModuleInfo> modules)
Description copied from interface:ModuleServiceManually unregisters a list of modules with the module service.- Specified by:
removeModulesin interfaceModuleService
-
getModules
public List<ModuleInfo> getModules()
Description copied from interface:ModuleServiceGets the list of available modules.- Specified by:
getModulesin interfaceModuleService
-
getModuleById
public ModuleInfo getModuleById(String id)
Description copied from interface:ModuleServiceGets the module with the given identifier string.- Specified by:
getModuleByIdin interfaceModuleService- Parameters:
id- The identifier string corresponding to the desired module.- Returns:
- The
Identifiablemodule with the given identifier.
-
getModuleForAccelerator
public ModuleInfo getModuleForAccelerator(Accelerator acc)
Description copied from interface:ModuleServiceGets the module for a given keyboard shortcut.- Specified by:
getModuleForAcceleratorin interfaceModuleService- Parameters:
acc- the accelerator for which to search.- Returns:
- the module info for the corresponding module, or null.
-
createModule
public Module createModule(ModuleInfo info)
Description copied from interface:ModuleServiceCreates an instance of the given module.If the module implements the
Contextualinterface, the appropriate context is injected. Similarly, if the module implements thePrioritizedinterface, the appropriate priority is injected.Note that in the case of commands, this method does not do any preprocessing on the command instances, so parameters will not be auto-populated, initializers will not be executed, etc.
- Specified by:
createModulein interfaceModuleService
-
run
public Future<Module> run(ModuleInfo info, boolean process, Object... inputs)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
info- The module to instantiate and run.process- If true, executes the module with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the module with no pre- or postprocessing.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the module, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public Future<Module> run(ModuleInfo info, boolean process, Map<String,Object> inputMap)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
info- The module to instantiate and run.process- If true, executes the module with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the module with no pre- or postprocessing.inputMap- Table of input parameter values, with keys matching theModuleInfo's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public Future<Module> run(ModuleInfo info, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Object... inputs)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
info- The module to instantiate and run.pre- List of preprocessing steps to perform.post- List of postprocessing steps to perform.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the module, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public Future<Module> run(ModuleInfo info, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Map<String,Object> inputMap)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
info- The module to instantiate and run.pre- List of preprocessing steps to perform.post- List of postprocessing steps to perform.inputMap- Table of input parameter values, with keys matching theModuleInfo's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public <M extends Module> Future<M> run(M module, boolean process, Object... inputs)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
module- The module to run.process- If true, executes the module with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the module with no pre- or postprocessing.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the module, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public <M extends Module> Future<M> run(M module, boolean process, Map<String,Object> inputMap)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
module- The module to run.process- If true, executes the module with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the module with no pre- or postprocessing.inputMap- Table of input parameter values, with keys matching theModuleInfo's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public <M extends Module> Future<M> run(M module, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Object... inputs)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
module- The module to run.pre- List of preprocessing steps to perform.post- List of postprocessing steps to perform.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the module, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
public <M extends Module> Future<M> run(M module, List<? extends ModulePreprocessor> pre, List<? extends ModulePostprocessor> post, Map<String,Object> inputMap)
Description copied from interface:ModuleServiceExecutes the given module.- Specified by:
runin interfaceModuleService- Parameters:
module- The module to run.pre- List of preprocessing steps to perform.post- List of postprocessing steps to perform.inputMap- Table of input parameter values, with keys matching the module'sModuleInfo's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
waitFor
public <M extends Module> M waitFor(Future<M> future)
Description copied from interface:ModuleServiceBlocks until the given module is finished executing.- Specified by:
waitForin interfaceModuleService
-
getSingleInput
public <T> ModuleItem<T> getSingleInput(Module module, Class<T> type)
Description copied from interface:ModuleServiceChecks the given module for a solitary unresolved fillable input of the given type, returning the relevantModuleItemif found, or null if not exactly one unresolved fillable input of that type.- Specified by:
getSingleInputin interfaceModuleService
-
getSingleOutput
public <T> ModuleItem<T> getSingleOutput(Module module, Class<T> type)
Description copied from interface:ModuleServiceChecks the given module for a solitary unresolved output of the given type, returning the relevantModuleItemif found, or null if not exactly one unresolved output of that type.- Specified by:
getSingleOutputin interfaceModuleService
-
getSingleInput
public ModuleItem<?> getSingleInput(Module module, Collection<Class<?>> types)
Description copied from interface:ModuleServiceAsModuleService.getSingleInput(Module, Class)but will match with a set of potential classes, at the cost of generic parameter safety.- Specified by:
getSingleInputin interfaceModuleService
-
getSingleOutput
public ModuleItem<?> getSingleOutput(Module module, Collection<Class<?>> types)
Description copied from interface:ModuleServiceAsModuleService.getSingleOutput(Module, Class)but will match with a set of potential classes, at the cost of generic parameter safety.- Specified by:
getSingleOutputin interfaceModuleService
-
save
public <T> void save(ModuleItem<T> item, T value)
Description copied from interface:ModuleServiceRegisters the given value for the givenModuleItemusing thePrefService.- Specified by:
savein interfaceModuleService
-
load
public <T> T load(ModuleItem<T> item)
Description copied from interface:ModuleServiceReturns the value, if any, stored in thePrefServicefor the givenModuleItem.- Specified by:
loadin interfaceModuleService
-
getDefaultValue
public <T> T getDefaultValue(ModuleItem<T> item)
Description copied from interface:ModuleServiceGets the default value of the givenModuleItem.- Specified by:
getDefaultValuein interfaceModuleService
-
saveInputs
public void saveInputs(Module module)
Description copied from interface:ModuleServiceSaves values to persistent storage from the givenModule.- Specified by:
saveInputsin interfaceModuleService
-
loadInputs
public void loadInputs(Module module)
Description copied from interface:ModuleServiceLoads values from persistent storage into the givenModule.- Specified by:
loadInputsin interfaceModuleService
-
initialize
public void initialize()
Description copied from interface:ServicePerforms any needed initialization when the service is first loaded.NB: This method is not intended to be called directly. It is called by the service framework itself (specifically by the
ServiceHelper) when initializing the service. It should not be called a second time.- Specified by:
initializein interfaceInitializable- Specified by:
initializein interfaceService
-
-