Method: Cosmos::JsonDRbObject#method_missing

Defined in:
lib/cosmos/io/json_drb_object.rb

#method_missing(method_name, *method_params, **keyword_params) ⇒ Object

Forwards all method calls to the remote service.

Parameters:

  • method_name (Symbol)

    Name of the method to call

  • method_params (Array)

    Array of parameters to pass to the method

  • keyword_params (Hash<Symbol, Variable>)

    Hash of keyword parameters

Returns:

  • The result of the method call. If the method raises an exception the same exception is also raised. If something goes wrong with the protocol a JsonDRbError exception is raised.

Raises:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cosmos/io/json_drb_object.rb', line 58

def method_missing(method_name, *method_params, **keyword_params)
  raise JsonDRbError, "Shutdown" if @shutdown
  @mutex.synchronize do
    for attempt in 1..3
      @log = [nil, nil, nil]
      connect() if !@http
      json_rpc_request = JsonRpcRequest.new(method_name, method_params, keyword_params, @id)
      data = json_rpc_request.to_json(:allow_nan => true)
      response_body = make_request(data: data)
      if !response_body or response_body.to_s.length < 1
        disconnect()
      else
        response = JsonRpcResponse.from_json(response_body)
        return handle_response(response: response)
      end
    end
    error = "#{attempt} no response from server: #{@log[0]} ::: #{@log[1]} ::: #{@log[2]}"
    raise JsonDRbError, error
  end
end