ConfigurableFsCommand@Private @Evolving public abstract class Command extends Configured
| Modifier and Type | Field | Description |
|---|---|---|
protected java.lang.String[] |
args |
|
static java.lang.String |
COMMAND_DESCRIPTION_FIELD |
field name indicating the command's long description
|
static java.lang.String |
COMMAND_NAME_FIELD |
field name indicating the default name of the command
|
static java.lang.String |
COMMAND_USAGE_FIELD |
field name indicating the command's usage switches and arguments format
|
java.io.PrintStream |
err |
allows stderr to be captured if necessary
|
protected java.util.ArrayList<java.lang.Exception> |
exceptions |
|
protected int |
exitCode |
|
protected java.lang.String |
name |
|
protected int |
numErrors |
|
java.io.PrintStream |
out |
allows stdout to be captured if necessary
|
protected boolean |
recursive |
| Modifier | Constructor | Description |
|---|---|---|
protected |
Command() |
Constructor
|
protected |
Command(Configuration conf) |
Constructor.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
displayError(java.lang.Exception e) |
Display an exception prefaced with the command name.
|
void |
displayError(java.lang.String message) |
Display an error string prefaced with the command name.
|
void |
displayWarning(java.lang.String message) |
Display an warning string prefaced with the command name.
|
protected int |
exitCodeForError() |
The exit code to be returned if any errors occur during execution.
|
protected java.util.List<PathData> |
expandArgument(java.lang.String arg) |
Expand the given argument into a list of
PathData objects. |
protected java.util.LinkedList<PathData> |
expandArguments(java.util.LinkedList<java.lang.String> args) |
Expands a list of arguments into
PathData objects. |
protected CommandFactory |
getCommandFactory() |
retrieves the command factory.
|
abstract java.lang.String |
getCommandName() |
|
protected int |
getDepth() |
|
java.lang.String |
getDescription() |
The long usage suitable for help output
|
protected int |
getListingGroupSize() |
While using iterator method for listing for a path, whether to group items
and process as array? If so what is the size of array?
|
java.lang.String |
getName() |
The name of the command.
|
java.lang.String |
getReplacementCommand() |
The replacement for a deprecated command
|
java.lang.String |
getUsage() |
The short usage suitable for the synopsis
|
boolean |
isDeprecated() |
Is the command deprecated?
|
protected boolean |
isPathRecursable(PathData item) |
Determines whether a
PathData item is recursable. |
protected boolean |
isRecursive() |
|
protected boolean |
isSorted() |
Whether the directory listing for a path should be sorted.?
|
protected void |
postProcessPath(PathData item) |
Hook for commands to implement an operation to be applied on each
path for the command after being processed successfully
|
protected void |
processArgument(PathData item) |
Processes a
PathData item, calling
processPathArgument(PathData) or
processNonexistentPath(PathData) on each item. |
protected void |
processArguments(java.util.LinkedList<PathData> args) |
Processes the command's list of expanded arguments.
|
protected void |
processNonexistentPath(PathData item) |
Provides a hook for handling paths that don't exist.
|
protected void |
processOptions(java.util.LinkedList<java.lang.String> args) |
Must be implemented by commands to process the command line flags and
check the bounds of the remaining arguments.
|
protected void |
processPath(PathData item) |
Hook for commands to implement an operation to be applied on each
path for the command.
|
protected void |
processPathArgument(PathData item) |
This is the last chance to modify an argument before going into the
(possibly) recursive
processPaths(PathData, PathData...)
-> processPath(PathData) loop. |
protected void |
processPaths(PathData parent,
RemoteIterator<PathData> itemsIterator) |
Iterates over the given expanded paths and invokes
processPath(PathData) on each element. |
protected void |
processPaths(PathData parent,
PathData... items) |
Iterates over the given expanded paths and invokes
processPath(PathData) on each element. |
protected void |
processRawArguments(java.util.LinkedList<java.lang.String> args) |
Allows commands that don't use paths to handle the raw arguments.
|
protected void |
recursePath(PathData item) |
Gets the directory listing for a path and invokes
processPaths(PathData, PathData...) |
int |
run(java.lang.String... argv) |
Invokes the command handler.
|
protected abstract void |
run(Path path) |
Execute the command on the input path
|
protected void |
run(PathData pathData) |
Execute the command on the input path data.
|
int |
runAll() |
For each source path, execute the command
|
void |
setCommandFactory(CommandFactory factory) |
sets the command factory for later use.
|
void |
setName(java.lang.String name) |
Define the name of the command.
|
protected void |
setRecursive(boolean flag) |
getConf, setConfpublic static final java.lang.String COMMAND_NAME_FIELD
public static final java.lang.String COMMAND_USAGE_FIELD
public static final java.lang.String COMMAND_DESCRIPTION_FIELD
protected java.lang.String[] args
protected java.lang.String name
protected int exitCode
protected int numErrors
protected boolean recursive
protected java.util.ArrayList<java.lang.Exception> exceptions
public java.io.PrintStream out
public java.io.PrintStream err
protected Command()
protected Command(Configuration conf)
conf - configuration.public abstract java.lang.String getCommandName()
protected void setRecursive(boolean flag)
protected boolean isRecursive()
protected int getDepth()
protected abstract void run(Path path) throws java.io.IOException
path - the input pathjava.io.IOException - if any error occursprotected void run(PathData pathData) throws java.io.IOException
pathData - The input path with resolved filesystemjava.io.IOException - raised on errors performing I/O.public int runAll()
public void setCommandFactory(CommandFactory factory)
factory - factory.protected CommandFactory getCommandFactory()
public int run(java.lang.String... argv)
run |->Most commands will chose to implement justprocessOptions(LinkedList)\->processRawArguments(LinkedList)|->expandArguments(LinkedList)| \->expandArgument(String)* \->processArguments(LinkedList)|->processArgument(PathData)* | |->processPathArgument(PathData)| \->processPaths(PathData, PathData...)| \->processPath(PathData)* \->processNonexistentPath(PathData)
processOptions(LinkedList) and processPath(PathData)argv - the list of command line argumentsjava.lang.IllegalArgumentException - if called with invalid argumentsprotected int exitCodeForError()
protected void processOptions(java.util.LinkedList<java.lang.String> args)
throws java.io.IOException
args - the command line argumentsjava.io.IOException - raised on errors performing I/O.protected void processRawArguments(java.util.LinkedList<java.lang.String> args)
throws java.io.IOException
expandArguments(LinkedList) and pass the resulting list to
processArguments(LinkedList)args - the list of argument stringsjava.io.IOException - raised on errors performing I/O.protected java.util.LinkedList<PathData> expandArguments(java.util.LinkedList<java.lang.String> args) throws java.io.IOException
PathData objects. The default
behavior is to call expandArgument(String) on each element
which by default globs the argument. The loop catches IOExceptions,
increments the error count, and displays the exception.protected java.util.List<PathData> expandArgument(java.lang.String arg) throws java.io.IOException
PathData objects.
The default behavior is to expand globs. Commands may override to
perform other expansions on an argument.arg - string pattern to expandPathData objectsjava.io.IOException - if anything goes wrong...protected void processArguments(java.util.LinkedList<PathData> args) throws java.io.IOException
processArgument(PathData) will be invoked with each item
in the list. The loop catches IOExceptions, increments the error
count, and displays the exception.args - a list of PathData to processjava.io.IOException - if anything goes wrong...protected void processArgument(PathData item) throws java.io.IOException
PathData item, calling
processPathArgument(PathData) or
processNonexistentPath(PathData) on each item.item - PathData item to processjava.io.IOException - if anything goes wrong...protected void processPathArgument(PathData item) throws java.io.IOException
processPaths(PathData, PathData...)
-> processPath(PathData) loop. Ex. ls and du use
this to expand out directories.item - a PathData representing a path which existsjava.io.IOException - if anything goes wrong...protected void processNonexistentPath(PathData item) throws java.io.IOException
item - the PathData that doesn't existjava.io.FileNotFoundException - if arg is a path and it doesn't existjava.io.IOException - if anything else goes wrong...protected void processPaths(PathData parent, PathData... items) throws java.io.IOException
processPath(PathData) on each element. If "recursive" is true,
will do a post-visit DFS on directories.parent - if called via a recurse, will be the parent dir, else nullitems - a list of PathData objects to processjava.io.IOException - if anything goes wrong...protected void processPaths(PathData parent, RemoteIterator<PathData> itemsIterator) throws java.io.IOException
processPath(PathData) on each element. If "recursive" is true,
will do a post-visit DFS on directories.parent - if called via a recurse, will be the parent dir, else nullitemsIterator - a iterator of PathData objects to processjava.io.IOException - if anything goes wrong...protected boolean isSorted()
protected int getListingGroupSize()
protected boolean isPathRecursable(PathData item) throws java.io.IOException
PathData item is recursable. Default
implementation is to recurse directories but can be overridden to recurse
through symbolic links.item - a PathData objectjava.io.IOException - if anything goes wrong in the user-implementationprotected void processPath(PathData item) throws java.io.IOException
item - a PathData objectjava.lang.RuntimeException - if invoked but not implementedjava.io.IOException - if anything else goes wrong in the user-implementationprotected void postProcessPath(PathData item) throws java.io.IOException
item - a PathData objectjava.io.IOException - if anything goes wrong...protected void recursePath(PathData item) throws java.io.IOException
processPaths(PathData, PathData...)item - PathData for directory to recurse intojava.io.IOException - if anything goes wrong...public void displayError(java.lang.Exception e)
e - exception to displaypublic void displayError(java.lang.String message)
message - error message to displaypublic void displayWarning(java.lang.String message)
message - warning message to displaypublic java.lang.String getName()
public void setName(java.lang.String name)
name - as invokedpublic java.lang.String getUsage()
public java.lang.String getDescription()
public final boolean isDeprecated()
public java.lang.String getReplacementCommand()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.