omf_common 6.0.6 → 6.0.7

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
- MDhiNzEzYjc1OTczZmI5NGM4OTg2YjBjODM0Zjk0NWQxYTJiNTgzNA==
4
+ OTdlZmJkZTY0ODNlZWZhNzQ2N2Y3NWYyYjMwNjBiOTRhYzFjNGE0NQ==
5
5
  data.tar.gz: !binary |-
6
- OTE2MzRhMjBlYzhiMDU0MTA4OTY1YTQ0ODFjN2RmNmQ5NTlkOWY4Ng==
6
+ MDkzNTdhZWMyNGFmNGYxNTIxZjAwM2RkZjY0NTI1ODk2YjQ0MWEzOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGViOWZiYmZjZDIyMzY0Y2ZiZDUxZjQ1M2I0ZjAwNWViMTM3Y2JlOTIyYTg0
10
- MjgwNzE1NjM3OTQ5NWQxNTFmM2I3MzM4OWU5MGFmOGUzYjM1OWFlMTg0ZjYz
11
- ZjAzMDQzZTgzNjM4YjE3YjJhOGY5NTE4ZDQ0MDRmMWQwNzhlMGU=
9
+ MGJjYmQwOTIxODViYjZhYjg0YTBlMDI5MzkxODc1MTUxMDgwNWRkMTdiMWNi
10
+ ZTNiOGVlY2Y4N2QwZjQ3ZjQyN2NkY2I1YWUxOGUxMjA1NGUwZjQzNTVkNmJh
11
+ ZDE4NTBiMGMzYjU0ODA5NjY3MmM5ZmUwNjMzOWJlMjVmNmQ4ODM=
12
12
  data.tar.gz: !binary |-
13
- MzY3ZmY1NjkzMjg1YjMyMGNkZWM0YzdkZTM2Njc3YjFhZTAzYzdhMjI3NWU4
14
- MjE2NGZkZTMxNjc5MGE4MGQyODQ1MjM1ZmRmZDU4YzEzNDQ4NDRiZWEzM2E4
15
- OTFhNjg4YjZhOTkwNzM1OTNiYzAxMDE1ZTZlMDg3ZDEwMDU4NzQ=
13
+ NjQ5NWI2YmY2MTFkNWQzM2U4ZjU3YmQ2NjBjOTFjZmEyNDJjOThiZGExZDcx
14
+ NDg3ZTllN2EwOGUzY2NmYTE3OGUzN2RkODcxZDM5YjNjZjhlOWRmYmYxZDM0
15
+ MmQ2NTMxZDY1NTAzMjcwZDlmZjdkZjc1NTY0YWJmZmFiZWE5YWQ=
@@ -3,12 +3,14 @@
3
3
  # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
+ require 'blather'
6
7
  require 'blather/client/dsl'
7
8
 
8
9
  require 'omf_common/comm/xmpp/xmpp_mp'
9
10
  require 'omf_common/comm/xmpp/topic'
10
11
  require 'uri'
11
12
  require 'socket'
13
+ require 'monitor'
12
14
 
13
15
  module Blather
14
16
  class Stream
@@ -20,6 +22,12 @@ module Blather
20
22
  @client.unbind
21
23
  end
22
24
  end
25
+
26
+ class Client
27
+ def state
28
+ @state
29
+ end
30
+ end
23
31
  end
24
32
 
25
33
  module OmfCommon
@@ -31,8 +39,8 @@ class Comm
31
39
  attr_accessor :published_messages, :normal_shutdown_mode, :retry_counter
32
40
 
33
41
  HOST_PREFIX = 'pubsub'
34
- RETRY_INTERVAL = 5
35
- PING_INTERVAL = 5
42
+ RETRY_INTERVAL = 180
43
+ PING_INTERVAL = 1800
36
44
 
