首先,Context是一个内部类,从哪看出来的呢?如下

public class Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {/*** The <code>Context</code> passed on to the {@link Mapper} implementations.*/public abstract class Contextimplements MapContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT> {}}

内部类有啥好处呢?也就是Mapper类的参数那么Context可以很方便的访问到.

Context类实现了MapContext接口.
看一下.有一个获取分片的方法.至于context怎么来的,还需要继续溯源

public interface MapContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT> extends TaskInputOutputContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT> {/*** Get the input split for this map.*/public InputSplit getInputSplit();}

获取是否有下一个键值对,以及当前键值对.还有写入方法在这里定义了,就是把k2,v2写出去.写到哪里呢?

public interface TaskInputOutputContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT> extends TaskAttemptContext {/*** Advance to the next key, value pair, returning null if at end.* @return the key object that was read into, or null if no more*/public boolean nextKeyValue() throws IOException, InterruptedException;/*** Get the current key.* @return the current key object or null if there isn't one* @throws IOException* @throws InterruptedException*/public KEYIN getCurrentKey() throws IOException, InterruptedException;/*** Get the current value.* @return the value object that was read into* @throws IOException* @throws InterruptedException*/public VALUEIN getCurrentValue() throws IOException, InterruptedException;/*** Generate an output key/value pair.*/public void write(KEYOUT key, VALUEOUT value) throws IOException, InterruptedException;/*** Get the {@link OutputCommitter} for the task-attempt.* @return the <code>OutputCommitter</code> for the task-attempt*/public OutputCommitter getOutputCommitter();
}

继续溯源.TaskInputOutputContext又继承了TaskAttemptContext接口,这个接口中包含一些job信息.

public interface TaskAttemptContext extends JobContext, Progressable {/*** Get the unique name for this task attempt.*/public TaskAttemptID getTaskAttemptID();/*** Set the current status of the task to the given string.*/public void setStatus(String msg);/*** Get the last set status message.* @return the current status message*/public String getStatus();/*** The current progress of the task attempt.* @return a number between 0.0 and 1.0 (inclusive) indicating the attempt's* progress.*/public abstract float getProgress();/*** Get the {@link Counter} for the given <code>counterName</code>.* @param counterName counter name* @return the <code>Counter</code> for the given <code>counterName</code>*/public Counter getCounter(Enum<?> counterName);/*** Get the {@link Counter} for the given <code>groupName</code> and * <code>counterName</code>.* @param counterName counter name* @return the <code>Counter</code> for the given <code>groupName</code> and *         <code>counterName</code>*/public Counter getCounter(String groupName, String counterName);}

继续溯源

