From f57d0506ed02689448b9ac9c7503355da79c3203 Mon Sep 17 00:00:00 2001 From: Colin Surprenant Date: Tue, 15 Nov 2011 23:54:03 -0500 Subject: [PATCH] implicit ids and multiple values auto emit --- examples/simple/local_word_count_topology.rb | 10 ++++---- examples/simple/split_sentence_bolt.rb | 27 +++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/examples/simple/local_word_count_topology.rb b/examples/simple/local_word_count_topology.rb index 0f37955..e0aedc7 100644 --- a/examples/simple/local_word_count_topology.rb +++ b/examples/simple/local_word_count_topology.rb @@ -4,14 +4,14 @@ require 'examples/simple/split_sentence_bolt' require 'examples/simple/word_count_bolt' class LocalWordCountTopology < RedStorm::SimpleTopology - spout RandomSentenceSpout, :id => 1, :parallelism => 5 + spout RandomSentenceSpout, :parallelism => 5 - bolt SplitSentenceBolt, :id => 2, :parallelism => 8 do - source 1, :shuffle + bolt SplitSentenceBolt, :parallelism => 8 do + source RandomSentenceSpout, :shuffle end - bolt WordCountBolt, :id => 3, :parallelism => 12 do - source 2, :fields => ["word"] + bolt WordCountBolt, :parallelism => 12 do + source SplitSentenceBolt, :fields => ["word"] end configure :word_count do |env| diff --git a/examples/simple/split_sentence_bolt.rb b/examples/simple/split_sentence_bolt.rb index 8ae9a3d..f762264 100644 --- a/examples/simple/split_sentence_bolt.rb +++ b/examples/simple/split_sentence_bolt.rb @@ -1,4 +1,29 @@ class SplitSentenceBolt < RedStorm::SimpleBolt output_fields :word - on_receive(:emit => false) {|tuple| tuple.getString(0).split(' ').each {|w| emit(w)}} + + # block declaration style no auto-emit + # + # on_receive :emit => false do |tuple| + # tuple.getString(0).split(' ').each{|w| emit(w)} + # end + + # block declaration style with auto-emit + # + on_receive do |tuple| + tuple.getString(0).split(' ').map{|w| [w]} + end + + # alternate declaration style using on_receive method + # + # on_receive :emit => false + # def on_receive(tuple) + # tuple.getString(0).split(' ').each {|w| emit(w)} + # end + + # alternate declaration style using any specific method + # + # on_receive :my_method, :emit => false + # def my_method(tuple) + # tuple.getString(0).split(' ').each {|w| emit(w)} + # end end