fastbeans 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 009d4f46bbf878b1cdbb7dd9306e900fdf6b7383
4
- data.tar.gz: 5e3b72f8623a07078a0703e40659151ed52bcc5b
3
+ metadata.gz: 253535af0467722585d09f5e68012b7d7cf376d4
4
+ data.tar.gz: 9482dc05865476f6b32629a26ccadc9ada5365c8
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: f4975abf1d69929357b03767b035c787bd7d9d3795bbcca059253e66954c7851e62ae6bc3592f6f822ea5f0131cfbffc211098643816933bc0d985ecb83bd3f9
7
- data.tar.gz: fbacfa11add60048ab93d02ed27c9252f7b2cad2a4d4889eb783e900880f3512e43639579484e4aff0fe8aeb5e0b245543c85382f273b72cee37301c52aa8778
6
+ metadata.gz: d0cad8311ce4a55d7c198a5b2443777fd362bffb77df3819731ac6b2e694967af67c542684df871f519732014a0f17e645ed715d01accc07d55e75f81436fa71
7
+ data.tar.gz: d390aa9d9117303fac53508e8716bd193cf1831b756767707d2dc7ae9db7f1ae58a393442143fbe37ba902e0639711ce28557bbfc5f56311b80637ad68e4754f
@@ -9,11 +9,11 @@ module Fastbeans
9
9
 
10
10
  attr_reader :call_cache
11
11
  attr_accessor :connection_class
12
+ attr_accessor :cache_class
12
13
 
13
- def initialize(host='127.0.0.1', port=12345, cache_size=nil, pool_opts={})
14
+ def initialize(host='127.0.0.1', port=12345, cache=nil, pool_opts={})
14
15
  @host, @port = host, port
15
- @cache_size ||= CALL_CACHE_SIZE
16
- @call_cache = Rufus::Lru::SynchronizedHash.new(@cache_size)
16
+ @call_cache = cache || Rufus::Lru::SynchronizedHash.new(CALL_CACHE_SIZE)
17
17
  @pool_opts = {:size => 5, :timeout => 5}.update(pool_opts)
18
18
  @connection_class = Fastbeans::Connection
19
19
  end
@@ -29,7 +29,7 @@ module Fastbeans
29
29
  end
30
30
 
31
31
  def call(*data)
32
- Fastbeans.benchmark("Calling: #{data.inspect}") do
32
+ Fastbeans.benchmark("Calling: #{data.first.inspect}") do
33
33
  pool.with do |conn|
34
34
  conn.call(*data)
35
35
  end
@@ -10,7 +10,12 @@ module Fastbeans
10
10
  def initialize(host, port)
11
11
  Fastbeans.debug("Connecting to #{host}:#{port}")
12
12
  @host, @port = host, port
13
- @socket = connect!(@host, @port)
13
+ begin
14
+ @socket = connect!(@host, @port)
15
+ rescue => e
16
+ Fastbeans.error(e)
17
+ raise RemoteConnectionDead, e.message
18
+ end
14
19
  end
15
20
 
16
21
  def connect!(host, port)
@@ -72,6 +77,9 @@ module Fastbeans
72
77
 
73
78
  def with_socket
74
79
  yield(get_socket)
80
+ rescue Exception => anything
81
+ disconnect!
82
+ raise
75
83
  end
76
84
 
77
85
  def perform(data)
@@ -1,3 +1,3 @@
1
1
  module Fastbeans
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/fastbeans.rb CHANGED
@@ -16,13 +16,22 @@ module Fastbeans
16
16
  end
17
17
  end
18
18
 
19
+ def error(str_or_exc)
20
+ case str_or_exc
21
+ when String
22
+ STDERR.puts("[#{Time.now}] #{str_or_exc}")
23
+ when Exception
24
+ error("Exception: #{str_or_exc.message}\n#{str_or_exc.backtrace.join("\n")}")
25
+ end
26
+ end
27
+
19
28
  def benchmark(str, &blk)
20
29
  debug(str)
21
30
  t1 = Time.now
22
31
  blk.call
23
32
  ensure
24
33
  t2 = Time.now
25
- debug("Time spent: #{t2-t1}s")
34
+ debug("Time spent: #{t2-t1}s") if t1
26
35
  end
27
36
 
28
37
  def exception(classname)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastbeans
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dima Sabanin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack