diff options
author | Cody Hiar <cody@hiar.ca> | 2021-10-25 14:34:37 -0600 |
---|---|---|
committer | Cody Hiar <cody@hiar.ca> | 2021-10-25 14:34:37 -0600 |
commit | e3d2ffca585660f0c088ab8323bfe78a86ba75e3 (patch) | |
tree | 1f542c4d1c032cdc85149ccfd28cafc402ddb3d0 /wordcount/multilang/resources/countbolt.py | |
parent | 08cf73a70e3ce2dbc85e8b389f15090c148ec003 (diff) |
Save working version of deploying jars
Diffstat (limited to 'wordcount/multilang/resources/countbolt.py')
-rw-r--r-- | wordcount/multilang/resources/countbolt.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/wordcount/multilang/resources/countbolt.py b/wordcount/multilang/resources/countbolt.py new file mode 100644 index 0000000..4aebc19 --- /dev/null +++ b/wordcount/multilang/resources/countbolt.py @@ -0,0 +1,26 @@ +import storm +# Counter is a nice way to count things, +# but it is a Python 2.7 thing +from collections import Counter + +class CountBolt(storm.BasicBolt): + # Initialize this instance + def initialize(self, conf, context): + self._conf = conf + self._context = context + # Create a new counter for this instance + self._counter = Counter() + storm.logInfo("Counter bolt instance starting...") + + def process(self, tup): + # Get the word from the inbound tuple + word = tup.values[0] + # Increment the counter + self._counter[word] +=1 + count = self._counter[word] + storm.logInfo("Emitting %s:%s" % (word, count)) + # Emit the word and count + storm.emit([word, count]) + +# Start the bolt when it's invoked +CountBolt().run() |