fastbeans 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 34f9f59a758172ffcc5fd127dfcc13f042dbcf8d
4
- data.tar.gz: 208209f3eba7a5a7234d609b3404ce32be5bbd3e
3
+ metadata.gz: 04cdb54378919592072c8368e3c26d62366dfde5
4
+ data.tar.gz: e80257667320c6b26b58134008f6c24417fb6770
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 520fe196b83219df71b4e07251bac4be33c024634f9eb06d815134b87d232335f8caffc456c2f0cef3071de3dcef11c1baa38789daddd6d7e2d6fd50bac9dbdd
7
- data.tar.gz: 08abc020dd251e1123527cd0f1bccfa4364c13ae329534e4f213dfe0194b1fd432ecd4c2ebe84da992cf3f34d1a09676294352af8efbadb3868ac89288fdae7c
6
+ metadata.gz: 278316a00225048129fb1094eb3716368000d0ca6ee98ca9fe1bfc63341d214fc5fd630359fec2cb085161bb951acc272d11d1eb0e1097e349c6d7c182e8f45e
7
+ data.tar.gz: 1da6d91ff9374c9b11b1f4ddfb41bf58bb4368b3f33b40e29dfe26b397515527d8127c53db3ed4100a8b6f9715ae4e9e66f1cf5ca6b768c05b1a885a41b0694e
@@ -1,6 +1,7 @@
1
1
  require 'msgpack'
2
2
  require 'thread'
3
3
  require 'rufus-lru'
4
+ require 'fastbeans/response'
4
5
 
5
6
  module Fastbeans
6
7
 
@@ -62,17 +63,14 @@ module Fastbeans
62
63
  end
63
64
 
64
65
  def call_without_retries(*data)
65
- resp = @mutex.synchronize do
66
+ raw_resp = @mutex.synchronize do
66
67
  payload = MessagePack.pack(data).force_encoding("BINARY")
67
68
  @sock.write([payload.bytesize].pack("N"))
68
69
  @sock.write(payload)
69
70
  MessagePack.load(@sock)
70
71
  end
71
- if resp == 0xDEAD
72
- raise RemoteException.new("Remote exception on #{data.inspect} through #{@sock.inspect}")
73
- else
74
- resp
75
- end
72
+ resp = Response.new(data, raw_resp)
73
+ resp.payload
76
74
  rescue IOError, Errno::EPIPE, MessagePack::MalformedFormatError => e
77
75
  ne = RemoteConnectionFailed.new(e.message)
78
76
  ne.orig_exc = e
@@ -8,5 +8,6 @@ module Fastbeans
8
8
  class RemoteException < Fastbeans::Exception; end
9
9
  class RemoteConnectionFailed < Fastbeans::Exception; end
10
10
  class RemoteConnectionDead < Fastbeans::Exception; end
11
-
11
+ class AutogeneratedException < Fastbeans::Exception; end
12
+
12
13
  end
@@ -0,0 +1,29 @@
1
+ module Fastbeans
2
+
3
+
4
+ class Response
5
+
6
+ def initialize(call_data, raw_response)
7
+ @call_data = call_data
8
+ @raw_response = raw_response
9
+ end
10
+
11
+ def error?
12
+ @raw_response.is_a?(Hash) and @raw_response.has_key?("fastbeans-error")
13
+ end
14
+
15
+ def payload
16
+ unless error?
17
+ @raw_response
18
+ else
19
+ raise to_exception
20
+ end
21
+ end
22
+
23
+ def to_exception
24
+ name = @raw_response["fastbeans-error"].underscore.classify
25
+ Fastbeans.exception(name).new(@raw_response["error-information"])
26
+ end
27
+ end
28
+
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Fastbeans
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/fastbeans.rb CHANGED
@@ -1,6 +1,6 @@
1
- require "fastbeans/version"
2
- require "fastbeans/errors"
3
- require "fastbeans/client"
1
+ require 'fastbeans/version'
2
+ require 'fastbeans/errors'
3
+ require 'fastbeans/client'
4
4
 
5
5
  module Fastbeans
6
6
  class << self
@@ -10,7 +10,7 @@ module Fastbeans
10
10
  def debug(str_or_exc)
11
11
  case str_or_exc
12
12
  when String
13
- STDERR.puts("[#{Time.now}] #{str}") if self.debug_mode
13
+ STDERR.puts("[#{Time.now}] #{str_or_exc}") if self.debug_mode
14
14
  when Exception
15
15
  debug("Exception: #{str_or_exc.message}\n#{str_or_exc.backtrace.join("\n")}")
16
16
  end
@@ -24,5 +24,13 @@ module Fastbeans
24
24
  t2 = Time.now
25
25
  debug("Time spent: #{t2-t1}s")
26
26
  end
27
+
28
+ def exception(classname)
29
+ begin
30
+ Fastbeans.const_get(classname)
31
+ rescue NameError
32
+ Fastbeans.const_set(classname, Class.new(Fastbeans::AutogeneratedException))
33
+ end
34
+ end
27
35
  end
28
36
  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.1.3
4
+ version: 0.2.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-05-24 00:00:00.000000000 Z
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -82,6 +82,7 @@ files:
82
82
  - lib/fastbeans.rb
83
83
  - lib/fastbeans/client.rb
84
84
  - lib/fastbeans/errors.rb
85
+ - lib/fastbeans/response.rb
85
86
  - lib/fastbeans/version.rb
86
87
  homepage: https://github.com/dsabanin/fastbeans-rb
87
88
  licenses: