Package mgui.command
Class CommandInstance
java.lang.Object
mgui.command.CommandInterpreter
mgui.command.CommandInstance
- Direct Known Subclasses:
DataSourceCommands
public abstract class CommandInstance extends CommandInterpreter
Class which handles command-line arguments and calls specific methods
as implemented by a sub-class.
Parameters are handled as pairs (parameter name preceded by a dash and followed by a value) or as flags (single flag parameter preceded by a dash).
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.HashMap<java.lang.Long,JavaProcess>
current_processes
protected LoggingType
default_logging_type
protected boolean
exit_on_termination
protected long
instance_timer
protected boolean
is_interrupted
protected java.io.BufferedWriter
log_out
protected java.util.HashMap<java.lang.String,java.lang.String>
parameters
Fields inherited from class mgui.command.CommandInterpreter
clock_start, elapsed, instance_clock_start, instance_state, success_status
-
Constructor Summary
Constructors Constructor Description CommandInstance()
-
Method Summary
Modifier and Type Method Description CommandFunctions.ProcessState
execute(java.lang.String[] args)
Executes a process, similar tomain
, but runs as an instance, and returns the elapsed time in milliseconds.protected java.lang.String
getCommandLine(java.lang.String[] args)
Converts an array of parameters to a single space-delimited line.boolean
interrupt()
Requests that the currently executing process terminateprotected boolean
load_parameter_file(java.lang.String file)
Loads a parameter file and populatesparameters
with it.protected void
log(java.lang.String message)
protected void
log(java.lang.String message, LoggingType type)
protected boolean
output_help(java.net.URL resource)
Reads and outputs a help file from the given URLprotected abstract boolean
run_command(java.lang.String command)
Runs a single command with the current parameters.protected void
setSuccessStatus(boolean status)
protected boolean
start_log(java.lang.String file)
protected boolean
stop_log()
Methods inherited from class mgui.command.CommandInterpreter
getInstanceTimer, getParameters, getSuccessStatus, getTimer, isNumeric, startInstanceTimer, startTimer, stopInstanceTimer
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
instance_timer
protected long instance_timer -
parameters
protected java.util.HashMap<java.lang.String,java.lang.String> parameters -
log_out
protected java.io.BufferedWriter log_out -
default_logging_type
-
current_processes
-
is_interrupted
protected boolean is_interrupted -
exit_on_termination
protected boolean exit_on_termination
-
-
Constructor Details
-
CommandInstance
public CommandInstance()
-
-
Method Details
-
interrupt
public boolean interrupt()Requests that the currently executing process terminate- Returns:
-
execute
Description copied from class:CommandInterpreter
Executes a process, similar tomain
, but runs as an instance, and returns the elapsed time in milliseconds.- Overrides:
execute
in classCommandInterpreter
- Returns:
- Throws:
java.lang.Exception
-
setSuccessStatus
protected void setSuccessStatus(boolean status)- Overrides:
setSuccessStatus
in classCommandInterpreter
-
getCommandLine
protected java.lang.String getCommandLine(java.lang.String[] args)Converts an array of parameters to a single space-delimited line.- Parameters:
args
-- Returns:
-
start_log
protected boolean start_log(java.lang.String file) -
stop_log
protected boolean stop_log() -
log
protected void log(java.lang.String message) -
log
-
load_parameter_file
protected boolean load_parameter_file(java.lang.String file)Loads a parameter file and populatesparameters
with it. Returnstrue
if successful. File must be of the form [parameter_name]\t[parameter_value].- Parameters:
file
-- Returns:
-
run_command
protected abstract boolean run_command(java.lang.String command)Runs a single command with the current parameters.- Parameters:
command
-
-
output_help
protected boolean output_help(java.net.URL resource)Reads and outputs a help file from the given URL- Parameters:
resource
-- Returns:
-