omf_common 6.0.5 → 6.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjQwYWI3ZWUzZGQwNTU5ZmRhOGYzMTE1ZjE0ODVlZTQ0ZTQ3ODAxMw==
4
+ MDhiNzEzYjc1OTczZmI5NGM4OTg2YjBjODM0Zjk0NWQxYTJiNTgzNA==
5
5
  data.tar.gz: !binary |-
6
- ZDRkNTMxZWY0MGE1MTkzZGZkYzU5MDk4NGQ1NWM4MGIxODEyYThmMA==
6
+ OTE2MzRhMjBlYzhiMDU0MTA4OTY1YTQ0ODFjN2RmNmQ5NTlkOWY4Ng==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MmYxNWExZTZlZDViZmQ3OGMyMmJkNGU2ZGU5OWQyYjZjODE4NjRiMmE4ZTRj
10
- NWQ2YzNiNjFlMjBlOGYyMTU2YjkxYTg3OGNiZDg0MjNjODk3ODM1ZGJkMTg5
11
- MGI4MTJmZjA2OGQ5OTk5OWFiNzFmY2ExZDcyNmM0OTUwNzlhMzU=
9
+ NGViOWZiYmZjZDIyMzY0Y2ZiZDUxZjQ1M2I0ZjAwNWViMTM3Y2JlOTIyYTg0
10
+ MjgwNzE1NjM3OTQ5NWQxNTFmM2I3MzM4OWU5MGFmOGUzYjM1OWFlMTg0ZjYz
11
+ ZjAzMDQzZTgzNjM4YjE3YjJhOGY5NTE4ZDQ0MDRmMWQwNzhlMGU=
12
12
  data.tar.gz: !binary |-
13
- NTA1Yjc5M2Y1MGFlMDcxYWE1ZDE0NGUyMWIxZmU3ZWJhMzkyNTVjOTY1NTlm
14
- ZjcxZDA2YmM4Y2NhYjdhNjYxNjlmNzM0YzE3MjYxNGJjYTA2MWYzMjE5MTc2
15
- MjQ3NTRjMjU2NmU5MGU5NmM4M2UwOTg4MTE3MzQ4MmY2YWQ3MmE=
13
+ MzY3ZmY1NjkzMjg1YjMyMGNkZWM0YzdkZTM2Njc3YjFhZTAzYzdhMjI3NWU4
14
+ MjE2NGZkZTMxNjc5MGE4MGQyODQ1MjM1ZmRmZDU4YzEzNDQ4NDRiZWEzM2E4
15
+ OTFhNjg4YjZhOTkwNzM1OTNiYzAxMDE1ZTZlMDg3ZDEwMDU4NzQ=
@@ -10,6 +10,18 @@ require 'omf_common/comm/xmpp/topic'
10
10
  require 'uri'
11
11
  require 'socket'
12
12
 
13
+ module Blather
14
+ class Stream
15
+ def unbind
16
+ cleanup
17
+ raise NoConnection unless @inited
18
+ @state = :stopped
19
+ @client.receive_data @error if @error
20
+ @client.unbind
21
+ end
22
+ end
23
+ end
24
+
13
25
  module OmfCommon
14
26
  class Comm
15
27
  class XMPP
@@ -19,6 +31,8 @@ class Comm
19
31
  attr_accessor :published_messages, :normal_shutdown_mode, :retry_counter
20
32
 
21
33
  HOST_PREFIX = 'pubsub'
34
+ RETRY_INTERVAL = 5
35
+ PING_INTERVAL = 5
22
36
 
23
37
  PUBSUB_CONFIGURE = Blather::Stanza::X.new({
24
38
  :type => :submit,
@@ -65,24 +79,35 @@ class Comm
65
79
 
66
80
  @retry_counter = 0
67
81
  @normal_shutdown_mode = false
82
+ @pong = true
68
83
 
69
84
  connect(username, password, server)
70
85
 
71
86
  when_ready do
72
- @cbks[:connected].each { |cbk| cbk.call(self) }
87
+ @ping_alive_timer = OmfCommon.el.every(PING_INTERVAL) do
88
+ if @pong
89
+ ping_alive
90
+ else
91
+ warn "No connection..."
92
+ @ping_alive_timer.cancel
93
+ @not_initial_connection = true
94
+ OmfCommon.el.after(RETRY_INTERVAL) do
95
+ client.run
96
+ end
97
+ end
98
+ end
99
+ info "Reconnected" if @not_initial_connection
100
+ @cbks[:connected].each { |cbk| cbk.call(self) } unless @not_initial_connection
73
101
  end
74
102
 
75
103
  disconnected do
76
- unless normal_shutdown_mode
77
- unless retry_counter > 0
78
- @retry_counter += 1
79
- client.connect
80
- else
81
- error "Authentication failed."
82
- OmfCommon.eventloop.stop
83
- end
84
- else
104
+ if normal_shutdown_mode
85
105
  shutdown
106
+ else
107
+ warn "No connection..."
108
+ OmfCommon.el.after(RETRY_INTERVAL) do
109
+ client.run
110
+ end
86
111
  end
87
112
  end
88
113
 
@@ -98,15 +123,21 @@ class Comm
98
123
  info "Connecting to '#{server}' ..."
99
124
  jid = "#{username}@#{server}"
100
125
  client.setup(jid, password)
101
- client.run
102
- MPConnection.inject(Time.now.to_f, jid, 'connect') if OmfCommon::Measure.enabled?
126
+ begin
127
+ client.run
128
+ rescue ::EventMachine::ConnectionError => e
129
+ warn "[#{e.class}] #{e}, try again..."
130
+ OmfCommon.el.after(RETRY_INTERVAL) do
131
+ connect(username, password, server)
132
+ end
133
+ end
103
134
  end
104
135
 
105
136
  # Shut down XMPP connection
106
137
  def disconnect(opts = {})
107
138
  # NOTE Do not clean up
108
- info "Disconnecting ..."
109
139
  @normal_shutdown_mode = true
140
+ info "Disconnecting..."
110
141
  shutdown
111
142
  OmfCommon::DSL::Xmpp::MPConnection.inject(Time.now.to_f, jid, 'disconnect') if OmfCommon::Measure.enabled?
112
143
  end
@@ -228,6 +259,18 @@ class Comm
228
259
  def default_host
229
260
  @pubsub_host || "#{HOST_PREFIX}.#{jid.domain}"
230
261
  end
262
+
263
+ def ping_alive
264
+ @pong = false
265
+ client.write_with_handler Blather::Stanza::Iq::Ping.new(:get, jid.domain) do |response|
266
+ @pong = true
267
+ begin
268
+ handle_error response if response.is_a? Blather::BlatherError
269
+ rescue ProtocolError => e
270
+ raise unless e.name == :feature_not_implemented
271
+ end
272
+ end
273
+ end
231
274
  end
232
275
  end
233
276
  end
@@ -4,6 +4,6 @@
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
6
  module OmfCommon
7
- VERSION = "6.0.5"
7
+ VERSION = "6.0.6"
8
8
  PROTOCOL_VERSION = "6.0"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.5
4
+ version: 6.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICTA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest