activemessaging 0.10.0 → 0.11.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.0
1
+ 0.11.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "activemessaging"
8
- s.version = "0.10.0"
8
+ s.version = "0.11.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jon Tirsen", "Andrew Kuklewicz", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", "Uwe Kubosch"]
12
- s.date = "2012-07-13"
12
+ s.date = "2012-08-07"
13
13
  s.description = "ActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc. Now supporting Rails 3 as of version 0.8.0."
14
14
  s.email = "activemessaging-discuss@googlegroups.com"
15
15
  s.extra_rdoc_files = [
@@ -36,7 +36,7 @@ module ActiveMessaging
36
36
  end
37
37
 
38
38
  def self.app_root
39
- @@app_root ||= (ENV['APP_ROOT'] || (defined?(::Rails) && ::Rails.root) || ENV['RAILS_ROOT'] || File.dirname($0))
39
+ @@app_root ||= (ENV['APP_ROOT'] || (defined?(::Rails) && ::Rails.root) || ENV['RAILS_ROOT'] || File.expand_path(Dir.pwd))
40
40
  end
41
41
 
42
42
  def self.app_env
@@ -74,10 +74,10 @@ module ActiveMessaging
74
74
  end
75
75
 
76
76
  def self.load_processors(first=true)
77
- logger.info "ActiveMessaging: Loading #{app_root}/app/processors/application.rb" if first
78
- load "#{app_root}/app/processors/application.rb" if File.exist?("#{app_root}/app/processors/application.rb")
77
+ logger.info "ActiveMessaging: Loading #{app_root}/app/processors/application_processor.rb" if first
78
+ load "#{app_root}/app/processors/application_processor.rb" if File.exist?("#{app_root}/app/processors/application_processor.rb")
79
79
  Dir["#{app_root}/app/processors/*.rb"].each do |f|
80
- unless f.match(/\/application.rb/)
80
+ unless f.match(/\/application_processor.rb/)
81
81
  logger.info "ActiveMessaging: Loading #{f}" if first
82
82
  load f
83
83
  end
@@ -95,6 +95,20 @@ module ActiveMessaging
95
95
  send_messsage queue, message_body
96
96
  end
97
97
 
98
+ # def receive(options={})
99
+ # while true
100
+ # # this will try all the queues once, by priority
101
+ # # returns nil if nothing there
102
+ # message = receive_message(options)
103
+
104
+ # if message
105
+ # return message
106
+ # else
107
+ # sleep(poll_interval)
108
+ # end
109
+ # end
110
+ # end
111
+
98
112
  # new receive respects priorities
99
113
  def receive(options={})
100
114
  message = nil
@@ -49,8 +49,12 @@ module ActiveMessaging
49
49
  @guard.synchronize {
50
50
  dispatch Thread.current[:message]
51
51
  }
52
+ Thread.current[:message] = nil
53
+ else
54
+ # if there is no message at all, sleep
55
+ # maybe this should be configurable
56
+ sleep(1)
52
57
  end
53
- Thread.current[:message] = nil
54
58
  end
55
59
  Thread.pass
56
60
  end
@@ -63,7 +67,7 @@ module ActiveMessaging
63
67
  living = false
64
68
  @connection_threads.each { |name, thread| living ||= thread.alive? }
65
69
  @running = living
66
- sleep 1
70
+ sleep(1)
67
71
  end
68
72
  ActiveMessaging.logger.error "All connection threads have died..."
69
73
  rescue Interrupt
@@ -73,9 +73,16 @@ module ActiveMessaging
73
73
  # indicates to all busy workers not to pick up another messages, but does not interrupt
74
74
  # also indicates to the message receiver to stop getting more messages
75
75
  self.running = false
76
-
76
+
77
77
  # tell each waiting worker to shut down. Running ones will be allowed to finish
78
- workers.each { |w| w.terminate if w.alive? }
78
+ receiver.terminate! if receiver.alive?
79
+ logger.info "ActiveMessaging::ThreadedPoller receiver terminated"
80
+
81
+ workers.each { |w| w.terminate! if w.alive? }
82
+ logger.info "ActiveMessaging::ThreadedPoller workers terminated"
83
+
84
+
85
+ after(0) { signal(:shutdown) } if stopped?
79
86
  end
80
87
 
81
88
  # recursive method, uses celluloid 'after' to keep calling
@@ -105,16 +112,16 @@ module ActiveMessaging
105
112
  worker.terminate if worker.alive?
106
113
  if busy.empty?
107
114
  logger.info "all executed: signal stopped"
108
- self.terminate if alive?
115
+ after(0) { signal(:shutdown) }
109
116
  end
110
117
  end
111
118
  end
112
119
 
113
120
  def died(worker, reason)
114
- logger.info "uh oh, #{worker.inspect} died because of #{reason.class}"
115
121
  busy.delete(worker)
116
122
 
117
123
  if running
124
+ logger.info "uh oh, #{worker.inspect} died because of #{reason.class}"
118
125
  worker = Worker.new_link(current_actor)
119
126
  workers << worker
120
127
  receive(worker)
@@ -122,13 +129,13 @@ module ActiveMessaging
122
129
  logger.info "check to see if busy is empty: #{busy.inspect}"
123
130
  if busy.empty?
124
131
  logger.info "all died: signal stopped"
125
- after(0){ self.terminate } if alive?
132
+ after(0){ signal(:shutdown) }
126
133
  end
127
134
  end
128
135
  end
129
136
 
130
137
  def stopped?
131
- !alive? || (!running && busy.empty?)
138
+ (!running && busy.empty?)
132
139
  end
133
140
 
134
141
  def logger; ActiveMessaging.logger; end
@@ -153,20 +160,25 @@ module ActiveMessaging
153
160
  def receive(worker)
154
161
  return unless poller.running
155
162
 
163
+ # logger.debug("***** MessageReceiver calling receive")
156
164
  message = self.connection.receive(worker.options)
165
+ # logger.debug("***** MessageReceiver receive returned")
157
166
 
158
167
  if message
159
168
  logger.debug("ActiveMessaging::MessageReceiver.receive: message:'#{message.inspect}'")
160
169
  poller.dispatch!(message, worker)
161
170
  else
162
- self.terminate if !poller.running && alive?
171
+ if (!poller || !poller.alive? || !poller.running)
172
+ logger.debug("ActiveMessaging::MessageReceiver.receive: terminate")
173
+ self.terminate
174
+ end
163
175
  logger.debug("ActiveMessaging::MessageReceiver.receive: no message, retry in #{pause} sec")
164
176
  after(pause) { receive(worker) }
165
177
  end
166
178
 
167
179
  end
168
180
 
169
- def logger; ActiveMessaging.logger; end
181
+ def logger; ::ActiveMessaging.logger; end
170
182
  end
171
183
 
172
184
  class Worker
@@ -180,11 +192,16 @@ module ActiveMessaging
180
192
  end
181
193
 
182
194
  def execute(message)
183
- ActiveMessaging::Gateway.dispatch(message)
195
+ begin
196
+ ::ActiveMessaging::Gateway.dispatch(message)
197
+ ensure
198
+ ::ActiveRecord::Base.clear_active_connections! if defined?(::ActiveRecord)
199
+ end
200
+
184
201
  poller.executed!(current_actor)
185
202
  end
186
203
 
187
- def logger; ActiveMessaging.logger; end
204
+ def logger; ::ActiveMessaging.logger; end
188
205
 
189
206
  end
190
207
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemessaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-07-13 00:00:00.000000000 Z
17
+ date: 2012-08-07 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport