Hadoop程序中Configured类的用途是什么? [英] What is the usage of Configured class in Hadoop programs?
问题描述
大多数Hadoop MapReduce程序如下:
Most of Hadoop MapReduce programs are like this:
public class MyApp extends Configured Implements Tool {
@Override
public int run(String[] args) throws Exception {
Job job = new Job(getConf());
/* process command line options */
return job.waitForCompletion(true) ? 0 : 1;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new MyApp(), args);
System.exit(exitCode);
}
}
Configured
的用途是什么?由于Tool
和Configured
都具有getConf()
和setConf()
的共同点.它为我们的应用程序提供了什么?
What is the usage of Configured
? As Tool
and Configured
both have getConf()
and setConf()
in common. What does it provide to our application?
推荐答案
Configured
是接口Configurable
的实现类. Configured
是具有getConf()
和setConf()
的实现的基类.
Configured
is an implementation class of the interface Configurable
. Configured
is the base class which has the implementations of getConf()
and setConf()
.
仅扩展此基类,即可使用Configuration
配置扩展此基类的类,并且Configuration
有多个实现.
Merely extending this base class enables the class that extends this to be configured using a Configuration
and there are more than one implementations for Configuration
.
您的代码执行以下行时,
When your code executes the following line,
ToolRunner.run(new MyApp(), args);
内部将执行此操作
ToolRunner.run(tool.getConf(), tool, args);
在上述情况下,tool
是MyApp
类实例,它是Tool
的实现,正如您所说的具有getConf()
,但它只是作为接口.该实现来自Configured
基类.如果您避免在上述代码中扩展Configured
类,则必须自己执行getConf()
和setConf()
实现.
In the above case tool
is the MyApp
class instance which is an implementation of Tool
which just as you said has getConf()
but it is just as an interface. The implementation is coming from Configured
base class. If you avoid extending Configured
class in the above code, then you will have to do the getConf()
and setConf()
implementations on your own.
这篇关于Hadoop程序中Configured类的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!