Class: Akephalos::RemoteClient
- Inherits:
-
Object
- Object
- Akephalos::RemoteClient
- Defined in:
- lib/akephalos/remote_client.rb
Overview
Class Method Summary collapse
-
.manager ⇒ DRbObject
Starts a remove JRuby DRb server unless already running and returns an instance of Akephalos::ClientManager.
-
.new(options = {}) ⇒ DRbObject
A new instance of Akephalos::Client from the DRb server.
-
.start! ⇒ Object
Start a remote server process and return when it is available for use.
Class Method Details
.manager ⇒ DRbObject
Starts a remove JRuby DRb server unless already running and returns an instance of Akephalos::ClientManager.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/akephalos/remote_client.rb', line 29 def self.manager return @manager if defined?(@manager) server_port = start! DRb.start_service("druby://127.0.0.1:#{find_available_port}") manager = 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. manager.configuration = Akephalos.configuration.extend(DRbUndumped) @manager = manager end |
.new(options = {}) ⇒ DRbObject
Returns a new instance of Akephalos::Client from the DRb server.
21 22 23 |
# File 'lib/akephalos/remote_client.rb', line 21 def self.new( = {}) manager.new_client() end |
.start! ⇒ Object
Start a remote server process and return when it is available for use.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/akephalos/remote_client.rb', line 47 def self.start! port = find_available_port remote_client = IO.popen("ruby #{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 |