hey Anirudh, To decipher this code we need to first realize that the the `zk` in that code refers to CuratorFramework:
- https://github.com/apache/storm/blob/v0.10.0/storm-core/src/clj/backtype/storm/zookeeper.clj#L125 Next we need to figure out the funny (.. ) syntax. I happen to have tribal knowledge that this syntax is part of Clojure's java interop stuff, as documented here: http://clojure.org/reference/java_interop ------------------------------------------------ *Clojure's docs on java interop:* (.. instance-expr member+) (.. Classname-symbol member+) member ⇒ fieldName-symbol or (instanceMethodName-symbol args*) Macro. Expands into a member access (.) of the first member on the first argument, followed by the next member on the result, etc. For instance: (.. System (getProperties) (get "os.name")) expands to: (. (. System (getProperties)) (get "os.name")) but is easier to write, read, and understand. See also the -> macro which can be used similarly: (→ (System/getProperties) (.get "os.name")) ------------------------------------------------ Hence: - (.. zk (getData) (forPath path)) Expands to: - (. (. zk (getData)) (forPath path)) Which is basically (in Java syntax): - zk.getData().forPath(path) And the other line: - (.. zk (getData) (watched) (forPath path)) Basically means: - zk.getData().watched().forPath(path) Here are those docs for these Apache Curator methods: - https://curator.apache.org/apidocs/org/apache/curator/framework/CuratorFramework.html#getData-- - https://curator.apache.org/apidocs/org/apache/curator/framework/api/Watchable.html#watched-- - https://curator.apache.org/apidocs/org/apache/curator/framework/api/Pathable.html#forPath-java.lang.String- So when you call "watched" you are setting a "watcher" for the obtained data. As for what the "watcher" *is*, it seems that it comes from the cluster.clj's wrapper code having created the CuratorFramework instance: - https://github.com/apache/storm/blob/v0.10.0/storm-core/src/clj/backtype/storm/cluster.clj#L59-L70 - https://github.com/apache/storm/blob/v0.10.0/storm-core/src/clj/backtype/storm/zookeeper.clj#L48-L80 - https://github.com/apache/storm/blob/v0.10.0/storm-core/src/clj/backtype/storm/cluster.clj#L112-L114 Note that there are callbacks registered via that initialization code, so the callbacks are invoked when a watch fires. - Erik On Sun, Jan 31, 2016 at 8:57 AM, Anirudh Jayakumar < [email protected]> wrote: > Hi, > > Could someone help me understand the difference between the below zk method > invocations? > > a. (.. zk (getData) (watched) (forPath path)) > b. (.. zk (getData) (forPath path)))) > > I want to understand the significance of "watched" method here. > > Thanks, > Anirudh >
