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

The following are Jave code examples for showing how to use getClassLoader() 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.
+ Save this method
Example 1
Project: hadoop   File: MRAppMaster.java   View Source Code Vote up 6 votes
/**
 * Executes the given action with the job classloader set as the configuration
 * classloader as well as the thread context class loader if the job
 * classloader is enabled. After the call, the original classloader is
 * restored.
 *
 * If the job classloader is enabled and the code needs to load user-supplied
 * classes via configuration or thread context classloader, this method should
 * be used in order to load them.
 *
 * @param conf the configuration on which the classloader will be set
 * @param action the callable action to be executed
 */
<T> T callWithJobClassLoader(Configuration conf, Action<T> action) {
  // if the job classloader is enabled, we may need it to load the (custom)
  // classes; we make the job classloader available and unset it once it is
  // done
  ClassLoader currentClassLoader = conf.getClassLoader();
  boolean setJobClassLoader =
      jobClassLoader != null && currentClassLoader != jobClassLoader;
  if (setJobClassLoader) {
    MRApps.setClassLoader(jobClassLoader, conf);
  }
  try {
    return action.call(conf);
  } finally {
    if (setJobClassLoader) {
      // restore the original classloader
      MRApps.setClassLoader(currentClassLoader, conf);
    }
  }
}