大多数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类的用途是什么?
发布评论