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

The following are Jave code examples for showing how to use getClassByNameOrNull() of the org.apache.hadoop.conf.Configuration class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop-oss   File: ReflectionUtils.java   Source Code and License Vote up 5 votes
/**
 * 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
Project: hadoop   File: ReflectionUtils.java   Source Code and License Vote up 5 votes
/**
 * 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);
  }
}