Class: Estore::ConnectionContext
- Inherits:
-
Object
- Object
- Estore::ConnectionContext
- Defined in:
- lib/estore/connection_context.rb
Overview
Registry storing handlers for the pending commands
Instance Method Summary collapse
- #dispatch(uuid, message) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ ConnectionContext
constructor
A new instance of ConnectionContext.
- #on_error(error) ⇒ Object
- #register(command) ⇒ Object
- #remove(command) ⇒ Object
Constructor Details
#initialize ⇒ ConnectionContext
Returns a new instance of ConnectionContext.
6 7 8 9 |
# File 'lib/estore/connection_context.rb', line 6 def initialize @mutex = Mutex.new @commands = {} end |
Instance Method Details
#dispatch(uuid, message) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/estore/connection_context.rb', line 23 def dispatch(uuid, ) command = @commands[uuid] command.handle() if command rescue => error command.reject! error remove(command) puts "[DISPATCH] #{error.}" puts error.backtrace end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/estore/connection_context.rb', line 34 def empty? @commands.empty? end |
#on_error(error) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/estore/connection_context.rb', line 38 def on_error(error) # TODO: Error handling @mutex.synchronize do @commands.each { |_uuid, command| command.reject! error } @commands = {} end end |
#register(command) ⇒ Object
11 12 13 14 15 |
# File 'lib/estore/connection_context.rb', line 11 def register(command) @mutex.synchronize do @commands[command.uuid] = command end end |
#remove(command) ⇒ Object
17 18 19 20 21 |
# File 'lib/estore/connection_context.rb', line 17 def remove(command) @mutex.synchronize do @commands.delete(command.uuid) end end |