Java源码示例:org.apache.hadoop.hive.common.JavaUtils

示例1
/**
 * Returns the hooks specified in a configuration variable.  The hooks are returned in a list in
 * the order they were specified in the configuration variable.
 *
 * @param hookConfVar The configuration variable specifying a comma separated list of the hook
 *                    class names.
 * @return            A list of the hooks, in the order they are listed in the value of hookConfVar
 * @throws Exception
 */
private static <T extends Hook> List<T> getHooks(String csHooks) throws Exception {

  List<T> hooks = new ArrayList<T>();
  if (csHooks.isEmpty()) {
    return hooks;
  }
  for (String hookClass : Splitter.on(",").omitEmptyStrings().trimResults().split(csHooks)) {
    try {
      @SuppressWarnings("unchecked")
      T hook =
          (T) Class.forName(hookClass, true, JavaUtils.getClassLoader()).newInstance();
      hooks.add(hook);
    } catch (ClassNotFoundException e) {
      LOG.error(hookClass + " Class not found:" + e.getMessage());
      throw e;
    }
  }

  return hooks;
}
 
示例2
/**
 * Returns the hooks specified in a configuration variable. The hooks are returned in a list in
 * the order they were specified in the configuration variable.
 *
 * @param hookConfVar The configuration variable specifying a comma separated list of the hook
 *        class names.
 * @param clazz The super type of the hooks.
 * @return A list of the hooks cast as the type specified in clazz, in the order they are listed
 *         in the value of hookConfVar
 * @throws Exception
 */
public static <T extends Hook> List<T> getHooks(String csHooks, Class<T> clazz) throws Exception {

  List<T> hooks = new ArrayList<T>();
  if (csHooks.isEmpty()) {
    return hooks;
  }
  for (String hookClass : Splitter.on(",").omitEmptyStrings().trimResults().split(csHooks)) {
    try {
      @SuppressWarnings("unchecked")
      T hook = (T) Class.forName(hookClass, true, JavaUtils.getClassLoader()).newInstance();
      hooks.add(hook);
    } catch (ClassNotFoundException e) {
      LOG.error(hookClass + " Class not found:" + e.getMessage());
      throw e;
    }
  }

  return hooks;
}
 
示例3
private static void validateEmrFsClass()
{
    // verify that the class exists
    try {
        Class.forName(EMR_FS_CLASS_NAME, true, JavaUtils.getClassLoader());
    }
    catch (ClassNotFoundException e) {
        throw new RuntimeException("EMR File System class not found: " + EMR_FS_CLASS_NAME, e);
    }
}
 
示例4
/**
 * Creates the partition InputFormat.
 *
 * @param inputFormatName input format class name
 * @param jobConf         configuration data for the Hadoop framework
 * @return a {@link org.apache.hadoop.mapred.InputFormat} derived object
 * @throws Exception if failed to create input format
 */
public static InputFormat<?, ?> makeInputFormat(String inputFormatName,
                                                JobConf jobConf)
        throws Exception {
    Class<?> c = Class.forName(inputFormatName, true,
            JavaUtils.getClassLoader());
    InputFormat<?, ?> inputFormat = (InputFormat<?, ?>) c.getDeclaredConstructor().newInstance();

    if ("org.apache.hadoop.mapred.TextInputFormat".equals(inputFormatName)) {
        // TextInputFormat needs a special configuration
        ((TextInputFormat) inputFormat).configure(jobConf);
    }

    return inputFormat;
}