wiki:waue/2010/0115-program-drive

程式驅動

import org.apache.hadoop.util.ProgramDriver;

//TsmMenu
//說明: 
//  將之前的功能整合起來
//
//測試方法:
//  將此程式運作在hadoop 0.20 平台上,執行:
//  ---------------------------
//  hadoop jar NCHCMenu.jar <功能>
//  ---------------------------
//
//注意:
//1. 此程式需與之前的範例一起打包成一個TsmMenu.jar檔


public class NCHCMenu {


  public static void main(String argv[]) {
    int exitCode = -1;
    ProgramDriver pgd = new ProgramDriver();
    if (argv.length < 1) {
      System.out.print("******************************************\n"
          + "歡迎使用 NCHC Class 的運算功能 \n" + "指令: \n"
          + "  Hadoop jar TSM-example-*.jar <功能> \n" + "功能:\n"
          + "  HelloHadoop:  秀出Hadoop的<Key,Value>為何 \n"
          + "  HelloHadoopV2:  秀出Hadoop的<Key,Value> 進階版 \n"
          + "  HelloHadoopV3:  秀出Hadoop的<Key,Value> 進化版 \n"
          + "  WordCount:  計算輸入資料夾內分別在每個檔案的字數統計 \n"
          + "  WordCountV2:  WordCount 進階版 \n"
          + "  WordIndex:  索引每個字與其所有出現的所在列 \n"
          + "******************************************\n");
    } else {

      try {
        pgd.addClass("HelloHadoop", HelloHadoop.class, " Hadoop hello world");
        pgd.addClass("HelloHadoopV2", HelloHadoopV2.class, " Hadoop hello world V2");
        pgd.addClass("HelloHadoopV3", HelloHadoopV3.class, " Hadoop hello world V3");
        pgd.addClass("WordCount", WordCount.class, " word count.");
        pgd.addClass("WordCountV2", WordCountV2.class, " word count V2.");
        pgd.addClass("WordIndex", WordIndex.class, "invert each word in line");
        pgd.driver(argv);
        // Success
        exitCode = 0;
        System.exit(exitCode);
      } catch (Throwable e) {
        e.printStackTrace();
      }
    }

  }
}

Last modified 15 years ago Last modified on Apr 28, 2010, 8:59:25 AM