I have a JRuby/Rails app using Rack::FiberPool and EventMachine. And I have some event-based action controller:
class TwitterController < ApllicationController
def tweets
fiber = Fiber.current
tweets = nil
EventMachine.next_tick do
http = EM::HttpRequest.new("http://search.twitter.com/search?q=rails+3&format=json").get
http.callback do
tweets = JSON.parse(http.response)
fiber.resume
end
http.errback do
puts "request failed"
fiber.resume
end
end
Fiber.yield
render :json => tweets
end
end
It works fine when I run manually with Thin server:
rails s thin
But it will not work when I deploy to Tomcat. Is there anyway to use EventMachine in Tomcat?
Thanks.