Class: ClusteredRpc::Transport::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/clustered_rpc/transport/base.rb

Direct Known Subclasses

LocalProcess, RedisCluster

Instance Method Summary collapse

Instance Method Details

#connectObject



9
10
11
# File 'lib/clustered_rpc/transport/base.rb', line 9

def connect
  # Subclassers should implement this
end

#get_result(request_id) ⇒ Object



5
6
7
# File 'lib/clustered_rpc/transport/base.rb', line 5

def get_result(request_id)
  raise "Subclassers must implement this to retrieve results"
end

#reconnectObject



17
18
19
# File 'lib/clustered_rpc/transport/base.rb', line 17

def reconnect
  # Subclassers should implement this if they offer keep_alive guarantees
end

#run_method_from_message(payload) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/clustered_rpc/transport/base.rb', line 21

def run_method_from_message(payload)
  klass=payload['klass']
  method=payload['method']
  klass = Object.const_get(klass) rescue nil if klass.is_a? String  
  if klass
    start_time = Time.now
    args = payload['args']
    kwargs = payload['kwargs']
    kwargs = Hash[kwargs.map{|k,v| [k.to_sym, v] }] if kwargs
    result = if args && args.length > 0 && kwargs && kwargs.length > 0
      klass.send method.to_sym, *args, **kwargs
    elsif kwargs && kwargs.length > 0
      klass.send method.to_sym, **kwargs
    elsif args && args.length > 0
      klass.send method.to_sym, *args
    else           
      klass.send method.to_sym
    end          
    seconds = Time.now - start_time        
  end
  {seconds: seconds, result: result}
end

#subscribed?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/clustered_rpc/transport/base.rb', line 13

def subscribed?
  # Subclassers should implement this if they offer keep_alive guarantees
end