Module: EM::Nodes::Commands
- Included in:
- Client, Server
- Defined in:
- lib/em-nodes/commands.rb
Constant Summary
collapse
- COMMAND_PREFIX =
'send_'
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/em-nodes/commands.rb', line 21
def method_missing(method, *args)
method = method.to_s
unless method.start_with?(COMMAND_PREFIX)
EM::Nodes.logger.warn { "unknown send :#{method} #{args.inspect}" }
super(method, *args)
return
end
if @alive
send_command(method[5..-1], args)
else
EM::Nodes.logger.error { "failed command attempt #{method}, connection dead" }
end
end
|
Instance Method Details
#receive_object(h) ⇒ Object
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/em-nodes/commands.rb', line 3
def receive_object(h)
method, args = h
method = 'on_' + method
t = Time.now
send(method, *args)
EM::Nodes.logger.debug { "<= #{method} #{args.inspect} (#{Time.now - t}s)" }
rescue Object => ex
EM::Nodes.exception(ex)
end
|
#send_command(method, args) ⇒ Object
14
15
16
17
|
# File 'lib/em-nodes/commands.rb', line 14
def send_command(method, args)
EM::Nodes.logger.debug { "=> #{method}" }
EM.schedule { send_object [method.to_s, args] }
end
|