Skip to content
Browse files

etc

  • Loading branch information...
1 parent 9723b4d commit e1faf0d1060d12f19a1e67342d8104fb21e92fc6 @winebarrel winebarrel committed Nov 6, 2011
Showing with 22 additions and 3 deletions.
  1. +21 −2 lib/rgossip2/context_helper.rb
  2. +1 −1 rgossip2.gemspec
View
23 lib/rgossip2/context_helper.rb
@@ -20,18 +20,37 @@ def create(klass, *args)
# 各種ハンドラプロキシメソッド
def callback(action, address, timestamp, data)
if @context.callback_handler
- @context.callback_handler.yield([action, address, timestamp, data])
+ __proc_yield_protect__(@context.callback_handler, action, address, timestamp, data)
end
end
def handle_error(e)
if @context.error_handler
- @context.error_handler.yield(e)
+ __proc_yield_protect__(@context.error_handler, e)
else
raise e
end
end
+ def __proc_yield_protect__(proc, *args)
+ case proc.arity
+ when 0
+ proc.call
+ when 1
+ proc.call((args.length < 2) ? args.first : args)
+ else
+ proc.call(*args)
+ end
+ rescue Exception => e
+ message = (["#{e.class}: #{e.message}"] + (e.backtrace || [])).join("\n\tfrom ")
+
+ if @context.logger
+ @context.logger.error(message)
+ else
+ $stderr.puts(message)
+ end
+ end
+
# ノード情報群からハッシュ値とメッセージを生成する
def digest_and_message(nodes)
message = nodes.map {|i| i.to_a }.to_msgpack
View
2 rgossip2.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'rgossip2'
- spec.version = '0.1.1'
+ spec.version = '0.1.2'
spec.summary = 'Basic implementation of a gossip protocol. This is a porting of Java implementation. see http://code.google.com/p/gossip-protocol-java/'
spec.require_paths = %w(lib)
spec.files = %w(README) + Dir.glob('bin/**/*') + Dir.glob('lib/**/*')

0 comments on commit e1faf0d

Please sign in to comment.
Something went wrong with that request. Please try again.