fastbeans 0.0.2 → 0.1.0

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: fde83e1b94b24bc6b9ef5eca97b61406d8bd317c
4
- data.tar.gz: b685ad0744874132e32307f1d3bf33a733e61c0c
3
+ metadata.gz: 81dd5cefa84f07df8a30be547a2d1f59d9a45fb1
4
+ data.tar.gz: 0f4246c4f140470ce697400708f34fb10dc3f3ca
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 5e92eedcd609eb008ab486ff06752b833f626335625bd248b5d1c223f9f3f0ca9b7ad3c3f67d135ccf934c53f6224c8419aa06cbd36eb0e15cf69f5dfaa619af
7
- data.tar.gz: d14fc7575bc30989351f68ac83b4c19c8ec7d8d479f2769e9f588551227c1f478cee9c72b33c6336cbcc542c7891a75b0335e97566d4baa33eb55e97b1857e80
6
+ metadata.gz: 34fb78c25ae1d453793b48679a6c53ff31558e15ac584333d8354ffe98d162524b00a4700bf5c575d298b922cb435b602fe2d5422cb4aca6a74b42f9d68bdc8c
7
+ data.tar.gz: 641b69d5cf561bfddaca4ca165e405f04db666fc6cd60599368ceeef8db13d1f768f0aaf3db3d3bc850a509b9a86f73322c05fc9eac3160e1c6c28f225826ca5
@@ -5,15 +5,21 @@ require 'rufus-lru'
5
5
  module Fastbeans
6
6
 
7
7
  class Client
8
- RESULT_CACHE_SIZE=100
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 ||= RESULT_CACHE_SIZE
13
- @lru_cache = Rufus::Lru::SynchronizedHash.new(@cache_size)
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
- counter = 0
35
+ retries = 0
30
36
  begin
31
37
  call_without_retries(*data)
32
38
  rescue Fastbeans::RemoteConnectionFailed => e
33
- if counter < 3
34
- counter += 1
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} (#{counter} retries)"
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
- @lru_cache[data] ||= call(*data)
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, @sock)
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
@@ -1,3 +1,3 @@
1
1
  module Fastbeans
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
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.0.2
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-04-27 00:00:00.000000000 Z
11
+ date: 2013-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack