def dispatch(request, connection)
Log.debug("Dispatching a message to agent #{request.agent}")
Thread.new do
begin
agent = PluginManager["#{request.agent}_agent"]
Timeout::timeout(agent.timeout) do
replies = agent.handlemsg(request.payload, connection)
unless replies == nil
yield(replies)
end
end
rescue Timeout::Error => e
Log.warn("Timeout while handling message for #{request.agent}")
rescue Exception => e
Log.error("Execution of #{request.agent} failed: #{e}")
Log.error(e.backtrace.join("\n\t\t"))
end
end
end