Class: Akephalos::RemoteClient
- Inherits:
-
Object
- Object
- Akephalos::RemoteClient
- Defined in:
- lib/akephalos/remote_client.rb
Overview
Class Method Summary collapse
-
.new ⇒ DRbObject
Start a remote akephalos server and return the remote Akephalos::Client instance.
-
.start! ⇒ Object
Start a remote server process and return when it is available for use.
Class Method Details
.new ⇒ DRbObject
Start a remote akephalos server and return the remote Akephalos::Client instance.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/akephalos/remote_client.rb', line 22 def self.new server_port = start! DRb.start_service("druby://127.0.0.1:#{find_available_port}") client = DRbObject.new_with_uri("druby://127.0.0.1:#{server_port}") # 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 and return when it is available for use.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/akephalos/remote_client.rb', line 38 def self.start! port = find_available_port remote_client = IO.popen("#{Akephalos::BIN_DIR + 'akephalos'} #{port}") # Set up a monitor thread to detect if the forked server exits # prematurely. server_monitor = Thread.new { Thread.current[:exited] = Process.wait(remote_client.pid) } # Wait for the server to be accessible on the socket we specified. until responsive?(port) exit!(1) if server_monitor[:exited] sleep 0.5 end server_monitor.kill # Ensure that the remote server shuts down gracefully when we are # finished. at_exit { Process.kill(:INT, remote_client.pid) } port end |