Class: Akephalos::RemoteClient
- Inherits:
-
Object
- Object
- Akephalos::RemoteClient
- Defined in:
- lib/akephalos/remote_client.rb
Overview
The RemoteClient class provides an interface to an Akephalos::Client isntance on a remote DRb server.
Usage
client = Akephalos::RemoteClient.new
client.visit "http://www.oinopa.com"
client.page.source # => "<!DOCTYPE html PUBLIC..."
Class Method Summary collapse
-
.new ⇒ Object
Starts a remote akephalos server and returns the remote Akephalos::Client instance.
-
.start! ⇒ Object
Start a remote server process, returning when it is available for use.
Class Method Details
.new ⇒ Object
Starts a remote akephalos server and returns the remote Akephalos::Client instance.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/akephalos/remote_client.rb', line 22 def self.new start! DRb.start_service client = DRbObject.new_with_uri("drbunix://#{@socket_file}") # We want to share our local configuration with the remote server # process, so we share an undumped version of our configuration. This # lets us continue to make changes locally and have them reflected in the # remote process. client.configuration = Akephalos.configuration.extend(DRbUndumped) client end |
.start! ⇒ Object
Start a remote server process, returning when it is available for use.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/akephalos/remote_client.rb', line 36 def self.start! remote_client = fork do exec("#{Akephalos::BIN_DIR + 'akephalos'} #{@socket_file}") end # Set up a monitor thread to detect if the forked server exits # prematurely. server_monitor = Thread.new { Thread.current[:exited] = Process.wait } # Wait for the server to be accessible on the socket we specified. until File.exists?(@socket_file) exit!(1) if server_monitor[:exited] sleep 1 end server_monitor.kill # Ensure that the remote server shuts down gracefully when we are # finished. at_exit { Process.kill(:INT, remote_client); File.unlink(@socket_file) } end |