public interface JobContext extends MRJobConfig {/*** Return the configuration for the job.* @return the shared configuration object*/public Configuration getConfiguration();/*** Get credentials for the job.* @return credentials for the job*/public Credentials getCredentials();/*** Get the unique ID for the job.* @return the object with the job id*/public JobID getJobID();/*** Get configured the number of reduce tasks for this job. Defaults to * <code>1</code>.* @return the number of reduce tasks for this job.*/public int getNumReduceTasks();/*** Get the current working directory for the default file system.* * @return the directory name.*/public Path getWorkingDirectory() throws IOException;/*** Get the key class for the job output data.* @return the key class for the job output data.*/public Class<?> getOutputKeyClass();/*** Get the value class for job outputs.* @return the value class for job outputs.*/public Class<?> getOutputValueClass();/*** Get the key class for the map output data. If it is not set, use the* (final) output key class. This allows the map output key class to be* different than the final output key class.* @return the map output key class.*/public Class<?> getMapOutputKeyClass();/*** Get the value class for the map output data. If it is not set, use the* (final) output value class This allows the map output value class to be* different than the final output value class.*  * @return the map output value class.*/public Class<?> getMapOutputValueClass();/*** Get the user-specified job name. This is only used to identify the * job to the user.* * @return the job's name, defaulting to "".*/public String getJobName();/*** Get the {@link InputFormat} class for the job.* * @return the {@link InputFormat} class for the job.*/public Class<? extends InputFormat<?,?>> getInputFormatClass() throws ClassNotFoundException;/*** Get the {@link Mapper} class for the job.* * @return the {@link Mapper} class for the job.*/public Class<? extends Mapper<?,?,?,?>> getMapperClass() throws ClassNotFoundException;/*** Get the combiner class for the job.* * @return the combiner class for the job.*/public Class<? extends Reducer<?,?,?,?>> getCombinerClass() throws ClassNotFoundException;/*** Get the {@link Reducer} class for the job.* * @return the {@link Reducer} class for the job.*/public Class<? extends Reducer<?,?,?,?>> getReducerClass() throws ClassNotFoundException;/*** Get the {@link OutputFormat} class for the job.* * @return the {@link OutputFormat} class for the job.*/public Class<? extends OutputFormat<?,?>> getOutputFormatClass() throws ClassNotFoundException;/*** Get the {@link Partitioner} class for the job.* * @return the {@link Partitioner} class for the job.*/public Class<? extends Partitioner<?,?>> getPartitionerClass() throws ClassNotFoundException;/*** Get the {@link RawComparator} comparator used to compare keys.* * @return the {@link RawComparator} comparator used to compare keys.*/public RawComparator<?> getSortComparator();/*** Get the pathname of the job's jar.* @return the pathname*/public String getJar();/*** Get the user defined {@link RawComparator} comparator for* grouping keys of inputs to the combiner.** @return comparator set by the user for grouping values.* @see Job#setCombinerKeyGroupingComparatorClass(Class)*/public RawComparator<?> getCombinerKeyGroupingComparator();/*** Get the user defined {@link RawComparator} comparator for* grouping keys of inputs to the reduce.** @return comparator set by the user for grouping values.* @see Job#setGroupingComparatorClass(Class)* @see #getCombinerKeyGroupingComparator()*/public RawComparator<?> getGroupingComparator();/*** Get whether job-setup and job-cleanup is needed for the job * * @return boolean */public boolean getJobSetupCleanupNeeded();/*** Get whether task-cleanup is needed for the job * * @return boolean */public boolean getTaskCleanupNeeded();/*** Get whether the task profiling is enabled.* @return true if some tasks will be profiled*/public boolean getProfileEnabled();/*** Get the profiler configuration arguments.** The default value for this property is* "-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,verbose=n,file=%s"* * @return the parameters to pass to the task child to configure profiling*/public String getProfileParams();/*** Get the range of maps or reduces to profile.* @param isMap is the task a map?* @return the task ranges*/public IntegerRanges getProfileTaskRange(boolean isMap);/*** Get the reported username for this job.* * @return the username*/public String getUser();/*** Originally intended to check if symlinks should be used, but currently* symlinks cannot be disabled.* @return true*/@Deprecatedpublic boolean getSymlink();/*** Get the archive entries in classpath as an array of Path*/public Path[] getArchiveClassPaths();/*** Get cache archives set in the Configuration* @return A URI array of the caches set in the Configuration* @throws IOException*/public URI[] getCacheArchives() throws IOException;/*** Get cache files set in the Configuration* @return A URI array of the files set in the Configuration* @throws IOException*/public URI[] getCacheFiles() throws IOException;/*** Return the path array of the localized caches* @return A path array of localized caches* @throws IOException* @deprecated the array returned only includes the items the were * downloaded. There is no way to map this to what is returned by* {@link #getCacheArchives()}.*/@Deprecatedpublic Path[] getLocalCacheArchives() throws IOException;/*** Return the path array of the localized files* @return A path array of localized files* @throws IOException* @deprecated the array returned only includes the items the were * downloaded. There is no way to map this to what is returned by* {@link #getCacheFiles()}.*/@Deprecatedpublic Path[] getLocalCacheFiles() throws IOException;/*** Get the file entries in classpath as an array of Path*/public Path[] getFileClassPaths();/*** Get the timestamps of the archives.  Used by internal* DistributedCache and MapReduce code.* @return a string array of timestamps */public String[] getArchiveTimestamps();/*** Get the timestamps of the files.  Used by internal* DistributedCache and MapReduce code.* @return a string array of timestamps */public String[] getFileTimestamps();/** * Get the configured number of maximum attempts that will be made to run a* map task, as specified by the <code>mapred.map.max.attempts</code>* property. If this property is not already set, the default is 4 attempts.*  * @return the max number of attempts per map task.*/public int getMaxMapAttempts();/** * Get the configured number of maximum attempts  that will be made to run a* reduce task, as specified by the <code>mapred.reduce.max.attempts</code>* property. If this property is not already set, the default is 4 attempts.* * @return the max number of attempts per reduce task.*/public int getMaxReduceAttempts();}

总结一下,就是

  • context是一个Mapper的内部类
  • context可以获取一些Job相关的信息.

