Created
September 19, 2010 10:40
-
-
Save skanev/586649 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sunglass | |
module Slave | |
class WEBrick | |
def initialize(application, port) | |
@application = application | |
@port = port | |
@mutex = Mutex.new | |
@condition = ConditionVariable.new | |
end | |
def start | |
@mutex.synchronize do | |
Thread.new do | |
Rack::Handler::WEBrick.run(@application, webrick_options) { |server| @server = server } | |
end | |
@condition.wait @mutex | |
end | |
end | |
def stop | |
@mutex.synchronize do | |
@server.shutdown | |
@condition.wait @mutex | |
end | |
end | |
private | |
def webrick_options | |
{ | |
:Port => @port, | |
:Logger => Logger.new('/dev/null'), | |
:AccessLog => [], | |
:StartCallback => lambda { @mutex.synchronize { @condition.signal } }, | |
:StopCallback => lambda { @mutex.synchronize { @condition.signal } }, | |
} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment