
public abstract class AbstractCommand extends Object implements Command
Command implementation.Command.ListenerSTATUS_FAILURE, STATUS_SUCCESS| Constructor and Description |
|---|
AbstractCommand()
Creates a new
AbstractCommand instance. |
| Modifier and Type | Method and Description |
|---|---|
int |
execute(CommandLine commandLine)
Executes the command.
|
protected abstract void |
executeCommand(CommandLine commandLine)
Called by the
execute method prior to the postExecuteCommand method. |
static Level |
getDefaultLogLevel()
Gets the default log level events are logged at.
|
protected ExecutorService |
getExecutorService(CommandLine commandLine)
Gets the
ExecutorService used to run tasks in parallel. |
List<Command.Listener> |
getListeners()
Gets the list of registered listeners.
|
Level |
getLogLevel()
Gets the log level of the instance.
|
Options |
getOptions()
Gets the options of the command.
|
protected boolean |
isLoggable(Level level)
Checks if a message at a given level is provided to the listeners of the instance.
|
protected void |
log(Level level,
String message,
Throwable throwable)
Notifies registered listeners.
|
protected void |
postExecuteCommand(CommandLine commandLine)
Called by the
execute method after the preExecuteCommand/executeCommand methods even if
those methods threw an exception. |
protected void |
preExecuteCommand(CommandLine commandLine)
Called by the
execute method prior to the executeCommand method. |
static void |
setDefaultLogLevel(Level value)
Sets the default log level events are logged at.
|
void |
setLogLevel(Level value)
Sets the log level of the instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAbbreviatedName, getLongDescription, getName, getShortDescriptionpublic AbstractCommand()
AbstractCommand instance.public static Level getDefaultLogLevel()
The default log level is controlled by system property
org.jomc.cli.commands.AbstractCommand.defaultLogLevel holding the log level to log events at by
default. If that property is not set, the WARNING default is returned.
getLogLevel(),
Level.parse(java.lang.String)public static void setDefaultLogLevel(Level value)
value - The new default level events are logged at or null.getDefaultLogLevel()public final Level getLogLevel()
getLogLevel in interface CommandgetDefaultLogLevel(),
setLogLevel(java.util.logging.Level),
isLoggable(java.util.logging.Level)public final void setLogLevel(Level value)
setLogLevel in interface Commandvalue - The new log level of the instance or null.getLogLevel(),
isLoggable(java.util.logging.Level)public final List<Command.Listener> getListeners()
This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
to the returned list will be present inside the object. This is why there is no set method for the
listeners property.
getListeners in interface Commandlog(java.util.logging.Level, java.lang.String, java.lang.Throwable)protected boolean isLoggable(Level level)
level - The level to test.true, if messages at level are provided to the listeners of the instance;
false, if messages at level are not provided to the listeners of the instance.NullPointerException - if level is null.getLogLevel(),
setLogLevel(java.util.logging.Level)protected void log(Level level, String message, Throwable throwable)
level - The level of the event.message - The message of the event or null.throwable - The throwable of the event null.NullPointerException - if level is null.getListeners(),
isLoggable(java.util.logging.Level)public Options getOptions()
CommandgetOptions in interface Commandprotected final ExecutorService getExecutorService(CommandLine commandLine)
ExecutorService used to run tasks in parallel.commandLine - The CommandLine to use for setting up an executor service when not already created.ExecutorService used to run tasks in parallel or null.public final int execute(CommandLine commandLine)
Commandexecute in interface CommandcommandLine - Command line to execute.Command.STATUS_SUCCESS,
Command.STATUS_FAILUREprotected void preExecuteCommand(CommandLine commandLine) throws CommandExecutionException
execute method prior to the executeCommand method.commandLine - The command line to execute.NullPointerException - if commandLine is null.CommandExecutionException - if executing the command fails.execute(org.apache.commons.cli.CommandLine)protected abstract void executeCommand(CommandLine commandLine) throws CommandExecutionException
execute method prior to the postExecuteCommand method.commandLine - The command line to execute.CommandExecutionException - if executing the command fails.execute(org.apache.commons.cli.CommandLine)protected void postExecuteCommand(CommandLine commandLine) throws CommandExecutionException
execute method after the preExecuteCommand/executeCommand methods even if
those methods threw an exception.commandLine - The command line to execute.NullPointerException - if commandLine is null.CommandExecutionException - if executing the command fails.execute(org.apache.commons.cli.CommandLine)Copyright © 2005–2016 The JOMC Project. All rights reserved.