Java Code Examples for org.apache.hadoop.conf.Configuration#getClassByNameOrNull()

The following examples show how to use org.apache.hadoop.conf.Configuration#getClassByNameOrNull() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   File: ReflectionUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This code is to support backward compatibility and break the compile  
 * time dependency of core on mapred.
 * This should be made deprecated along with the mapred package HADOOP-1230. 
 * Should be removed when mapred package is removed.
 */
private static void setJobConf(Object theObject, Configuration conf) {
  //If JobConf and JobConfigurable are in classpath, AND
  //theObject is of type JobConfigurable AND
  //conf is of type JobConf then
  //invoke configure on theObject
  try {
    Class<?> jobConfClass = 
      conf.getClassByNameOrNull("org.apache.hadoop.mapred.JobConf");
    if (jobConfClass == null) {
      return;
    }
    
    Class<?> jobConfigurableClass = 
      conf.getClassByNameOrNull("org.apache.hadoop.mapred.JobConfigurable");
    if (jobConfigurableClass == null) {
      return;
    }
    if (jobConfClass.isAssignableFrom(conf.getClass()) &&
          jobConfigurableClass.isAssignableFrom(theObject.getClass())) {
      Method configureMethod = 
        jobConfigurableClass.getMethod("configure", jobConfClass);
      configureMethod.invoke(theObject, conf);
    }
  } catch (Exception e) {
    throw new RuntimeException("Error in configuring object", e);
  }
}
 
Example 2
Source Project: big-c   File: ReflectionUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This code is to support backward compatibility and break the compile  
 * time dependency of core on mapred.
 * This should be made deprecated along with the mapred package HADOOP-1230. 
 * Should be removed when mapred package is removed.
 */
private static void setJobConf(Object theObject, Configuration conf) {
  //If JobConf and JobConfigurable are in classpath, AND
  //theObject is of type JobConfigurable AND
  //conf is of type JobConf then
  //invoke configure on theObject
  try {
    Class<?> jobConfClass = 
      conf.getClassByNameOrNull("org.apache.hadoop.mapred.JobConf");
    if (jobConfClass == null) {
      return;
    }
    
    Class<?> jobConfigurableClass = 
      conf.getClassByNameOrNull("org.apache.hadoop.mapred.JobConfigurable");
    if (jobConfigurableClass == null) {
      return;
    }
    if (jobConfClass.isAssignableFrom(conf.getClass()) &&
          jobConfigurableClass.isAssignableFrom(theObject.getClass())) {
      Method configureMethod = 
        jobConfigurableClass.getMethod("configure", jobConfClass);
      configureMethod.invoke(theObject, conf);
    }
  } catch (Exception e) {
    throw new RuntimeException("Error in configuring object", e);
  }
}