riemann-client 0.2.3 → 0.2.4

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.
@@ -70,18 +70,17 @@ class Riemann::Client
70
70
  (response.states || [])
71
71
  end
72
72
 
73
+ def connect
74
+ # NOTE: connections are made automatically on send
75
+ warn "Riemann client#connect is deprecated"
76
+ end
77
+
73
78
  # Close both UDP and TCP sockets.
74
79
  def close
75
80
  @udp.close
76
81
  @tcp.close
77
82
  end
78
83
 
79
- # Connect both UDP and TCP sockets.
80
- def connect
81
- udp.connect
82
- tcp.connect
83
- end
84
-
85
84
  def connected?
86
85
  tcp.connected? and udp.connected?
87
86
  end
@@ -28,9 +28,7 @@ module Riemann
28
28
  close
29
29
  end
30
30
 
31
- if @socket and not @socket.closed?
32
- return @socket
33
- end
31
+ return @socket if connected?
34
32
 
35
33
  @socket = self.class.socket_factory.call(@options)
36
34
  @pid = Process.pid
@@ -41,15 +39,15 @@ module Riemann
41
39
 
42
40
  def close
43
41
  @locket.synchronize do
44
- if @socket && !@socket.closed?
45
- @socket.close
46
- end
42
+ @socket.close if connected?
47
43
  @socket = nil
48
44
  end
49
45
  end
50
46
 
51
47
  def connected?
52
- !@socket && @socket.closed?
48
+ @locket.synchronize do
49
+ !@socket.nil? && !@socket.closed?
50
+ end
53
51
  end
54
52
 
55
53
  # Read a message from a stream
@@ -63,12 +61,12 @@ module Riemann
63
61
  puts "Message was #{str.inspect}"
64
62
  raise
65
63
  end
66
-
64
+
67
65
  unless message.ok
68
66
  puts "Failed"
69
67
  raise ServerError, message.error
70
68
  end
71
-
69
+
72
70
  message
73
71
  else
74
72
  raise InvalidResponse, "unexpected EOF"
@@ -87,7 +85,7 @@ module Riemann
87
85
  # Yields a connection in the block.
88
86
  def with_connection
89
87
  tries = 0
90
-
88
+
91
89
  @locket.synchronize do
92
90
  begin
93
91
  tries += 1
@@ -3,27 +3,26 @@ module Riemann
3
3
  class UDP < Client
4
4
  MAX_SIZE = 16384
5
5
 
6
- attr_accessor :host, :port, :socket, :max_size
6
+ attr_accessor :host, :port, :max_size
7
7
 
8
8
  def initialize(opts = {})
9
- @host = opts[:host] || HOST
10
- @port = opts[:port] || PORT
9
+ @host = opts[:host] || HOST
10
+ @port = opts[:port] || PORT
11
11
  @max_size = opts[:max_size] || MAX_SIZE
12
- @locket = Mutex.new
13
12
  end
14
13
 
15
- def connect
14
+ def socket
15
+ return @socket if connected?
16
16
  @socket = UDPSocket.new
17
17
  end
18
18
 
19
19
  def close
20
- @locket.synchronize do
21
- @socket.close
22
- end
20
+ @socket.close if connected?
21
+ @socket = nil
23
22
  end
24
23
 
25
24
  def connected?
26
- !!@socket && @socket.closed?
25
+ @socket && !@socket.closed?
27
26
  end
28
27
 
29
28
  # Read a message from a stream
@@ -36,42 +35,10 @@ module Riemann
36
35
  end
37
36
 
38
37
  def send_maybe_recv(message)
39
- with_connection do |s|
40
- x = message.encode ''
41
- unless x.length < @max_size
42
- raise TooBig
43
- end
44
-
45
- s.send(x, 0, @host, @port)
46
- nil
47
- end
48
- end
49
-
50
- # Yields a connection in the block.
51
- def with_connection
52
- tries = 0
53
-
54
- @locket.synchronize do
55
- begin
56
- tries += 1
57
- yield(@socket || connect)
58
- rescue IOError => e
59
- raise if tries > 3
60
- connect and retry
61
- rescue Errno::EPIPE => e
62
- raise if tries > 3
63
- connect and retry
64
- rescue Errno::ECONNREFUSED => e
65
- raise if tries > 3
66
- connect and retry
67
- rescue Errno::ECONNRESET => e
68
- raise if tries > 3
69
- connect and retry
70
- rescue InvalidResponse => e
71
- raise if tries > 3
72
- connect and retry
73
- end
74
- end
38
+ encoded_string = message.encode.to_s
39
+ raise TooBig unless encoded_string.length < @max_size
40
+ socket.send(encoded_string, 0, @host, @port)
41
+ nil
75
42
  end
76
43
  end
77
44
  end
@@ -1,7 +1,7 @@
1
1
  module Riemann
2
2
  class Message
3
3
  include Beefcake::Message
4
-
4
+
5
5
  optional :ok, :bool, 2
6
6
  optional :error, :string, 3
7
7
  repeated :states, State, 4
@@ -9,9 +9,8 @@ module Riemann
9
9
  repeated :events, Event, 6
10
10
 
11
11
  def encode_with_length
12
- buffer = ''
13
- encoded = encode buffer
14
- "#{[encoded.length].pack('N')}#{encoded}"
12
+ encoded_string = encode.to_s
13
+ [encoded_string.length].pack('N') << encoded_string
15
14
  end
16
- end
15
+ end
17
16
  end
@@ -1,3 +1,3 @@
1
1
  module Riemann
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,55 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Kyle Kingsbury
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
12
+ date: 2015-02-03 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: beefcake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 0.3.5
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.3.5
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: trollop
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: 1.16.2
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: 1.16.2
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: mtrc
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: 0.0.4
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 0.0.4
55
62
  description:
@@ -75,25 +82,26 @@ files:
75
82
  - README.markdown
76
83
  homepage: https://github.com/aphyr/riemann-ruby-client
77
84
  licenses: []
78
- metadata: {}
79
85
  post_install_message:
80
86
  rdoc_options: []
81
87
  require_paths:
82
88
  - lib
83
89
  required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
84
91
  requirements:
85
- - - '>='
92
+ - - ! '>='
86
93
  - !ruby/object:Gem::Version
87
94
  version: 1.8.7
88
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
89
97
  requirements:
90
- - - '>='
98
+ - - ! '>='
91
99
  - !ruby/object:Gem::Version
92
100
  version: '0'
93
101
  requirements: []
94
102
  rubyforge_project: riemann-client
95
- rubygems_version: 2.0.14
103
+ rubygems_version: 1.8.25
96
104
  signing_key:
97
- specification_version: 4
105
+ specification_version: 3
98
106
  summary: Client for the distributed event system Riemann.
99
107
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 971fad804164c0db71b3e689d9b866ad89a20e41
4
- data.tar.gz: 1e7f35daae4ab58fa8018225959da905bfd5f77b
5
- SHA512:
6
- metadata.gz: 904df6b31de7feda767274d2a776040287d2b3849280257abd5b167171adf990812b5deabfdde8a48a220b329564476c93a844bb195a11655736578784c84a3c
7
- data.tar.gz: 3ccaa03c50e24502eee6e9e440279a1d5989b776f70ad04536654e3c887c3f14fb841502593fb84d3dbd9256749a7babb6870d4a7f4f9eb1c259f23f39b5e14f