Module: EMogileFS
- Defined in:
- lib/emogilefs.rb
Defined Under Namespace
Classes: Request
Constant Summary collapse
- @@connections =
{}
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#current_task ⇒ Object
Returns the value of attribute current_task.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_task ⇒ Object
- #initialize(client) ⇒ Object
- #new_task(request) ⇒ Object
- #receive_data(data) ⇒ Object
- #socket ⇒ Object
- #task_completed ⇒ Object
- #unbind ⇒ Object
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
20 21 22 |
# File 'lib/emogilefs.rb', line 20 def client @client end |
#current_task ⇒ Object
Returns the value of attribute current_task.
20 21 22 |
# File 'lib/emogilefs.rb', line 20 def current_task @current_task end |
Class Method Details
.<<(request) ⇒ Object
6 7 8 |
# File 'lib/emogilefs.rb', line 6 def <<(request) connection(request.client).new_task request end |
.connection(client) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/emogilefs.rb', line 9 def connection(client) real_socket = client.send(:socket) current_client = @@connections[client] if current_client && current_client.socket == real_socket current_client else @@connections[client] = EM.attach real_socket, EMogileFS, client end end |
Instance Method Details
#handle_task ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/emogilefs.rb', line 42 def handle_task if @queue.size > 0 && @current_task.nil? @current_task = @queue.pop @current_task.perform end end |
#initialize(client) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/emogilefs.rb', line 22 def initialize(client) @queue = Queue.new @current_task = nil self.client = client super end |
#new_task(request) ⇒ Object
33 34 35 36 |
# File 'lib/emogilefs.rb', line 33 def new_task(request) @queue << request handle_task end |
#receive_data(data) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/emogilefs.rb', line 50 def receive_data(data) begin raise MogileFS::Backend::ConnectionLost unless data if current_task && current_task.callback begin parsed = client.send :parse_response, data current_task.callback.call parsed rescue MogileFS::Backend::UnknownKeyError current_task.callback.call :unknown_key rescue MogileFS::Backend::ChannelNotFoundError => e current_task.callback.call :channel_not_found end end ensure task_completed handle_task end end |
#socket ⇒ Object
29 30 31 |
# File 'lib/emogilefs.rb', line 29 def socket @io end |
#task_completed ⇒ Object
38 39 40 |
# File 'lib/emogilefs.rb', line 38 def task_completed @current_task = nil end |
#unbind ⇒ Object
69 70 71 |
# File 'lib/emogilefs.rb', line 69 def unbind detach end |