Class: Bullring::ServerProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/bullring/util/server_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ServerProxy

options looks like:

{

:server => {
  :command => [the command to run the process],
  :args => [the arguments to the process command],
  :first_port => [the first port to be used by a server]
}
:registry => {
  :host => [the host of the registry]
  :port => [the port the registry listens on]
}
:proxy => {
  :host => [the host that this proxy runs on (and listens on)]
}

}



27
28
29
# File 'lib/bullring/util/server_proxy.rb', line 27

def initialize(options)
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bullring/util/server_proxy.rb', line 35

def method_missing(m, *args, &block)  
  result = nil
  num_retries = 0

  server = nil
  begin
    server = server_registry.lease_server!

    server.logger = Bullring.logger
    result = server.send(m, *args, &block)
    server.logger = nil
  rescue ServerRegistryOffline => e
    Bullring.logger.debug {"Lost connection to the server registry (proxy)"}
    connect!
    num_retries = num_retries + 1
    if (num_retries < 3)
      retry
    else
      raise 
    end
  ensure
    server_registry.release_server if !server.nil?
  end

  result
end

Instance Method Details

#discardObject



62
63
64
65
66
67
# File 'lib/bullring/util/server_proxy.rb', line 62

def discard
  server_registry.close!      
  sleep(0.5) while !server_registry.registry_unavailable?
  DRb.stop_service
  @server_registry = nil
end

#refreshObject



69
70
71
# File 'lib/bullring/util/server_proxy.rb', line 69

def refresh
  server_registry.expire_servers
end

#server_registryObject



73
74
75
76
# File 'lib/bullring/util/server_proxy.rb', line 73

def server_registry
  connect! if @server_registry.nil?
  @server_registry
end

#store_in_registry(dictionary, key, value) ⇒ Object



31
32
33
# File 'lib/bullring/util/server_proxy.rb', line 31

def store_in_registry(dictionary, key, value)
  server_registry[dictionary, key] = value
end