More Advanced Starfish Feature
I promised you in Dynamically Add Methods to Classes Through their Objects in Ruby that there was a good use for that idea coming up. The time has come to show you how to use it.
server do |map_reduce|
map_reduce.type = File
map_reduce.input = "some_file_name.txt"
map_reduce.process = lambda do |text|
map_reduce.finished = lambda do
client do |line|
if line =~ /some_regular_expression/
Notice how I am dynamically adding methods to map_reduce in the server declaration. I define the process and finished methods. The process method is called from the client via server.process and the finished method is called when the collection has been fully processed.
Astute readers will notice that being able to dynamically add server side helper methods does a non-distribtued version of reduce (from MapReduce), which is good enough for many real world situations. Enjoy!
You should follow me on twitter here.
Technoblog reader special: click here to get $10 off web hosting by FatCow!