modern_times 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.rdoc +114 -80
  2. data/VERSION +1 -1
  3. data/examples/advanced_requestor/README +15 -0
  4. data/examples/advanced_requestor/base_request_worker.rb +13 -0
  5. data/examples/advanced_requestor/char_count_worker.rb +11 -0
  6. data/examples/advanced_requestor/exception_raiser_worker.rb +10 -0
  7. data/examples/advanced_requestor/length_worker.rb +9 -0
  8. data/examples/advanced_requestor/manager.rb +22 -0
  9. data/examples/advanced_requestor/modern_times.yml +32 -0
  10. data/examples/advanced_requestor/print_worker.rb +9 -0
  11. data/examples/advanced_requestor/publish.rb +46 -0
  12. data/examples/advanced_requestor/reverse_worker.rb +9 -0
  13. data/examples/advanced_requestor/triple_worker.rb +9 -0
  14. data/examples/requestor/request.rb +3 -3
  15. data/examples/requestor/reverse_echo_worker.rb +1 -2
  16. data/lib/modern_times.rb +1 -1
  17. data/lib/modern_times/base/supervisor.rb +2 -0
  18. data/lib/modern_times/base/worker.rb +5 -3
  19. data/lib/modern_times/jms.rb +2 -0
  20. data/lib/modern_times/jms/connection.rb +7 -0
  21. data/lib/modern_times/jms/publish_handle.rb +219 -0
  22. data/lib/modern_times/jms/publisher.rb +55 -29
  23. data/lib/modern_times/{jms_requestor/worker.rb → jms/request_worker.rb} +29 -51
  24. data/lib/modern_times/jms/supervisor.rb +30 -0
  25. data/lib/modern_times/jms/supervisor_mbean.rb +17 -1
  26. data/lib/modern_times/jms/worker.rb +43 -40
  27. data/lib/modern_times/manager.rb +6 -2
  28. data/lib/modern_times/marshal_strategy.rb +14 -17
  29. data/lib/modern_times/marshal_strategy/bson.rb +2 -0
  30. data/lib/modern_times/marshal_strategy/json.rb +3 -0
  31. data/lib/modern_times/marshal_strategy/ruby.rb +3 -0
  32. data/lib/modern_times/marshal_strategy/string.rb +3 -0
  33. data/lib/modern_times/marshal_strategy/yaml.rb +3 -0
  34. data/lib/modern_times/railsable.rb +7 -14
  35. data/lib/modern_times/time_track.rb +84 -0
  36. data/test/jms.yml +1 -0
  37. data/test/jms_failure_test.rb +128 -0
  38. data/test/jms_requestor_block_test.rb +275 -0
  39. data/test/jms_requestor_test.rb +71 -96
  40. data/test/jms_test.rb +59 -78
  41. data/test/marshal_strategy_test.rb +1 -3
  42. metadata +29 -14
  43. data/examples/exception_test/bar_worker.rb +0 -8
  44. data/examples/exception_test/base_worker.rb +0 -23
  45. data/examples/exception_test/manager.rb +0 -11
  46. data/lib/modern_times/jms_requestor.rb +0 -10
  47. data/lib/modern_times/jms_requestor/request_handle.rb +0 -42
  48. data/lib/modern_times/jms_requestor/requestor.rb +0 -56
  49. data/lib/modern_times/jms_requestor/supervisor.rb +0 -45
  50. data/lib/modern_times/jms_requestor/supervisor_mbean.rb +0 -21
@@ -22,7 +22,7 @@ module SpockMarshalStrategy
22
22
  (i.to_i * 24).to_s
23
23
  end
24
24
 
25
- # Change days to hours
25
+ # Change hours to days
26
26
  def self.unmarshal(str)
27
27
  str.to_i / 24
28
28
  end
@@ -39,7 +39,6 @@ class MarshalStrategyTest < Test::Unit::TestCase
39
39
  @string = ModernTimes::MarshalStrategy.find(:string)
40
40
  @yaml = ModernTimes::MarshalStrategy.find(:string)
41
41
  @spock = ModernTimes::MarshalStrategy.find(:spock)
42
- @spock2 = ModernTimes::MarshalStrategy.find(SpockMarshalStrategy)
43
42
  end
