[
https://issues.apache.org/jira/browse/STORM-515?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15220702#comment-15220702
]
ASF GitHub Bot commented on STORM-515:
--------------------------------------
Github user knusbaum commented on a diff in the pull request:
https://github.com/apache/storm/pull/1262#discussion_r58131243
--- Diff:
examples/storm-starter/src/clj/org/apache/storm/starter/clj/bolts.clj ---
@@ -0,0 +1,75 @@
+;; Licensed to the Apache Software Foundation (ASF) under one
+;; or more contributor license agreements. See the NOTICE file
+;; distributed with this work for additional information
+;; regarding copyright ownership. The ASF licenses this file
+;; to you under the Apache License, Version 2.0 (the
+;; "License"); you may not use this file except in compliance
+;; with the License. You may obtain a copy of the License at
+;;
+;; http://www.apache.org/licenses/LICENSE-2.0
+;;
+;; Unless required by applicable law or agreed to in writing, software
+;; distributed under the License is distributed on an "AS IS" BASIS,
+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;; See the License for the specific language governing permissions and
+;; limitations under the License.
+(ns org.apache.storm.starter.clj.bolts
+ (:require [org.apache.storm
+ [clojure :refer :all]
+ [config :refer :all]
+ [log :refer :all]])
+ (:import [org.apache.storm.starter.tools
+ NthLastModifiedTimeTracker SlidingWindowCounter
+ Rankings RankableObjectWithFields]
+ [org.apache.storm.utils TupleUtils]))
+
+(defbolt rolling-count-bolt ["obj" "count" "actualWindowLengthInSeconds"]
+ {:prepare true
+ :params [window-length emit-frequency]
+ :conf {TOPOLOGY-TICK-TUPLE-FREQ-SECS emit-frequency}}
+ [conf context collector]
+ (let [num-windows (/ window-length emit-frequency)
+ counter (SlidingWindowCounter. num-windows)
+ tracker (NthLastModifiedTimeTracker. num-windows)]
+ (bolt
+ (execute [{word "word" :as tuple}]
+ (if (TupleUtils/isTick tuple)
+ (let [counts (.getCountsThenAdvanceWindow counter)
+ actual-window-length (.secondsSinceOldestModification
tracker)]
+ (log-debug "Received tick tuple, triggering emit of current
window counts")
+ (.markAsModified tracker)
+ (doseq [[obj count] counts]
+ (emit-bolt! collector [obj count actual-window-length])))
+ (do
+ (.incrementCount counter word)
+ (ack! collector tuple)))))))
+
+(defmacro update-rankings [& body]
+ `(if (TupleUtils/isTick ~'tuple)
--- End diff --
Relying on symbols from the expansion environment is sort of a bad idea. It
does make the call look cleaner, but it leaves potential for accidental
breakage in mysterious ways.
> Clojure documentation and examples
> ----------------------------------
>
> Key: STORM-515
> URL: https://issues.apache.org/jira/browse/STORM-515
> Project: Apache Storm
> Issue Type: Improvement
> Components: documentation, examples
> Affects Versions: 0.9.2-incubating
> Reporter: Dmitri Sotnikov
> Labels: newbie
>
> Clojure storm-starter example is extremely basic
> (https://github.com/apache/storm/blob/master/examples/storm-starter/src/clj/storm/starter/clj/word_count.clj)
> and doesn't demonstrate many use cases.
> Clojure documentation page
> (http://storm.incubator.apache.org/documentation/Clojure-DSL.html) has
> unreadable code samples, and glosses over many details in how bolts are
> setup, how to initialize parametarized bolts, where the requires such as
> execute come from, and so on.
> It would be nice to see clear documentation with properly documented examples
> for each of the use cases.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)