Class: Qwirk::Remote::Client

Inherits:
Object
  • Object
show all
Includes:
Rumx::Bean
Defined in:
lib/qwirk/remote/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(adapter_factory, options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
# File 'lib/qwirk/remote/client.rb', line 13

def initialize(adapter_factory, options={})
  @adapter_factory = adapter_factory
  @options         = options
  @servers = {}
  @timeout = 10.0
end

Instance Method Details

#refresh(timeout) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/qwirk/remote/client.rb', line 20

def refresh(timeout)
  new_servers = {}
  success_servers = []
  failure_servers = []
  publisher = Qwirk::Publisher.new(@adapter_factory, :topic_name => Qwirk::Remote.topic_name, :marshal => :bson, :ttl => timeout, :response => true)
  publisher.publish(:command => 'serialize').read_response(timeout) do |response|
    response.on_message do |hash|
      remote_name = Remote.remote_name(response.name)
      new_servers[remote_name] = ::Rumx::RemoteBean.new(hash, self, remote_name)
      success_servers << remote_name
    end
    response.on_remote_exception do |e|
      remote_name = Remote.remote_name(response.name)
      new_servers[remote_name] = ::Rumx::Beans::Message.new(e.message)
      failure_servers << remote_name
    end
  end
  @servers = new_servers
  answer = ''
  answer = "Success for #{success_servers.inspect}" unless success_servers.empty?
  unless failure_servers.empty?
    answer += ', ' unless answer.empty?
    answer += 'Failure for #{failure_servers.inspect}'
  end
  return answer
end

#run_operation(ancestry, operation, argument_hash, remote_name) ⇒ Object



47
48
49
50
51
# File 'lib/qwirk/remote/client.rb', line 47

def run_operation(ancestry, operation, argument_hash, remote_name)
  puts "In run_operation"
  value = remote_call(remote_name, :command => 'operation', :operation_name => operation.name, :ancestry => ancestry, :argument_hash => argument_hash)
  return operation.type.string_to_value(value['value'])
end

#set_attributes(ancestry, params, remote_name) ⇒ Object



53
54
55
56
# File 'lib/qwirk/remote/client.rb', line 53

def set_attributes(ancestry, params, remote_name)
  puts "In set_attributes"
  remote_call(remote_name, :command => 'attributes', :ancestry => ancestry, :params => params)
end