设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 系统 > 正文

Windows环境下大数据处理的构想(一)(2)

发布时间:2021-01-06 19:17 所属栏目:52 来源:网络整理
导读:?@Override ?public MapString,Integer wordCount(String filePath,String separator)? throws RemoteException { ??MapString,Integer? map = new? HashMap(); ??int? val; ?? ??Path? path = Paths.get(filePath)

?@Override
?public Map<String,Integer> wordCount(String filePath,String separator)? throws RemoteException {
??Map<String,Integer>? map = new? HashMap<>();
??int? val;
??
??Path? path = Paths.get(filePath);
??
??if (Files.notExists(path)) {
???System.err.println(path + " dose not exist.");
??????????? return? null;
??}
??
??if (Files.isDirectory(path)) {
???System.err.println(path + " is not a file.");
???return? null;
??}
??
??Reader? fin = null;
??BufferedReader? in = null;
??try {
???fin = Files.newBufferedReader(path,Constants.ONE);
?????} else {
??????val = map.get(key) + 1;
??????map.put(key,val);
?????}
????}
???}
??} catch (IOException e) {
???e.printStackTrace();
???return? null;
??} finally {
???try {
????if(fin != null) {
?????fin.close();
????}
????if(in != null) {
?????in.close();
????}
???} catch (IOException e) {
????e.printStackTrace();
???}
??}
??
??return? map;
?}

}

public class WCServer {

?public static void main(String[] args) throws RemoteException,MalformedURLException {
??// 注册端口
?LocateRegistry.createRegistry(Constants.PORT);
/*
?Constants.WCCount_RMI = "rmi://某节点(这里同服务器节点):" + PORT + "/net.xxx.xxx.wordCount.xxx.WCServiceImpl";
*/
// 将服务对象绑定url
??Naming.rebind(Constants.WCCount_RMI,new? WCServiceImpl());
?}

}

public class WCClient {

?public static void main(String[] args) throws MalformedURLException,RemoteException,NotBoundException {??// 在注册的服务中根据url寻找服务??WCService? wcService = (WCService) Naming.lookup(Constants.WCCount_RMI);??Map<String,Integer> wordCount = wcService.wordCount("X:/xxx/words.txt"," ");??for(String? k : wordCount.keySet()) {???System.out.println(k + "\t" + wordCount.get(k));??}?}}当然这里为了简单起见,我们把代码写死了,在实际的大数据处理框架中处理逻辑是由用户完成的。我们只需要提供接口,而且第一步先进行数据映射,即map阶段,第二步才是聚合统计reduce/aggregate,中间还有shuffle,最开始还有split。这里只是为了说明RMI在Windows中可以轻易、方便地使用。有了RMI,我们一开始的数据存储和处理逻辑就可以分布在分布式环境中了;有了RMI,我们的数据和处理逻辑就可以“自由”地在节点间“旅行”了。这构成了大数据处理框架的基础。千里之行,始于足下。借鉴hadoop和spark,我们应该先搭建RPC环境。RMI使用起来太麻烦,而且功能有限,现实中的大数据框架从未真正使用过RMI,而是使用对它的封装和改良,比如说Netty。下一节我们介绍Netty,并逐渐用Netty搭建起RPC环境。学识有限,描述错误、不周的地方,还望各位技术大佬批评指正。这一节主要论述了在windows环境下处理大数据的可能性。

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读