fastbeans 0.2.0 → 0.2.1

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: 04cdb54378919592072c8368e3c26d62366dfde5
4
- data.tar.gz: e80257667320c6b26b58134008f6c24417fb6770
3
+ metadata.gz: 67eab3ca06d0a653513eb084cb45a0655f408427
4
+ data.tar.gz: 23abe57b8fe553ad1138ebf0788152ebc80a5998
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 278316a00225048129fb1094eb3716368000d0ca6ee98ca9fe1bfc63341d214fc5fd630359fec2cb085161bb951acc272d11d1eb0e1097e349c6d7c182e8f45e
7
- data.tar.gz: 1da6d91ff9374c9b11b1f4ddfb41bf58bb4368b3f33b40e29dfe26b397515527d8127c53db3ed4100a8b6f9715ae4e9e66f1cf5ca6b768c05b1a885a41b0694e
6
+ metadata.gz: 9ccbef09ae0418cef27d3036c2b883bc8cab52d4d32d261339b52132c3b1c91f695beb5e0668f4b7a900451f86b1491f9c0fdd8c1c5d40a790c8524a9f9172e9
7
+ data.tar.gz: 5dd5b54ed3ceb38b3ef08a0df61710078da3e6eb74d5a99f399556247c26536e1690e9b0dde21b7082fce10c8fb9d4a51e7b3f74512dfb469de3033b1e78ff1f
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "msgpack"
22
22
  spec.add_runtime_dependency "rufus-lru"
23
+ spec.add_runtime_dependency "connection_pool"
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "rake"
25
26
  end
@@ -1,8 +1,9 @@
1
1
  require 'msgpack'
2
2
  require 'thread'
3
3
  require 'rufus-lru'
4
+ require 'fastbeans/connection'
4
5
  require 'fastbeans/response'
5
-
6
+ require 'connection_pool'
6
7
  module Fastbeans
7
8
 
8
9
  class Client
@@ -11,28 +12,21 @@ module Fastbeans
11
12
 
12
13
  attr_reader :call_cache
13
14
 
14
- def initialize(host="127.0.0.1", port=12345, cache_size=nil)
15
+ def initialize(host="127.0.0.1", port=12345, cache_size=nil, pool_opts={})
15
16
  @host, @port = host, port
16
17
  @cache_size ||= CALL_CACHE_SIZE
17
18
  @call_cache = Rufus::Lru::SynchronizedHash.new(@cache_size)
18
- connect!(host, port)
19
- end
20
-
21
- def clear_call_cache!
22
- @call_cache.clear
19
+ @pool_opts = {:size => 5, :timeout => 5}.update(pool_opts)
23
20
  end
24
21
 
25
- def reconnect!
26
- disconnect!
27
- connect!(@host, @port)
22
+ def pool
23
+ @pool ||= ConnectionPool.new(@pool_opts) do
24
+ Fastbeans::Connection.new(@host, @port)
25
+ end
28
26
  end
29
27
 
30
-
31
- def connect!(host, port)
32
- Fastbeans.debug("Connecting to #{host}:#{port}")
33
- @sock = TCPSocket.new(host, port)
34
- @sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
35
- @mutex = Mutex.new
28
+ def clear_call_cache!
29
+ @call_cache.clear
36
30
  end
37
31
 
38
32
  def call(*data)
@@ -63,11 +57,11 @@ module Fastbeans
63
57
  end
64
58
 
65
59
  def call_without_retries(*data)
66
- raw_resp = @mutex.synchronize do
60
+ raw_resp = pool.with do |conn|
67
61
  payload = MessagePack.pack(data).force_encoding("BINARY")
68
- @sock.write([payload.bytesize].pack("N"))
69
- @sock.write(payload)
70
- MessagePack.load(@sock)
62
+ conn.write([payload.bytesize].pack("N"))
63
+ conn.write(payload)
64
+ MessagePack.load(conn.socket)
71
65
  end
72
66
  resp = Response.new(data, raw_resp)
73
67
  resp.payload
@@ -76,12 +70,6 @@ module Fastbeans
76
70
  ne.orig_exc = e
77
71
  raise ne
78
72
  end
79
-
80
- def disconnect!
81
- if @sock
82
- @sock.close rescue nil
83
- end
84
- end
85
73
  end
86
74
 
87
75
  end
@@ -1,3 +1,3 @@
1
1
  module Fastbeans
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.2.0
4
+ version: 0.2.1
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-05-28 00:00:00.000000000 Z
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: connection_pool
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement