⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobconf.java

📁 hadoop:Nutch集群平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * Copyright 2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.hadoop.mapred;import java.io.IOException;import java.io.File;import java.util.StringTokenizer;import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;import java.net.URL;import java.net.URLDecoder;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.io.Writable;import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.io.WritableComparator;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.io.compress.CompressionCodec;import org.apache.hadoop.mapred.lib.IdentityMapper;import org.apache.hadoop.mapred.lib.IdentityReducer;import org.apache.hadoop.mapred.lib.HashPartitioner;import org.apache.hadoop.util.ReflectionUtils;/** A map/reduce job configuration.  This names the {@link Mapper}, combiner * (if any), {@link Partitioner}, {@link Reducer}, {@link InputFormat}, and * {@link OutputFormat} implementations to be used.  It also indicates the set * of input files, and where the output files should be written. */public class JobConf extends Configuration {  private void initialize() {    addDefaultResource("mapred-default.xml");  }    private void initialize(Class exampleClass) {    initialize();    String jar = findContainingJar(exampleClass);    if (jar != null) {      setJar(jar);    }     }    /**   * Construct a map/reduce job configuration.   */  public JobConf() {    initialize();  }  /**    * Construct a map/reduce job configuration.   * @param conf a Configuration whose settings will be inherited.   * @param exampleClass a class whose containing jar is used as the job's jar.   */  public JobConf(Class exampleClass) {    initialize(exampleClass);  }    /**   * Construct a map/reduce job configuration.   *    * @param conf   *          a Configuration whose settings will be inherited.   */  public JobConf(Configuration conf) {    super(conf);    initialize();  }  /** Construct a map/reduce job configuration.   *    * @param conf a Configuration whose settings will be inherited.   * @param exampleClass a class whose containing jar is used as the job's jar.   */  public JobConf(Configuration conf, Class exampleClass) {    this(conf);    initialize(exampleClass);  }  /** Construct a map/reduce configuration.   *   * @param config a Configuration-format XML job description file   */  public JobConf(String config) {    this(new Path(config));  }  /** Construct a map/reduce configuration.   *   * @param config a Configuration-format XML job description file   */  public JobConf(Path config) {    super();    addDefaultResource("mapred-default.xml");    addDefaultResource(config);  }  public String getJar() { return get("mapred.jar"); }  public void setJar(String jar) { set("mapred.jar", jar); }  public Path getSystemDir() {    return new Path(get("mapred.system.dir", "/tmp/hadoop/mapred/system"));  }  public String[] getLocalDirs() throws IOException {    return getStrings("mapred.local.dir");  }  public void deleteLocalFiles() throws IOException {    String[] localDirs = getLocalDirs();    for (int i = 0; i < localDirs.length; i++) {      FileSystem.getNamed("local", this).delete(new Path(localDirs[i]));    }  }  public void deleteLocalFiles(String subdir) throws IOException {    String[] localDirs = getLocalDirs();    for (int i = 0; i < localDirs.length; i++) {      FileSystem.getNamed("local", this).delete(new Path(localDirs[i], subdir));    }  }  /** @deprecated Call {@link #getLocalPath(String)} instead. */  public File getLocalFile(String subdir, String name) throws IOException {    return new File(getLocalPath(subdir+Path.SEPARATOR+name).toString());  }  /** Constructs a local file name.  Files are distributed among configured   * local directories.*/  public Path getLocalPath(String pathString) throws IOException {    return getLocalPath("mapred.local.dir", pathString);  }  /** @deprecated Call {@link #setInputPath(Path)} instead.*/  public void setInputDir(File dir) { setInputPath(new Path(dir.toString())); }  public void setInputPath(Path dir) {    dir = new Path(getWorkingDirectory(), dir);    set("mapred.input.dir", dir);  }  /** @deprecated Call {@link #addInputPath(Path)} instead.*/  public void addInputDir(File dir) { addInputPath(new Path(dir.toString())); }  public void addInputPath(Path dir) {    dir = new Path(getWorkingDirectory(), dir);    String dirs = get("mapred.input.dir");    set("mapred.input.dir", dirs == null ? dir.toString() : dirs + "," + dir);  }  public Path[] getInputPaths() {    String dirs = get("mapred.input.dir", "");    ArrayList list = Collections.list(new StringTokenizer(dirs, ","));    Path[] result = new Path[list.size()];    for (int i = 0; i < list.size(); i++) {      result[i] = new Path((String)list.get(i));    }    return result;  }  /**   * Get the reported username for this job.   * @return the username   */  public String getUser() {    return get("user.name");  }    /**   * Set the reported username for this job.   * @param user the username   */  public void setUser(String user) {    set("user.name", user);  }    /**   * Set whether the framework should keep the intermediate files for    * failed tasks.   */  public void setKeepFailedTaskFiles(boolean keep) {    setBoolean("keep.failed.task.files", keep);  }    /**   * Should the temporary files for failed tasks be kept?   * @return should the files be kept?   */  public boolean getKeepFailedTaskFiles() {    return getBoolean("keep.failed.task.files", false);  }    /**   * Set a regular expression for task names that should be kept.    * The regular expression ".*_m_000123_0" would keep the files   * for the first instance of map 123 that ran.   * @param pattern the java.util.regex.Pattern to match against the    *        task names.   */  public void setKeepTaskFilesPattern(String pattern) {    set("keep.task.files.pattern", pattern);  }    /**   * Get the regular expression that is matched against the task names   * to see if we need to keep the files.   * @return the pattern as a string, if it was set, othewise null   */  public String getKeepTaskFilesPattern() {    return get("keep.task.files.pattern");  }    /**   * Set the current working directory for the default file system   * @param dir the new current working directory   */  public void setWorkingDirectory(Path dir) {    dir = new Path(getWorkingDirectory(), dir);    set("mapred.working.dir", dir.toString());  }    /**   * Get the current working directory for the default file system.   * @return the directory name   */  public Path getWorkingDirectory() {    String name = get("mapred.working.dir");    if (name != null) {      return new Path(name);    } else {      try {        Path dir = FileSystem.get(this).getWorkingDirectory();        set("mapred.working.dir", dir.toString());        return dir;      } catch (IOException e) {        throw new RuntimeException(e);      }    }  }    /** @deprecated Call {@link #getOutputPath()} instead.*/  public File getOutputDir() { return new File(getOutputPath().toString()); }  public Path getOutputPath() {     String name = get("mapred.output.dir");    return name == null ? null: new Path(name);  }  /** @deprecated Call {@link #setOutputPath(Path)} instead.*/  public void setOutputDir(File dir) {    setOutputPath(new Path(dir.toString()));  }  public void setOutputPath(Path dir) {    dir = new Path(getWorkingDirectory(), dir);    set("mapred.output.dir", dir);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -