Class DefaultCommandService
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.plugin.AbstractRichPlugin
-
- org.scijava.service.AbstractService
-
- org.scijava.plugin.AbstractPTService<Command>
-
- org.scijava.command.DefaultCommandService
-
- All Implemented Interfaces:
Comparable<Prioritized>,CommandService,Contextual,Disposable,Identifiable,Initializable,Locatable,Logged,HasPluginInfo,PTService<Command>,RichPlugin,SciJavaPlugin,Prioritized,SciJavaService,Service,Versioned
public class DefaultCommandService extends AbstractPTService<Command> implements CommandService
Default service for working withCommands. Available commands are obtained from the plugin service. Loading of the actual command classes can be deferred until a particular command's first execution.- Author:
- Curtis Rueden
- See Also:
Command
-
-
Constructor Summary
Constructors Constructor Description DefaultCommandService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventServiceeventService()<C extends Command>
CommandInfogetCommand(Class<C> commandClass)Gets the first available command of the given class, or null if none.CommandInfogetCommand(String className)Gets the first available command of the given class name, or null if none.List<CommandInfo>getCommands()Gets the list of all availableCommands).<CT extends Command>
List<CommandInfo>getCommands(List<PluginInfo<CT>> plugins)Gets the list ofCommands corresponding to the given plugins.<C extends Command>
List<CommandInfo>getCommandsOfClass(Class<C> commandClass)Gets the list of commands of the given class.List<CommandInfo>getCommandsOfClass(String className)Gets the list of commands with the given class name.<CT extends Command>
List<CommandInfo>getCommandsOfType(Class<CT> type)Gets the list ofCommands of the given type.Class<Command>getPluginType()Gets the type of plugins managed by this service.voidinitialize()Performs any needed initialization when the service is first loaded.ModuleServicemoduleService()protected voidonEvent(PluginsAddedEvent event)protected voidonEvent(PluginsRemovedEvent event)PluginServicepluginService()Gets the service responsible for discovering and managing this service's plugins.<C extends Command>
Future<CommandModule>run(Class<C> commandClass, boolean process, Object... inputs)Executes the first command of the given class.<C extends Command>
Future<CommandModule>run(Class<C> commandClass, boolean process, Map<String,Object> inputMap)Executes the first command of the given class.Future<CommandModule>run(String className, boolean process, Object... inputs)Executes the first command of the given class name.Future<CommandModule>run(String className, boolean process, Map<String,Object> inputMap)Executes the first command of the given class name.Future<CommandModule>run(CommandInfo info, boolean process, Object... inputs)Executes the given command.Future<CommandModule>run(CommandInfo info, boolean process, Map<String,Object> inputMap)Executes the given command.-
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.command.CommandService
getEventService, getModuleService
-
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.PTService
create, getPlugins, getPluginService
-
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
-
eventService
public EventService eventService()
- Specified by:
eventServicein interfaceCommandService
-
pluginService
public PluginService pluginService()
Description copied from interface:PTServiceGets the service responsible for discovering and managing this service's plugins.- Specified by:
pluginServicein interfacePTService<Command>- Overrides:
pluginServicein classAbstractPTService<Command>
-
moduleService
public ModuleService moduleService()
- Specified by:
moduleServicein interfaceCommandService
-
getCommands
public List<CommandInfo> getCommands()
Description copied from interface:CommandServiceGets the list of all availableCommands).- Specified by:
getCommandsin interfaceCommandService
-
getCommands
public <CT extends Command> List<CommandInfo> getCommands(List<PluginInfo<CT>> plugins)
Description copied from interface:CommandServiceGets the list ofCommands corresponding to the given plugins.- Specified by:
getCommandsin interfaceCommandService
-
getCommandsOfType
public <CT extends Command> List<CommandInfo> getCommandsOfType(Class<CT> type)
Description copied from interface:CommandServiceGets the list ofCommands of the given type.- Specified by:
getCommandsOfTypein interfaceCommandService
-
getCommand
public <C extends Command> CommandInfo getCommand(Class<C> commandClass)
Description copied from interface:CommandServiceGets the first available command of the given class, or null if none.- Specified by:
getCommandin interfaceCommandService
-
getCommand
public CommandInfo getCommand(String className)
Description copied from interface:CommandServiceGets the first available command of the given class name, or null if none.- Specified by:
getCommandin interfaceCommandService
-
getCommandsOfClass
public <C extends Command> List<CommandInfo> getCommandsOfClass(Class<C> commandClass)
Description copied from interface:CommandServiceGets the list of commands of the given class.Most classes will have only a single match, but some special classes (such as ImageJ's
LegacyCommand) may match many entries.NB: Classes are matched by strict equality, not assignability; subtypes of the specified class will not match. For this behavior, use
CommandService.getCommandsOfType(Class)on a common parent interface.- Specified by:
getCommandsOfClassin interfaceCommandService
-
getCommandsOfClass
public List<CommandInfo> getCommandsOfClass(String className)
Description copied from interface:CommandServiceGets the list of commands with the given class name.Most classes will have only a single match, but some special classes (such as ImageJ's
LegacyCommand) may match many entries.NB: Classes are matched by strict equality, not assignability; subtypes of the specified class will not match. For this behavior, use
CommandService.getCommandsOfType(Class)on a common parent interface.- Specified by:
getCommandsOfClassin interfaceCommandService
-
run
public Future<CommandModule> run(String className, boolean process, Object... inputs)
Description copied from interface:CommandServiceExecutes the first command of the given class name.If no command with the given class name is registered with the service, then a default one is created and then executed. This default command is not registered with the service for subsequent usage.
- Specified by:
runin interfaceCommandService- Parameters:
className- Class name of the command to execute.process- If true, executes the command with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the command with no pre- or postprocessing. For more fine-grained control, see theModuleService.run(org.scijava.module.ModuleInfo, boolean, java.lang.Object...)methods.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 plugin, 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<CommandModule> run(String className, boolean process, Map<String,Object> inputMap)
Description copied from interface:CommandServiceExecutes the first command of the given class name.If no command with the given class name is registered with the service, then a default one is created and then executed. This default command is not registered with the service for subsequent usage.
- Specified by:
runin interfaceCommandService- Parameters:
className- Class name of the command to execute.process- If true, executes the command with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the command with no pre- or postprocessing. For more fine-grained control, see theModuleService.run(org.scijava.module.ModuleInfo, boolean, java.lang.Object...)methods.inputMap- Table of input parameter values, with keys matching the plugin'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 <C extends Command> Future<CommandModule> run(Class<C> commandClass, boolean process, Object... inputs)
Description copied from interface:CommandServiceExecutes the first command of the given class.If no command of the given class is registered with the service, then a default one is created and then executed. This default command is not registered with the service for subsequent usage.
- Specified by:
runin interfaceCommandService- Type Parameters:
C- Class of the command to execute.- Parameters:
commandClass- Class object of the command to execute.process- If true, executes the command with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the command with no pre- or postprocessing. For more fine-grained control, see theModuleService.run(org.scijava.module.ModuleInfo, boolean, java.lang.Object...)methods.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 plugin, 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 <C extends Command> Future<CommandModule> run(Class<C> commandClass, boolean process, Map<String,Object> inputMap)
Description copied from interface:CommandServiceExecutes the first command of the given class.If no command of the given class is registered with the service, then a default one is created and then executed. This default command is not registered with the service for subsequent usage.
- Specified by:
runin interfaceCommandService- Type Parameters:
C- Class of the command to execute.- Parameters:
commandClass- Class object of the command to execute.process- If true, executes the command with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the command with no pre- or postprocessing. For more fine-grained control, see theModuleService.run(org.scijava.module.ModuleInfo, boolean, java.lang.Object...)methods.inputMap- Table of input parameter values, with keys matching the plugin'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<CommandModule> run(CommandInfo info, boolean process, Object... inputs)
Description copied from interface:CommandServiceExecutes the given command.- Specified by:
runin interfaceCommandService- Parameters:
info- The command to instantiate and run.process- If true, executes the command with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the command with no pre- or postprocessing. For more fine-grained control, see theModuleService.run(org.scijava.module.ModuleInfo, boolean, java.lang.Object...)methods.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 plugin, 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<CommandModule> run(CommandInfo info, boolean process, Map<String,Object> inputMap)
Description copied from interface:CommandServiceExecutes the given command.- Specified by:
runin interfaceCommandService- Parameters:
info- The command to instantiate and run.process- If true, executes the command with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the command with no pre- or postprocessing. For more fine-grained control, see theModuleService.run(org.scijava.module.ModuleInfo, boolean, java.lang.Object...)methods.inputMap- Table of input parameter values, with keys matching the plugin'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.
-
getPluginType
public Class<Command> getPluginType()
Description copied from interface:PTServiceGets the type of plugins managed by this service.- Specified by:
getPluginTypein interfacePTService<Command>
-
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
-
onEvent
protected void onEvent(PluginsRemovedEvent event)
-
onEvent
protected void onEvent(PluginsAddedEvent event)
-
-