37
45
  PUBSUB_CONFIGURE = Blather::Stanza::X.new({
38
46
  :type => :submit,
@@ -61,6 +69,8 @@ class Comm
61
69
  # Set up XMPP options and start the Eventmachine, connect to XMPP server
62
70
  #
63
71
  def init(opts = {})
72
+ @lock = Monitor.new
73
+
64
74
  @pubsub_host = opts[:pubsub_domain]
65
75
  if opts[:url]
66
76
  url = URI(opts[:url])
@@ -79,34 +89,56 @@ class Comm
79
89
 
80
90
  @retry_counter = 0
81
91
  @normal_shutdown_mode = false
82
- @pong = true
83
92
 
93
+ username.downcase!
94
+ jid = "#{username}@#{server}"
95
+ client.setup(jid, password)
84
96
  connect(username, password, server)
85
97
 
86
98
  when_ready do
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
99
+ if @not_initial_connection
100
+ info "Reconnected"
101
+ else
102
+ info "Connected"
103
+ @cbks[:connected].each { |cbk| cbk.call(self) }
104
+ # It will be reconnection after this
105
+ @lock.synchronize do
93
106
  @not_initial_connection = true
94
- OmfCommon.el.after(RETRY_INTERVAL) do
95
- client.run
107
+ end
108
+ end
109
+
110
+ @lock.synchronize do
111
+ @pong = true
112
+ @ping_alive_timer = OmfCommon.el.every(PING_INTERVAL) do
113
+ if @pong
114
+ @lock.synchronize do
115
+ @pong = false # Reset @pong
116
+ end
117
+ ping_alive
118
+ else
119
+ warn "No PONG. No connection..."
120
+ @lock.synchronize do
121
+ @ping_alive_timer.cancel
122
+ end
123
+ connect(username, password, server)
96
124
  end
97
125
  end
98
126
  end
99
- info "Reconnected" if @not_initial_connection
100
- @cbks[:connected].each { |cbk| cbk.call(self) } unless @not_initial_connection
101
127
  end
102
128
 
103
129
  disconnected do
130
+ @lock.synchronize do
131
+ @pong = false # Reset @pong
132
+ @ping_alive_timer && @ping_alive_timer.cancel
133
+ end
134
+
104
135
  if normal_shutdown_mode
105
136
  shutdown
106
137
  else
107
- warn "No connection..."
108
- OmfCommon.el.after(RETRY_INTERVAL) do
109
- client.run
138
+ warn "Disconnected... Last known state: #{client.state}"
139
+ retry_interval = client.state == :initializing ? 0 : RETRY_INTERVAL
140
+ OmfCommon.el.after(retry_interval) do
141
+ connect(username, password, server)
110
142
  end
111
143
  end
112
144
  end
@@ -121,11 +153,9 @@ class Comm
121
153
  #
122
154
  def connect(username, password, server)
123
155
  info "Connecting to '#{server}' ..."
124
- jid = "#{username}@#{server}"
125
- client.setup(jid, password)
126
156
  begin
127
157
  client.run
128
- rescue ::EventMachine::ConnectionError => e
158
+ rescue ::EventMachine::ConnectionError, Blather::Stream::ConnectionTimeout, Blather::Stream::NoConnection, Blather::Stream::ConnectionFailed => e
129
159
  warn "[#{e.class}] #{e}, try again..."
130
160
  OmfCommon.el.after(RETRY_INTERVAL) do
131
161
  connect(username, password, server)
@@ -136,7 +166,9 @@ class Comm
136
166
  # Shut down XMPP connection
137
167
  def disconnect(opts = {})
138
168
  # NOTE Do not clean up
139
- @normal_shutdown_mode = true
169
+ @lock.synchronize do
170
+ @normal_shutdown_mode = true
171
+ end
140
172
  info "Disconnecting..."
141
173
  shutdown
142
174
  OmfCommon::DSL::Xmpp::MPConnection.inject(Time.now.to_f, jid, 'disconnect') if OmfCommon::Measure.enabled?
@@ -261,13 +293,10 @@ class Comm
261
293
  end
262
294
 
263
295
  def ping_alive
264
- @pong = false
265
296
  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
297
+ info response
298
+ @lock.synchronize do
299
+ @pong = true
271
300
  end
272
301
  end
273
302
  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.6"
7
+ VERSION = "6.0.7"
8
8
  PROTOCOL_VERSION = "6.0"
9
9
  end
data/omf_common.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency "mocha"
29
29
 
30
30
  s.add_runtime_dependency "eventmachine", "= 1.0.3"
31
- s.add_runtime_dependency "blather", "= 0.8.4"
31
+ s.add_runtime_dependency "blather", "= 0.8.7"
32
32
  s.add_runtime_dependency "logging", "~> 1.7.1"
33
33
  s.add_runtime_dependency "hashie", "~> 1.2.0"
34
34
  s.add_runtime_dependency "oml4r", "~> 2.9.5"
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.6
4
+ version: 6.0.7
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-16 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.8.4
103
+ version: 0.8.7
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.8.4
110
+ version: 0.8.7
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: logging
113
113
  requirement: !ruby/object:Gem::Requirement