pigato 0.2.13 → 0.2.14
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/examples/echo_client.rb +13 -29
- data/lib/pigato/client.rb +14 -15
- data/lib/pigato/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d98e3d33779bd55e21b6dd1ad0311e059ea142bf
|
4
|
+
data.tar.gz: f520a52c6ae420c5d59dbd60ff0761174bf56d5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31a112e4750fffd77b813e4787f01d0b4c4cc2ac8495cab8d9b944aa31323c7fc44daf2493178ded13d7348117a0c5b06cb519474d4f99fb7d506c244a483256
|
7
|
+
data.tar.gz: 90b78f68f1335be0a1356254f9b5c4abf29735923989ed4b71587b444290ee47e317a0a4c4cbccc379ae2d283c7dbd9ba9470c00a007fa7af997f2bb096557d2
|
data/examples/echo_client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'pry-remote'
|
2
3
|
|
3
4
|
require "rubygems"
|
4
5
|
require "#{File.dirname(__FILE__)}/../lib/pigato.rb"
|
@@ -7,34 +8,17 @@ require 'thread'
|
|
7
8
|
|
8
9
|
client = Pigato::Client.new('tcp://localhost:55555')
|
9
10
|
|
10
|
-
|
11
|
-
client.stop
|
12
|
-
client.start
|
13
|
-
requests = 1000
|
14
|
-
d1 = Time.now
|
15
|
-
requests.times do |i|
|
16
|
-
begin
|
17
|
-
client.request('echo', 'Hello world')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
d2 = Time.now
|
21
|
-
puts "#{requests} requests/replies processed (#{(d2 - d1) * 1000} milliseconds)"
|
22
|
-
}
|
23
|
-
|
24
|
-
c2 = Thread.new {
|
25
|
-
client.stop
|
26
|
-
client.start
|
27
|
-
requests = 1000
|
28
|
-
d1 = Time.now
|
29
|
-
requests.times do |i|
|
30
|
-
begin
|
31
|
-
client.request('echo', 'Hello world')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
d2 = Time.now
|
35
|
-
puts "#{requests} requests/replies processed (#{(d2 - d1) * 1000} milliseconds)"
|
36
|
-
}
|
11
|
+
#Process.daemon
|
37
12
|
|
13
|
+
#binding.remote_pry
|
38
14
|
|
39
|
-
|
40
|
-
|
15
|
+
client.start
|
16
|
+
requests = 1000
|
17
|
+
d1 = Time.now
|
18
|
+
requests.times do |i|
|
19
|
+
begin
|
20
|
+
client.request('echo', 'Hello world1')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
d2 = Time.now
|
24
|
+
puts "#{requests} requests/replies processed (#{(d2 - d1) * 1000} milliseconds)"
|
data/lib/pigato/client.rb
CHANGED
@@ -3,12 +3,8 @@ require 'thread'
|
|
3
3
|
class Pigato::Client
|
4
4
|
|
5
5
|
def initialize broker, conf = {}
|
6
|
-
@mtx = Mutex.new
|
7
6
|
@broker = broker
|
8
|
-
@
|
9
|
-
@ctx.linger = 0
|
10
|
-
|
11
|
-
@sockets = {}
|
7
|
+
@ctxs = {}
|
12
8
|
|
13
9
|
@conf = {
|
14
10
|
:autostart => false,
|
@@ -28,9 +24,10 @@ class Pigato::Client
|
|
28
24
|
end
|
29
25
|
|
30
26
|
def request service, request, opts = {}
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
return nil if @ctxs[getid()] == nil
|
28
|
+
|
29
|
+
socket = @ctxs[getid()]['socket']
|
30
|
+
|
34
31
|
request = [Oj.dump(request), Oj.dump(opts)]
|
35
32
|
|
36
33
|
rid = SecureRandom.uuid
|
@@ -53,7 +50,7 @@ class Pigato::Client
|
|
53
50
|
end
|
54
51
|
|
55
52
|
def _recv rid
|
56
|
-
socket = @
|
53
|
+
socket = @ctxs[getid()]['socket']
|
57
54
|
socket.rcvtimeo = @conf[:timeout]
|
58
55
|
data = []
|
59
56
|
d1 = Time.now
|
@@ -76,18 +73,20 @@ class Pigato::Client
|
|
76
73
|
|
77
74
|
def stop
|
78
75
|
tid = getid()
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
@
|
76
|
+
if @ctxs[tid]
|
77
|
+
@ctxs[tid]['socket'].close
|
78
|
+
@ctxs[tid]['ctx'].destroy
|
79
|
+
@ctxs.delete(tid)
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
86
83
|
def reconnect_to_broker
|
87
84
|
stop
|
88
|
-
|
85
|
+
ctx = ZMQ::Context.new
|
86
|
+
ctx.linger = 0
|
87
|
+
socket = ctx.socket ZMQ::DEALER
|
89
88
|
socket.identity = SecureRandom.uuid
|
90
89
|
socket.connect @broker
|
91
|
-
@
|
90
|
+
@ctxs[getid()] = { 'socket' => socket, 'ctx' => ctx }
|
92
91
|
end
|
93
92
|
end
|
data/lib/pigato/version.rb
CHANGED