storm 源码笔记
(reify DistributedRPC$Iface
(^String execute
[this ^String function ^String args]
(log-debug "Received DRPC request for " function " " args " at " (System/currentTimeMillis))
(let [id (str (swap! ctr (fn [v] (mod (inc v) 1000000000))))
^Semaphore sem (Semaphore. 0)
req (DRPCRequest. args id)
^ConcurrentLinkedQueue queue (acquire-queue request-queues function)]
(swap! id->start assoc id (current-time-secs))
(swap! id->sem assoc id sem)
(swap! id->function assoc id function)
(swap! id->request assoc id req)
(.add queue req)
(log-debug "Waiting for DRPC result for " function " " args " at " (System/currentTimeMillis))
(.acquire sem)
(log-debug "Acquired DRPC result for " function " " args " at " (System/currentTimeMillis))
(let [result (@id->result id)]
(cleanup id)
(log-debug "Returning DRPC result for " function " " args " at " (System/currentTimeMillis))
(if (instance? DRPCExecutionException result)
(throw result)
(if (nil? result)
(throw (DRPCExecutionException. "Request timed out"))
result)))))
几个关键点:
1. reify:
Essentially, it is a way to
create objects that satisfy any protocol (or implement methods of any interface or
Object). This makes it analogous to anonymous inner classes in Java.(摘自《clojure programming》)
2. ^String
type hint
3. ^String execute
这里的^String是execute方法的返回类型hint
4. 总结
这里的代码其实就是实现了DistributedRPC$Iface接口。这个接口只定义了一个函数,execute,其接收两个参数,类型都是^String,返回类型也为^String。
关于DistributedRPC$Iface接口,参见https://storm.incubator.apache.org/apidocs/。以下是execute的说明:
String execute(String functionName,
String funcArgs)
throws DRPCExecutionException,
org.apache.thrift.TException
和这里的实现正好吻合。
storm 源码笔记的更多相关文章
- JStorm与Storm源码分析(四)--均衡调度器,EvenScheduler
EvenScheduler同DefaultScheduler一样,同样实现了IScheduler接口, 由下面代码可以看出: (ns backtype.storm.scheduler.EvenSche ...
- JStorm与Storm源码分析(一)--nimbus-data
Nimbus里定义了一些共享数据结构,比如nimbus-data. nimbus-data结构里定义了很多公用的数据,请看下面代码: (defn nimbus-data [conf inimbus] ...
- JStorm与Storm源码分析(三)--Scheduler,调度器
Scheduler作为Storm的调度器,负责为Topology分配可用资源. Storm提供了IScheduler接口,用户可以通过实现该接口来自定义Scheduler. 其定义如下: public ...
- JStorm与Storm源码分析(二)--任务分配,assignment
mk-assignments主要功能就是产生Executor与节点+端口的对应关系,将Executor分配到某个节点的某个端口上,以及进行相应的调度处理.代码注释如下: ;;参数nimbus为nimb ...
- storm源码之storm代码结构【译】【转】
[原]storm源码之storm代码结构[译] 说明:本文翻译自Storm在GitHub上的官方Wiki中提供的Storm代码结构描述一节Structure of the codebase,希望对正 ...
- storm源码之一个class解决nimbus单点问题【转】
本文导读: storm nimbus 单节点问题概述 storm与解决nimbus单点相关的概念 nimbus目前无法做到多节点的原因 解决nimbus单点问题的关键 业界对nimbus单点问题的努力 ...
- storm源码之理解Storm中Worker、Executor、Task关系 + 并发度详解
本文导读: 1 Worker.Executor.task详解 2 配置拓扑的并发度 3 拓扑示例 4 动态配置拓扑并发度 Worker.Executor.Task详解: Storm在集群上运行一个To ...
- 【原】storm源码之storm代码结构【译】
说明:本文翻译自Storm在GitHub上的官方Wiki中提供的Storm代码结构描述一节Structure of the codebase,希望对正在基于Storm进行源码级学习和研究的朋友有所帮助 ...
- Zepto源码笔记(一)
最近在研究Zepto的源码,这是第一篇分析,欢迎大家继续关注,第一次写源码笔记,希望大家多指点指点,第一篇文章由于首次分析原因不会有太多干货,希望后面的文章能成为各位大大心目中的干货. Zepto是一 ...
随机推荐
- java根据标点英文分词
最近学习java字符串部分,用正则表达式做了一个简单的统计单词出现次数的小程序,目前只能统计英文. 整个程序包括三个包,分别为output,run,wordcount wordCount包 执行单词统 ...
- About “this” of Javascript
the 4 point about This: 1.the use of Object methods 2.the use of constructors 3.the use of ordinary ...
- Python笔记总结week1
1. Python介绍: 发明者:Guido 应用范围:网络应用.科学运算.GUI程序.系统管理工具.其他程序 优势:简单易懂.开发效率高.高级语言.可移植性.可扩展性.可嵌入性. 缺点:速度慢,代码 ...
- 一个在线jpg png转ICO的网站
网站地址: https://lvwenhan.com/convertico/
- [转载]SQL Server如何保证可空字段中非空值唯一
原文地址:http://www.cnblogs.com/caspnet/archive/2011/02/23/1962638.html 解决问题是:在一个表里面,有一个允许为空的字段,空是可以重复的, ...
- Scala 高级编程练习
定义自己的控制结构,使它语言内置的用法一样 package exp object Main { def enableCustomerIF = false; def main(args: Array[S ...
- (DFS、全排列)POJ-3187 Backward Digit Sums
题目地址 简要题意: 输入两个数n和m,分别表示给你1--n这些整数,将他们按一定顺序摆成一行,按照杨辉三角的计算方式进行求和,求使他们求到最后时结果等于m的排列中字典序最小的一种. 思路分析: 不难 ...
- uva 213 Message Decoding
思路来自紫书...开始时的思路估计100行+,果断放弃!关键:1.正确提取出函数! initmap():初始化字母与整数的映射. returnint(x):向后读取x位,并转换为十进制数返回. ...
- 初学3D Touch
引言 With iOS 9, new iPhone models add a third dimension to the user interface. A user can now press y ...
- useful tips for win7--close the noise volume(关掉win7开机、系统操作的声音)
how to close the voice of your PC? i) open your computer and then press F2 to enter the BIOS set-u ...