Class: Ccrpc::RpcConnection::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/ccrpc/rpc_connection.rb

Overview

The context of a received call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, func, params = {}, id) ⇒ Call

Returns a new instance of Call.



44
45
46
47
48
49
50
# File 'lib/ccrpc/rpc_connection.rb', line 44

def initialize(conn, func, params={}, id)
  @conn = conn
  @func = func
  @params = params
  @id = id
  @answer = nil
end

Instance Attribute Details

#answerHash{String => String}

Returns List of parameters send back to the called.

Returns:

  • (Hash{String => String})

    List of parameters send back to the called.



41
42
43
# File 'lib/ccrpc/rpc_connection.rb', line 41

def answer
  @answer
end

#connRpcConnection (readonly)

Returns The used connection.

Returns:



34
35
36
# File 'lib/ccrpc/rpc_connection.rb', line 34

def conn
  @conn
end

#funcString (readonly)

Returns Called function.

Returns:

  • (String)

    Called function



36
37
38
# File 'lib/ccrpc/rpc_connection.rb', line 36

def func
  @func
end

#idObject (readonly)

Returns the value of attribute id.



39
40
41
# File 'lib/ccrpc/rpc_connection.rb', line 39

def id
  @id
end

#paramsHash{String => String} (readonly)

Returns List of parameters passed with the call.

Returns:

  • (Hash{String => String})

    List of parameters passed with the call.



38
39
40
# File 'lib/ccrpc/rpc_connection.rb', line 38

def params
  @params
end

Instance Method Details

#call_back(func, params = {}, &block) ⇒ Object

Send a dedicated callback to the caller’s block.

If Ccrpc::RpcConnection#call is called with both function name and block, then it’s possible to call back to this dedicated block through #call_back . The library ensures, that the callback ends up in the corresponding call block and in the same thread as the caller, even if there are multiple simultaneous calls are running at the same time in different threads or by using lazy_answers .

Yielded parameters and returned objects are described in Ccrpc::RpcConnection#call.

Parameters:

  • func (String, Symbol)

    The RPC function to be called on the other side. The other side must wait for calls through Ccrpc::RpcConnection#call with function name and with a block.

  • params (Hash{Symbol, String => Symbol, String}) (defaults to: {})

    Optional parameters passed with the RPC call. They can be retrieved through #params on the receiving side.

Raises:



72
73
74
75
# File 'lib/ccrpc/rpc_connection.rb', line 72

def call_back(func, params={}, &block)
  raise CallAlreadyReturned, "Callback is no longer possible since the call already returned #{self.inspect}" if @answer
  conn.send(:call_intern, func, params, @id, &block)
end