Hadoop程序中Configured类的用途是什么? [英] What is the usage of Configured class in Hadoop programs?

查看:100
本文介绍了Hadoop程序中Configured类的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数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的用途是什么?由于ToolConfigured都具有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);

在上述情况下,toolMyApp类实例,它是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