(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 源码笔记的更多相关文章

  1. JStorm与Storm源码分析(四)--均衡调度器,EvenScheduler

    EvenScheduler同DefaultScheduler一样,同样实现了IScheduler接口, 由下面代码可以看出: (ns backtype.storm.scheduler.EvenSche ...

  2. JStorm与Storm源码分析(一)--nimbus-data

    Nimbus里定义了一些共享数据结构,比如nimbus-data. nimbus-data结构里定义了很多公用的数据,请看下面代码: (defn nimbus-data [conf inimbus] ...

  3. JStorm与Storm源码分析(三)--Scheduler,调度器

    Scheduler作为Storm的调度器,负责为Topology分配可用资源. Storm提供了IScheduler接口,用户可以通过实现该接口来自定义Scheduler. 其定义如下: public ...

  4. JStorm与Storm源码分析(二)--任务分配,assignment

    mk-assignments主要功能就是产生Executor与节点+端口的对应关系,将Executor分配到某个节点的某个端口上,以及进行相应的调度处理.代码注释如下: ;;参数nimbus为nimb ...

  5. storm源码之storm代码结构【译】【转】

    [原]storm源码之storm代码结构[译]  说明:本文翻译自Storm在GitHub上的官方Wiki中提供的Storm代码结构描述一节Structure of the codebase,希望对正 ...

  6. storm源码之一个class解决nimbus单点问题【转】

    本文导读: storm nimbus 单节点问题概述 storm与解决nimbus单点相关的概念 nimbus目前无法做到多节点的原因 解决nimbus单点问题的关键 业界对nimbus单点问题的努力 ...

  7. storm源码之理解Storm中Worker、Executor、Task关系 + 并发度详解

    本文导读: 1 Worker.Executor.task详解 2 配置拓扑的并发度 3 拓扑示例 4 动态配置拓扑并发度 Worker.Executor.Task详解: Storm在集群上运行一个To ...

  8. 【原】storm源码之storm代码结构【译】

    说明:本文翻译自Storm在GitHub上的官方Wiki中提供的Storm代码结构描述一节Structure of the codebase,希望对正在基于Storm进行源码级学习和研究的朋友有所帮助 ...

  9. Zepto源码笔记(一)

    最近在研究Zepto的源码,这是第一篇分析,欢迎大家继续关注,第一次写源码笔记,希望大家多指点指点,第一篇文章由于首次分析原因不会有太多干货,希望后面的文章能成为各位大大心目中的干货. Zepto是一 ...

随机推荐

  1. Linux系统的初化始配置(包括配置网络,修改主机名,关闭firewalld与selinux的生效)

    一.配置网络环境 1.运行 cmd 查看本机的ip地址,然后记录下来. 2.网络和共享中心--本地连接属性如下: 手工配置到本地连接上面 IP:172.16.191.215,DNS:101.7.8.9 ...

  2. vue-todolist

    look:先看效果: 在浏览器的地址输入localhost:8080时,页面展示的是coding和walking两个无序序列,接着在输入框输入任何字符再敲enter回车键时,列表中又增加了一列,但是只 ...

  3. CSS3回执特殊图形

  4. iOS多线程中performSelector: 和dispatch_time的不同

    iOS中timer相关的延时调用,常见的有NSObject中的performSelector:withObject:afterDelay:这个方法在调用的时候会设置当前runloop中timer,还有 ...

  5. DeviceIoControl 应用层如何和驱动层通信?

    调用的方法之一的DeviceIoControl 驱动层提供设备名 例如filedisk 在驱动层 首先先是注册列表 用winObj查看 filedisk的驱动对象 但是 这八个对象时怎么生成的呢? 我 ...

  6. SharePoint 2010 + 左侧导航(Left Nav Bar)二级菜单的修改

    SharePoint 2010 + 修改左侧导航类似顶部导航菜单的样式 查找aspmenu的控件,ID为“V4QuickLaunchMenu”,修改分别将属性“StaticDisplayLevels” ...

  7. IHttpHandler给图片加水印

    /// <summary> /// WaterMarkHandlher 的摘要说明 /// </summary> public class WaterMarkHandlher ...

  8. Python学习07——字典(2)

    笨办法学Python第40节,上次用的第三版的书,这次是第四版的书. 这一节的代码如下: cities = {'CA':'San Francisco', 'MI':'Detroit', 'FL':'J ...

  9. 不安装HALCON下安装运行版U盘加密狗驱动

    参考halcon安装指导书 Installation Guide Depending on your operating system, you can install, configure, and ...

  10. JSP内置对象---response 响应

    将response.jsp 页面的html标签(包括html.head.body)全部删掉. <%@ page language="java" import="ja ...