fastbeans 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fastbeans/client.rb +17 -9
- data/lib/fastbeans/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81dd5cefa84f07df8a30be547a2d1f59d9a45fb1
|
4
|
+
data.tar.gz: 0f4246c4f140470ce697400708f34fb10dc3f3ca
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34fb78c25ae1d453793b48679a6c53ff31558e15ac584333d8354ffe98d162524b00a4700bf5c575d298b922cb435b602fe2d5422cb4aca6a74b42f9d68bdc8c
|
7
|
+
data.tar.gz: 641b69d5cf561bfddaca4ca165e405f04db666fc6cd60599368ceeef8db13d1f768f0aaf3db3d3bc850a509b9a86f73322c05fc9eac3160e1c6c28f225826ca5
|
data/lib/fastbeans/client.rb
CHANGED
@@ -5,15 +5,21 @@ require 'rufus-lru'
|
|
5
5
|
module Fastbeans
|
6
6
|
|
7
7
|
class Client
|
8
|
-
|
8
|
+
CALL_CACHE_SIZE=100
|
9
|
+
|
10
|
+
attr_reader :call_cache
|
9
11
|
|
10
12
|
def initialize(host, port, cache_size=nil)
|
11
13
|
@host, @port = host, port
|
12
|
-
@cache_size ||=
|
13
|
-
@
|
14
|
+
@cache_size ||= CALL_CACHE_SIZE
|
15
|
+
@call_cache = Rufus::Lru::SynchronizedHash.new(@cache_size)
|
14
16
|
connect!(host, port)
|
15
17
|
end
|
16
18
|
|
19
|
+
def clear_call_cache!
|
20
|
+
@call_cache.clear
|
21
|
+
end
|
22
|
+
|
17
23
|
def reconnect!
|
18
24
|
disconnect!
|
19
25
|
connect!(@host, @port)
|
@@ -26,12 +32,12 @@ module Fastbeans
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def call(*data)
|
29
|
-
|
35
|
+
retries = 0
|
30
36
|
begin
|
31
37
|
call_without_retries(*data)
|
32
38
|
rescue Fastbeans::RemoteConnectionFailed => e
|
33
|
-
if
|
34
|
-
|
39
|
+
if retries < 3
|
40
|
+
retries += 1
|
35
41
|
begin
|
36
42
|
reconnect!
|
37
43
|
rescue => e
|
@@ -39,18 +45,20 @@ module Fastbeans
|
|
39
45
|
end
|
40
46
|
retry
|
41
47
|
else
|
42
|
-
raise RemoteConnectionDead, "#{e.message} (#{
|
48
|
+
raise RemoteConnectionDead, "#{e.message} (#{retries} retries)"
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
47
53
|
def cached_call(*data)
|
48
|
-
@
|
54
|
+
@call_cache[data] ||= call(*data)
|
49
55
|
end
|
50
56
|
|
51
57
|
def call_without_retries(*data)
|
52
58
|
resp = @mutex.synchronize do
|
53
|
-
MessagePack.pack(data
|
59
|
+
payload = MessagePack.pack(data).force_encoding("CP1252") # fucking kill me please
|
60
|
+
@sock.write([payload.bytesize].pack("N"))
|
61
|
+
@sock.write(payload)
|
54
62
|
MessagePack.load(@sock)
|
55
63
|
end
|
56
64
|
if resp == 0xDEAD
|
data/lib/fastbeans/version.rb
CHANGED
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.0
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|