Class: Evesync::IPC::Client

Inherits:
Object
  • Object
show all
Includes:
Evesync::IPC
Defined in:
lib/evesync/ipc/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
# File 'lib/evesync/ipc/client.rb', line 12

def initialize(params)
  check_params_provided(params, [:port])
  port = get_port(params)
  @ip = params[:ip] || 'localhost' # TODO: check ip
  @uri = "druby://#{@ip}:#{port}"
  # to remote calls for unmarshallable objects
  DRb.start_service
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

TODO: add callbacks



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/evesync/ipc/client.rb', line 22

def method_missing(method, *args, &block)
  Log.debug("RPC Client calling '#{method}' on #{@uri}")
  # FIXME: don't send +start+ and +stop+ and +initialize+
  begin
    service = DRbObject.new_with_uri(@uri)
    res = service.send(method, *args, &block)
    Log.debug("RPC Client method '#{method}' handled on #{@uri}")
    res
  rescue StandardError
    Log.warn("RPC Client ERROR: no connection")
    nil
  end
end

Instance Attribute Details

#ipObject (readonly)

Returns the value of attribute ip.



10
11
12
# File 'lib/evesync/ipc/client.rb', line 10

def ip
  @ip
end

#uriObject (readonly)

Returns the value of attribute uri.



10
11
12
# File 'lib/evesync/ipc/client.rb', line 10

def uri
  @uri
end