Class: S3Agent
Instance Method Summary collapse
-
#initialize ⇒ S3Agent
constructor
Refer to eventmachine.rubyforge.org/EventMachine/Queue.html for interface details This agent class solves the following problem RMW in S3.
- #method_missing(method, *args) ⇒ Object
-
#request_service(method, *args) ⇒ true
Requests any of :get or :put from S3.
- #set_keys(public_key, private_key) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ S3Agent
Refer to eventmachine.rubyforge.org/EventMachine/Queue.html for interface details This agent class solves the following problem RMW in S3. It has a pool of (s3) bucket, object names which are right now being processed. When a new request comes, we check if its right now sent out to S3. If yes, add it to the queue and add a pop request which will do the same thing again. If no, process it If a new read request for the same (object, bucket) comes, it will cycle through the push/pop cycle.
11 12 13 14 15 |
# File 'lib/s3_agent.rb', line 11 def initialize @public_key = nil @private_key = nil setup end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/s3_agent.rb', line 44 def method_missing(method, *args) params = args[0] q = (@obj_pools["#{params[:bucket]}:#{params[:object]}"] ||= EM::Queue.new) q.push({:method => method, :params => params}) q.pop{|request| s3i = S3Interface.new(@public_key, @private_key) s3i.send(method, params) } end |
Instance Method Details
#request_service(method, *args) ⇒ true
Requests any of :get or :put from S3. If the object is not being processed now, service it immediately. If not, push it in a queue and wait for the reactor to take it through.
39 40 41 42 |
# File 'lib/s3_agent.rb', line 39 def request_service(method, *args) setup self.send(method.to_sym, *args) end |
#set_keys(public_key, private_key) ⇒ Object
21 22 23 24 25 |
# File 'lib/s3_agent.rb', line 21 def set_keys(public_key, private_key) @public_key ||= public_key @private_key ||= private_key self end |
#setup ⇒ Object
17 18 19 |
# File 'lib/s3_agent.rb', line 17 def setup @obj_pools = {} end |