44
43
 
45
44
  should 'marshal and unmarshal correctly' do
@@ -53,7 +52,6 @@ class MarshalStrategyTest < Test::Unit::TestCase
53
52
  assert_equal str, @string.unmarshal(@string.marshal(str))
54
53
  assert_equal obj.hello, @ruby.unmarshal(@ruby.marshal(obj)).hello
55
54
  assert_equal i, @spock.unmarshal(@spock.marshal(i))
56
- assert_equal i, @spock2.unmarshal(@spock2.marshal(i))
57
55
  end
58
56
  end
59
57
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: modern_times
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.11
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brad Pardee
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-04 00:00:00 -04:00
14
+ date: 2011-05-17 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -53,6 +53,17 @@ files:
53
53
  - Rakefile
54
54
  - VERSION
55
55
  - examples/README
56
+ - examples/advanced_requestor/README
57
+ - examples/advanced_requestor/base_request_worker.rb
58
+ - examples/advanced_requestor/char_count_worker.rb
59
+ - examples/advanced_requestor/exception_raiser_worker.rb
60
+ - examples/advanced_requestor/length_worker.rb
61
+ - examples/advanced_requestor/manager.rb
62
+ - examples/advanced_requestor/modern_times.yml
63
+ - examples/advanced_requestor/print_worker.rb
64
+ - examples/advanced_requestor/publish.rb
65
+ - examples/advanced_requestor/reverse_worker.rb
66
+ - examples/advanced_requestor/triple_worker.rb
56
67
  - examples/consumer/consumer.rb
57
68
  - examples/jms.yml
58
69
  - examples/requestor/.gitignore
@@ -74,16 +85,12 @@ files:
74
85
  - lib/modern_times/jms.rb
75
86
  - lib/modern_times/jms/connection.rb
76
87
  - lib/modern_times/jms/consumer.rb
88
+ - lib/modern_times/jms/publish_handle.rb
77
89
  - lib/modern_times/jms/publisher.rb
90
+ - lib/modern_times/jms/request_worker.rb
78
91
  - lib/modern_times/jms/supervisor.rb
79
92
  - lib/modern_times/jms/supervisor_mbean.rb
80
93
  - lib/modern_times/jms/worker.rb
81
- - lib/modern_times/jms_requestor.rb
82
- - lib/modern_times/jms_requestor/request_handle.rb
83
- - lib/modern_times/jms_requestor/requestor.rb
84
- - lib/modern_times/jms_requestor/supervisor.rb
85
- - lib/modern_times/jms_requestor/supervisor_mbean.rb
86
- - lib/modern_times/jms_requestor/worker.rb
87
94
  - lib/modern_times/loggable.rb
88
95
  - lib/modern_times/manager.rb
89
96
  - lib/modern_times/manager_mbean.rb
@@ -95,14 +102,14 @@ files:
95
102
  - lib/modern_times/marshal_strategy/yaml.rb
96
103
  - lib/modern_times/railsable.rb
97
104
  - lib/modern_times/remote_exception.rb
105
+ - lib/modern_times/time_track.rb
98
106
  - test/base_test.rb
99
107
  - test/jms.yml
108
+ - test/jms_failure_test.rb
109
+ - test/jms_requestor_block_test.rb
100
110
  - test/jms_requestor_test.rb
101
111
  - test/jms_test.rb
102
112
  - test/marshal_strategy_test.rb
103
- - examples/exception_test/bar_worker.rb
104
- - examples/exception_test/base_worker.rb
105
- - examples/exception_test/manager.rb
106
113
  has_rdoc: true
107
114
  homepage: http://github.com/ClarityServices/modern_times
108
115
  licenses: []
@@ -132,10 +139,16 @@ signing_key:
132
139
  specification_version: 3
133
140
  summary: Asynchronous task library
134
141
  test_files:
142
+ - examples/advanced_requestor/base_request_worker.rb
143
+ - examples/advanced_requestor/char_count_worker.rb
144
+ - examples/advanced_requestor/exception_raiser_worker.rb
145
+ - examples/advanced_requestor/length_worker.rb
146
+ - examples/advanced_requestor/manager.rb
147
+ - examples/advanced_requestor/print_worker.rb
148
+ - examples/advanced_requestor/publish.rb
149
+ - examples/advanced_requestor/reverse_worker.rb
150
+ - examples/advanced_requestor/triple_worker.rb
135
151
  - examples/consumer/consumer.rb