java Context类相关推荐

  1. hadoop开发必读:认识Context类的作用

    问题导读: 1.Context能干什么? 2.你对Context类了解多少? 3.Context在mapreduce中的作用是什么? 本文实在能够阅读源码的基础上一个继续,如果你还不能阅读源码,请参考 ...

  2. Hadoop中Context类的作用和Mapper<LongWritable, Text, Text, LongWritable>.Context context是怎么回事【笔记自用】

    问题导读: 1.Context能干什么? 2.你对Context类了解多少? 3.Context在mapreduce中的作用是什么? 下面我们通过来源码,来得到Context的作用: 下面主要对Set ...

  3. Hadoop中Context类的作用

    问题导读: 1.Context能干什么? 2.你对Context类了解多少? 3.Context在mapreduce中的作用是什么? 下面我们通过来源码,来得到Context的作用: 下面主要对Set ...

  4. java spring配置类_spring 配置 Java配置类装配bean

    https://www.cnblogs.com/chenbenbuyi/p/8457700.html 自动化装配的确有很大的便利性,但是却并不能适用在所有的应用场景,比如需要装配的组件类不是由自己的应 ...

  5. 【Spring第七篇】Java配置类:JavaConfig

    Java配置类:JavaConfig 在spring配置中 applicationContext.xml <?xml version="1.0" encoding=" ...

  6. java配置ssm_不用xml 配置文件,纯粹使用java配置类搭建SSM项目

    随着spring版本迭代更新,现在越来越倡导不使用复杂繁琐的配置文件来配置项目,下面介绍纯粹使用java 配置类来配置spring.springmvc.mybatis: 环境:java 8 + mav ...

  7. 使用JAVA工具类进行邮件发送

    使用JAVA工具类进行邮件发送 使用JAVA工具类进行邮件发送 文章目录 使用JAVA工具类进行邮件发送 前言 一.前期准备工作 二.使用步骤 1.引入依赖 2.进行发送邮件 前言 提示:我们在开发过 ...

  8. 【从0到1打造代码生成器】生成Java实体类

    代码生成器是指通过机器来生成各种类型的代码,其应用十分广泛,并且能够极大的提高开发效率.本文将介绍如何利用Velocity模板技术生成一个Java实体类. 问题 Velocity是 JavaEE企业级 ...

  9. java字符存储_用java的类集框架做一个字符存储器(15)

    11.这是java的关于java的类集框架做一个字符存储器的源代码可以直接进行编译运行,希望大家能够从中获益良多. package niming; //导入ArrayList这个类 import ja ...

最新文章

  1. JavaScript夯实基础系列(一):词法作用域
  2. 第八篇——Struts2的处理结果类型
  3. scrapy模拟登录微博
  4. jdbc c3p0 mysql_JDBC+C3P0+DBCP 基本使用
  5. 电阻电容封装用错该怎么办
  6. Android 分贝测试仪功能,华为移动终端开发
  7. 中国知网论文free下载的方法
  8. 计算机调用计算器快捷键,Windows系统打开计算器的快捷键 计算器快捷键大全
  9. 计算机网络教学改革方案,三教改革下的计算机网络专业教学改革
  10. 织梦CMS模板安装教程详细图文
  11. 科学计算法(机器学习)----决策树定义以相关概念
  12. 玩转星际争霸局部战斗 —— QMIX
  13. 微信 3.6.0 正式版来了,上班族狂喜!
  14. 安装win和xp双系统 若干问题
  15. nmap学习之路--测试版
  16. 简单实现直播手绘礼物
  17. Geant4学习记录(一)
  18. 2015计算机一级试题及答案,2015年计算机一级考试选择试题及答案
  19. 2021年化工自动化控制仪表考试试卷及化工自动化控制仪表模拟考试题库
  20. GASSHOW:野田洋次郎为东日本大地震丧生的罹难者所创的镇魂曲。

热门文章

  1. matlab 求极小值 一维优化,MATLABoptimization
  2. studioone唱歌效果精调_Sidechain是如何工作的,为什么sidechain可以带来如此酷炫的效果...
  3. cad细等线体不显示_CAD技法大全,如何在CAD中解决好部分图元无法正常显示的问题 ?...
  4. WARNING: Ignoring invalid distribution -ip (e:\python\lib\site-packages)
  5. 模拟生产者-消费者问题和读者-写者问题
  6. 在后台增加一个查询条件
  7. nodejs 从gitlab拉下来后运行爆错解决
  8. python的枚举函数_enumerate()函数~~返回一个枚举对象
  9. weblogic进程自动关闭_手机内存不够还卡顿,那是你不会清理,关闭这3个设置就变流畅...
  10. mysql分布式数据库_分布式数据库搭建详细教程