rgossip2 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rgossip2/context_helper.rb +21 -2
- metadata +3 -3
@@ -20,18 +20,37 @@ module RGossip2
|
|
20
20
|
# 各種ハンドラプロキシメソッド
|
21
21
|
def callback(action, address, timestamp, data)
|
22
22
|
if @context.callback_handler
|
23
|
-
@context.callback_handler
|
23
|
+
__proc_yield_protect__(@context.callback_handler, action, address, timestamp, data)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def handle_error(e)
|
28
28
|
if @context.error_handler
|
29
|
-
@context.error_handler
|
29
|
+
__proc_yield_protect__(@context.error_handler, e)
|
30
30
|
else
|
31
31
|
raise e
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def __proc_yield_protect__(proc, *args)
|
36
|
+
case proc.arity
|
37
|
+
when 0
|
38
|
+
proc.call
|
39
|
+
when 1
|
40
|
+
proc.call((args.length < 2) ? args.first : args)
|
41
|
+
else
|
42
|
+
proc.call(*args)
|
43
|
+
end
|
44
|
+
rescue Exception => e
|
45
|
+
message = (["#{e.class}: #{e.message}"] + (e.backtrace || [])).join("\n\tfrom ")
|
46
|
+
|
47
|
+
if @context.logger
|
48
|
+
@context.logger.error(message)
|
49
|
+
else
|
50
|
+
$stderr.puts(message)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
35
54
|
# ノード情報群からハッシュ値とメッセージを生成する
|
36
55
|
def digest_and_message(nodes)
|
37
56
|
message = nodes.map {|i| i.to_a }.to_msgpack
|
metadata
CHANGED