136
- - examples/exception_test/bar_worker.rb
137
- - examples/exception_test/base_worker.rb
138
- - examples/exception_test/manager.rb
139
152
  - examples/requestor/manager.rb
140
153
  - examples/requestor/request.rb
141
154
  - examples/requestor/reverse_echo_worker.rb
@@ -144,6 +157,8 @@ test_files:
144
157
  - examples/simple/manager.rb
145
158
  - examples/simple/publish.rb
146
159
  - test/base_test.rb
160
+ - test/jms_failure_test.rb
161
+ - test/jms_requestor_block_test.rb
147
162
  - test/jms_requestor_test.rb
148
163
  - test/jms_test.rb
149
164
  - test/marshal_strategy_test.rb
@@ -1,8 +0,0 @@
1
- require 'base_worker'
2
-
3
- class BarWorker < BaseWorker
4
-
5
- def perform
6
- raise "Raising my exception #{self.class.name}"
7
- end
8
- end
@@ -1,23 +0,0 @@
1
- class BaseWorker
2
- include ModernTimes::Base::Worker
3
-
4
- def start
5
- while true do
6
- sleep 1
7
- perform
8
- end
9
- rescue Exception => e
10
- puts "Caught #{e.inspect}"
11
- end
12
-
13
- def perform
14
- raise "Need to override perform method in #{self.class.name}"
15
- end
16
-
17
- def stop
18
- end
19
-
20
- def status
21
- "Need to override status method in #{self.class.name}"
22
- end
23
- end
@@ -1,11 +0,0 @@
1
- # Allow examples to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
3
-
4
- require 'rubygems'
5
- require 'modern_times'
6
- require 'bar_worker'
7
-
8
- manager = ModernTimes::Manager.new
9
- manager.stop_on_signal
10
- manager.add(BarWorker, 2, {})
11
- manager.join
@@ -1,10 +0,0 @@
1
- require 'modern_times/jms_requestor/request_handle'
2
- require 'modern_times/jms_requestor/requestor'
3
- require 'modern_times/jms_requestor/supervisor_mbean'
4
- require 'modern_times/jms_requestor/supervisor'
5
- require 'modern_times/jms_requestor/worker'
6
-
7
- module ModernTimes
8
- module JMSRequestor
9
- end
10
- end
@@ -1,42 +0,0 @@
1
- require 'timeout'
2
- require 'yaml'
3
-
4
- module ModernTimes
5
- module JMSRequestor
6
- class RequestHandle
7
- def initialize(requestor, jms_message_id, start, timeout, &reconstruct_block)
8
- @requestor = requestor
9
- @reply_queue = requestor.reply_queue
10
- @jms_message_id = jms_message_id
11
- @start = start
12
- @timeout = timeout
13
- @reconstruct_block = reconstruct_block
14
- end
15
-
16
- def read_response
17
- response = nil
18
- opts = { :destination => @reply_queue, :selector => "JMSCorrelationID = '#{@jms_message_id}'" }
19
- #opts = { :destination => @reply_queue }
20
- #opts = {:queue_name => 'foobarzulu'}
21
- ModernTimes::JMS::Connection.session_pool.consumer(opts) do |session, consumer|
22
- leftover_timeout = ((@start + @timeout - Time.now) * 1000).to_i
23
- if leftover_timeout > 100
24
- response = consumer.receive(leftover_timeout)
25
- else
26
- #response = consumer.receive_no_wait
27
- response = consumer.receive(100)
28
- end
29
- end
30
- raise Timeout::Error, "Timeout waiting for for response from message #{@jms_message_id} on queue #{@reply_queue}" unless response
31
- if error_yaml = response['Exception']
32
- raise ModernTimes::RemoteException.from_hash(YAML.load(error_yaml))
33
- end
34
- response = @requestor.marshaler.unmarshal(response.data)
35
- if @reconstruct_block
36
- response = @reconstruct_block.call(response)
37
- end
38
- return response
39
- end
40
- end
41
- end
42
- end
@@ -1,56 +0,0 @@
1
- module ModernTimes
2
- module JMSRequestor
3
- class Requestor < ModernTimes::JMS::Publisher
4
- attr_reader :reply_queue
5
-
6
- @@dummy_requesting = false
7
-
8
- def initialize(options)
9
- super
10
- return if @@dummy_requesting
11
- raise "ModernTimes::JMS::Connection has not been initialized" unless ModernTimes::JMS::Connection.inited?
12
- ModernTimes::JMS::Connection.session_pool.session do |session|
13
- @reply_queue = session.create_destination(:queue_name => :temporary)
14
- end
15
- end
16
-
17
- def request(object, timeout, &reconstruct_block)
18
- start = Time.now
19
- jms_message_id = publish(object, :jms_reply_to => @reply_queue)
20
- return RequestHandle.new(self, jms_message_id, start, timeout, &reconstruct_block)
21
- end
22
-
23
- # For non-configured Rails projects, The above request method will be overridden to
24
- # call this request method instead which calls all the JMS workers that
25
- # operate on the given address.
26
- def dummy_request(object, timeout, &reconstruct_block)
27
- @@worker_instances.each do |worker|
28
- if worker.kind_of?(Worker) && ModernTimes::JMS.same_destination?(producer_options, worker.class.destination_options)
29
- ModernTimes.logger.debug "Dummy requesting #{object} to #{worker}"
30
- response = worker.request(object)
31
- if reconstruct_block
32
- response = reconstruct_block.call(response)
33
- end
34
- return OpenStruct.new(:read_response => response)
35
- end
36
- end
37
- raise "No worker to handle #{address} request of #{object}"
38
- end
39
-
40
- def self.setup_dummy_requesting(workers)
41
- require 'ostruct'
42
- @@dummy_requesting = true
43
- @@worker_instances = workers.map {|worker| worker.new}
44
- alias_method :real_request, :request
45
- alias_method :request, :dummy_request
46
- end
47
-
48
- # For testing
49
- def self.clear_dummy_requesting
50
- @@dummy_requesting = false
51
- alias_method :dummy_request, :request
52
- alias_method :request, :real_request
53
- end
54
- end
55
- end
56
- end
@@ -1,45 +0,0 @@
1
- module ModernTimes
2
- module JMSRequestor
3
- class Supervisor < ModernTimes::JMS::Supervisor
4
-
5
- def initialize(manager, worker_name, supervisor_options, worker_options)
6
- super
7
- end
8
-
9
- def average_response_time
10
- count = 0
11
- total = 0.0
12
- workers.each do |w|
13
- pair = w.total_time
14
- count += pair.first
15
- total += pair.last
16
- end
17
- return 0.0 if count == 0
18
- return total / count
19
- end
20
-
21
- def min_response_time
22
- min_time = nil
23
- workers.each do |w|
24
- wmin_time = w.min_time
25
- min_time = wmin_time if wmin_time && (!min_time || wmin_time < min_time)
26
- end
27
- return min_time || 0.0
28
- end
29
-
30
- def max_response_time
31
- max_time = 0.0
32
- workers.each do |w|
33
- wmax_time = w.max_time
34
- max_time = wmax_time if wmax_time > max_time
35
- end
36
- return max_time
37
- end
38
-
39
- # Make JMSRequestor::SupervisorMBean our mbean
40
- def create_mbean(domain)
41
- SupervisorMBean.new(mbean_name(domain), mbean_description, self, {})
42
- end
43
- end
44
- end
45
- end
@@ -1,21 +0,0 @@
1
- module ModernTimes
2
- module JMSRequestor
3
- class SupervisorMBean < ModernTimes::JMS::SupervisorMBean
4
- r_attribute :average_response_time, :float, 'Average response time', :average_response_time
5
- r_attribute :min_response_time, :float, 'Minimum response time', :min_response_time
6
- r_attribute :max_response_time, :float, 'Maximum response time', :max_response_time
7
-
8
- def average_response_time
9
- supervisor.average_response_time
10
- end
11
-
12
- def min_response_time
13
- supervisor.min_response_time
14
- end
15
-
16
- def max_response_time
17
- supervisor.max_response_time
18
- end
19
- end
20
- end
21
- end