CommandFactory (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.fs.shell, class: CommandFactory

Package org.apache.hadoop.fs.shell

# Class CommandFactory

java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.fs.shell.CommandFactory

All Implemented Interfaces:
  `Configurable`

@Private @Unstable public class CommandFactory extends Configured
class to search for and register commands

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CommandFactory()`
  Factory constructor for commands
  `CommandFactory(Configuration conf)`
  Factory constructor for commands

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addClass(Class<? extends Command> cmdClass, String... names)`
  Register the given class as handling the given list of command names.
  `void`
  `addObject(Command cmdObject, String... names)`
  Register the given object as handling the given list of command names.
  `Command`
  `getInstance(String cmd)`
  Returns an instance of the class implementing the given command.
  `Command`
  `getInstance(String cmdName, Configuration conf)`
  Get an instance of the requested command
  `String[]`
  `getNames()`
  Gets all of the registered commands
  `void`
  `registerCommands(Class<?> registrarClass)`
  Invokes "static void registerCommands(CommandFactory)" on the given class.

  ### Methods inherited from class org.apache.hadoop.conf.Configured

  `getConf, setConf`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CommandFactory

    public CommandFactory()
    Factory constructor for commands

  - ### CommandFactory

    public CommandFactory(Configuration conf)
    Factory constructor for commands
    Parameters:
      `conf` - the hadoop configuration

- ## Method Details

  - ### registerCommands

    public void registerCommands(Class<?> registrarClass)
    Invokes "static void registerCommands(CommandFactory)" on the given class. This method abstracts the contract between the factory and the command class. Do not assume that directly invoking registerCommands on the given class will have the same effect.
    Parameters:
      `registrarClass` - class to allow an opportunity to register

  - ### addClass

    public void addClass(Class<? extends Command> cmdClass, String... names)
    Register the given class as handling the given list of command names.
    Parameters:
      `cmdClass` - the class implementing the command names
      `names` - one or more command names that will invoke this class

  - ### addObject

    public void addObject(Command cmdObject, String... names)
    Register the given object as handling the given list of command names. Avoid calling this method and use `addClass(Class, String...)` whenever possible to avoid startup overhead from excessive command object instantiations. This method is intended only for handling nested non-static classes that are re-usable. Namely -help/-usage.
    Parameters:
      `cmdObject` - the object implementing the command names
      `names` - one or more command names that will invoke this class

  - ### getInstance

    public Command getInstance(String cmd)
    Returns an instance of the class implementing the given command. The class must have been registered via `addClass(Class, String...)`
    Parameters:
      `cmd` - name of the command
    Returns:
      instance of the requested command

  - ### getInstance

    public Command getInstance(String cmdName, Configuration conf)
    Get an instance of the requested command
    Parameters:
      `cmdName` - name of the command to lookup
      `conf` - the hadoop configuration
    Returns:
      the `Command` or null if the command is unknown

  - ### getNames

    public String[] getNames()
    Gets all of the registered commands
    Returns:
      a sorted list of command names