class Estore::ConnectionContext

Registry storing handlers for the pending commands

Public Class Methods

new() click to toggle source
# File lib/estore/connection_context.rb, line 6
def initialize
  @mutex = Mutex.new
  @commands = {}
end

Public Instance Methods

dispatch(uuid, message) click to toggle source
# File lib/estore/connection_context.rb, line 23
def dispatch(uuid, message)
  command = @commands[uuid]
  command.handle(message) if command
rescue => error
  command.reject! error
  remove(command)

  puts "[DISPATCH] #{error.message}"
  puts error.backtrace
end
empty?() click to toggle source
# File lib/estore/connection_context.rb, line 34
def empty?
  @commands.empty?
end
on_error(error) click to toggle source
# 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) click to toggle source
# File lib/estore/connection_context.rb, line 11
def register(command)
  @mutex.synchronize do
    @commands[command.uuid] = command
  end
end
remove(command) click to toggle source
# File lib/estore/connection_context.rb, line 17
def remove(command)
  @mutex.synchronize do
    @commands.delete(command.uuid)
  end
end