Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

playing with drb

  • Loading branch information...
commit 8199394ee83c960ddf6e90079eeb7f48f22bda3c 1 parent d291fb9
@svenfuchs authored
View
18 lib/steam/browser/html_unit/drb.rb
@@ -7,25 +7,27 @@ class Drb
autoload :Client, 'steam/browser/html_unit/drb/client'
autoload :Service, 'steam/browser/html_unit/drb/service'
- def initialize
+ def initialize(connection, options = {})
DRb.start_service
- @browser = DRbObject.new(nil, Steam.config[:drb_uri])
+ @drb = DRbObject.new(nil, Steam.config[:drb_uri])
+ @connection = connection
+ @options = options
end
- def daemonize(connection = nil, options = {})
- Forker.new { start(connection, options) }
+ def daemonize
+ Forker.new(@options) { start }
sleep(1) # FIXME
end
- def start(connection = nil, options = {})
+ def start
uri = Steam.config[:drb_uri]
- DRb.start_service(uri, HtmlUnit.new(connection, options))
- puts "Browser ready and listening at #{uri}"
+ DRb.start_service(uri, HtmlUnit.new(@connection, @options)) rescue Errno::EADDRINUSE
+ puts "HtmlUnit ready and listening at #{uri}"
DRb.thread.join
end
def method_missing(method, *args, &block)
- @browser.send(method, *args, &block)
+ @drb.send(method, *args, &block)
end
end
end
View
20 lib/steam/browser/html_unit/drb/client.rb
@@ -1,20 +0,0 @@
-require 'drb'
-
-module Steam
- module Browser
- class HtmlUnit
- module Drb
- class Client
- def initialize
- DRb.start_service
- @browser = DRbObject.new(nil, Service.uri)
- end
-
- def method_missing(method, *args, &block)
- @browser.send(method, *args, &block) # if @browser.respond_to?(method)
- end
- end
- end
- end
- end
-end
View
28 lib/steam/browser/html_unit/drb/service.rb
@@ -1,28 +0,0 @@
-require 'drb'
-require 'core_ext/ruby/process/daemon'
-
-module Steam
- module Browser
- class HtmlUnit
- module Drb
- module Service
- class << self
- def uri
- Steam.config[:drb_uri]
- end
-
- def daemonize(connection = nil, options = {})
- Forker.new { start(connection, options) }
- end
-
- def start(connection = nil, options = {})
- DRb.start_service(uri, HtmlUnit.new(connection, options))
- puts "Browser ready and listening at #{uri}"
- DRb.thread.join
- end
- end
- end
- end
- end
- end
-end
View
11 lib/steam/browser/html_unit/forker.rb
@@ -9,6 +9,8 @@ def initialize(options = {}, &block)
:stdout => $stdout,
:stderr => $stderr
}.merge(options)
+
+ recall_pid && kill if options[:restart]
@pid = Kernel.fork do
STDIN.reopen options[:stdin]
@@ -16,8 +18,8 @@ def initialize(options = {}, &block)
STDERR.reopen options[:stderr]
block.call
end
- # write_pid
- at_exit { kill }
+ write_pid
+ # at_exit { kill }
end
def interrupt
@@ -25,6 +27,7 @@ def interrupt
end
def kill(signal = 'TERM')
+ puts "killing #{@pid}"
if running?
Process.kill(Signal.list[signal], @pid)
delete_pid
@@ -44,6 +47,10 @@ def write_pid
::File.open('/tmp/steam.pid', 'w'){ |f| f.write("#{@pid}") }
end
+ def recall_pid
+ @pid = ::File.read('/tmp/steam.pid').to_i rescue nil
+ end
+
def delete_pid
::File.delete('/tmp/steam.pid') rescue Errno::ENOENT
end
View
4 test/playground/drb.rb
@@ -9,9 +9,9 @@
static = Connection::Static.new(:root => root, :urls => %w(/ /javascripts /stylesheets))
connection = Rack::Cascade.new([static, @app])
-browser = Browser::HtmlUnit::Drb.new
+browser = Browser::HtmlUnit::Drb.new(connection)
-browser.daemonize(connection)
+browser.daemonize
browser.request('/index.html')
p browser.response.status
Please sign in to comment.
Something went wrong with that request. Please try again.