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 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