simpler bolt

This commit is contained in:
Colin Surprenant 2011-11-10 17:23:35 -05:00
parent 8ba31f6a74
commit 902fb8cb9c
1 changed files with 8 additions and 12 deletions

View File

@ -1,32 +1,28 @@
class WordCountBolt < RedStorm::SimpleBolt
output_fields :word, :count
on_init {@counts = Hash.new{|h, k| h[k] = 0}}
on_tuple do |tuple|
word = tuple.getString(0)
@counts[word] += 1
[word, @counts[word]]
end
def initialize
@counts = Hash.new{|h, k| h[k] = 0}
end
end
# below is the same bolt but passing a method name to on_tuple
# class WordCountBolt < RedStorm::SimpleBolt
# output_fields :word, :count
# on_tuple :count_word, :ack => true, :anchor => true
# on_init {@counts = Hash.new{|h, k| h[k] = 0}}
# on_tuple :count_word
#
# def count_word(tuple)
# word = tuple.getString(0)
# @counts[word] += 1
#
# [word, @counts[word]]
# end
# def initialize
# @counts = Hash.new{|h, k| h[k] = 0}
# end
# end