qwirk 0.0.1 → 0.1.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/README.md +9 -14
- data/lib/qwirk.rb +26 -17
- data/lib/qwirk/adapter.rb +3 -45
- data/lib/qwirk/adapter/base.rb +2 -0
- data/lib/qwirk/adapter/base/expanding_worker_config.rb +133 -0
- data/lib/qwirk/adapter/base/worker_config.rb +104 -0
- data/lib/qwirk/adapter/in_memory.rb +13 -0
- data/lib/qwirk/{queue_adapter/in_mem → adapter/in_memory}/factory.rb +2 -2
- data/lib/qwirk/{queue_adapter/in_mem → adapter/in_memory}/publisher.rb +4 -4
- data/lib/qwirk/{queue_adapter/in_mem → adapter/in_memory}/queue.rb +3 -2
- data/lib/qwirk/{queue_adapter/in_mem → adapter/in_memory}/reply_queue.rb +3 -2
- data/lib/qwirk/{queue_adapter/in_mem → adapter/in_memory}/topic.rb +2 -2
- data/lib/qwirk/{queue_adapter/in_mem → adapter/in_memory}/worker.rb +6 -8
- data/lib/qwirk/adapter/in_memory/worker_config.rb +50 -0
- data/lib/qwirk/adapter/inline.rb +9 -0
- data/lib/qwirk/adapter/inline/publisher.rb +86 -0
- data/lib/qwirk/adapter/inline/worker.rb +55 -0
- data/lib/qwirk/adapter/inline/worker_config.rb +30 -0
- data/lib/qwirk/adapter_factory.rb +48 -0
- data/lib/qwirk/base_worker.rb +18 -28
- data/lib/qwirk/batch/file_worker.rb +4 -4
- data/lib/qwirk/manager.rb +11 -8
- data/lib/qwirk/marshal_strategy/none.rb +1 -1
- data/lib/qwirk/publish_handle.rb +22 -11
- data/lib/qwirk/publisher.rb +9 -9
- data/lib/qwirk/{request_worker.rb → reply_worker.rb} +3 -3
- data/lib/qwirk/worker.rb +27 -29
- data/test/jms_fail_test.rb +11 -11
- data/test/jms_requestor_block_test.rb +12 -12
- data/test/jms_requestor_test.rb +8 -8
- data/test/jms_test.rb +10 -10
- metadata +104 -185
- data/examples/README +0 -1
- data/examples/activemq.xml +0 -84
- data/examples/advanced_requestor/README.md +0 -15
- data/examples/advanced_requestor/base_request_worker.rb +0 -18
- data/examples/advanced_requestor/char_count_worker.rb +0 -16
- data/examples/advanced_requestor/config.ru +0 -24
- data/examples/advanced_requestor/exception_raiser_worker.rb +0 -17
- data/examples/advanced_requestor/length_worker.rb +0 -14
- data/examples/advanced_requestor/print_worker.rb +0 -14
- data/examples/advanced_requestor/publisher.rb +0 -49
- data/examples/advanced_requestor/qwirk.yml +0 -16
- data/examples/advanced_requestor/reverse_worker.rb +0 -14
- data/examples/advanced_requestor/triple_worker.rb +0 -14
- data/examples/batch/my_batch_worker.rb +0 -30
- data/examples/batch/my_line_worker.rb +0 -8
- data/examples/qwirk.yml +0 -20
- data/examples/requestor/README.md +0 -13
- data/examples/requestor/config.ru +0 -13
- data/examples/requestor/qwirk_persist.yml +0 -5
- data/examples/requestor/requestor.rb +0 -68
- data/examples/requestor/reverse_echo_worker.rb +0 -15
- data/examples/setup.rb +0 -13
- data/examples/shared/README.md +0 -24
- data/examples/shared/config.ru +0 -13
- data/examples/shared/publisher.rb +0 -49
- data/examples/shared/qwirk_persist.yml +0 -5
- data/examples/shared/shared_worker.rb +0 -16
- data/examples/simple/README +0 -53
- data/examples/simple/bar_worker.rb +0 -10
- data/examples/simple/baz_worker.rb +0 -10
- data/examples/simple/config.ru +0 -14
- data/examples/simple/publisher.rb +0 -49
- data/examples/simple/qwirk_persist.yml +0 -4
- data/examples/simple/tmp/kahadb/db-1.log +0 -0
- data/examples/simple/tmp/kahadb/db.data +0 -0
- data/examples/simple/tmp/kahadb/db.redo +0 -0
- data/examples/task/README +0 -47
- data/examples/task/config.ru +0 -14
- data/examples/task/foo_worker.rb +0 -10
- data/examples/task/messages.out +0 -1000
- data/examples/task/publisher.rb +0 -25
- data/examples/task/qwirk_persist.yml +0 -5
- data/examples/task/task.rb +0 -36
- data/lib/qwirk/queue_adapter.rb +0 -3
- data/lib/qwirk/queue_adapter/active_mq.rb +0 -13
- data/lib/qwirk/queue_adapter/active_mq/publisher.rb +0 -12
- data/lib/qwirk/queue_adapter/active_mq/worker_config.rb +0 -16
- data/lib/qwirk/queue_adapter/in_mem.rb +0 -7
- data/lib/qwirk/queue_adapter/in_mem/worker_config.rb +0 -59
- data/lib/qwirk/queue_adapter/jms.rb +0 -50
- data/lib/qwirk/queue_adapter/jms/connection.rb +0 -42
- data/lib/qwirk/queue_adapter/jms/consumer.rb +0 -37
- data/lib/qwirk/queue_adapter/jms/publisher.rb +0 -126
- data/lib/qwirk/queue_adapter/jms/worker.rb +0 -89
- data/lib/qwirk/queue_adapter/jms/worker_config.rb +0 -38
- data/lib/qwirk/version.rb +0 -3
- data/lib/qwirk/worker_config.rb +0 -187
data/README.md
CHANGED
@@ -4,23 +4,18 @@ http://github.com/ClarityServices/qwirk
|
|
4
4
|
|
5
5
|
## Description:
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Library for performing background tasks as well as asynchronous and parallel RPC calls
|
9
8
|
Alpha version. API still subject to change.
|
10
9
|
|
11
|
-
## Features/Problems:
|
12
|
-
|
13
|
-
Currently tested only for ActiveMQ
|
14
|
-
|
15
10
|
## Install:
|
16
11
|
|
17
12
|
gem install qwirk
|
18
13
|
|
19
14
|
## Rails Usage:
|
20
15
|
|
21
|
-
TODO: This stuff is all obsolete modern_times documentation. Look at the
|
16
|
+
TODO: This stuff is all obsolete modern_times documentation. Look at the project http://github.com/ClarityServices/qwirk_examples for usage information.
|
22
17
|
|
23
|
-
Create config/
|
18
|
+
Create config/qwirk.yml which might look as follows:
|
24
19
|
|
25
20
|
development_server: &defaults
|
26
21
|
:factory: org.apache.activemq.ActiveMQConnectionFactory
|
@@ -98,7 +93,7 @@ examples for registering marshal strategies):
|
|
98
93
|
|
99
94
|
Qwirk.init_rails
|
100
95
|
# Publishers can be defined wherever appropriate, probably as class variables within the class that uses it
|
101
|
-
$foo_publisher = Qwirk::
|
96
|
+
$foo_publisher = Qwirk::Adapter::JMS::Publisher.new('Foo')
|
102
97
|
|
103
98
|
When creating publishers, you will probably want to store the value in a class variable. Publishers internally
|
104
99
|
make use of a session pool for communicating with the JMS server so you wouldn't want to create a new connection
|
@@ -111,7 +106,7 @@ In your code, queue foo objects:
|
|
111
106
|
In app/workers, create a FooWorker class:
|
112
107
|
|
113
108
|
class FooWorker
|
114
|
-
include Qwirk::
|
109
|
+
include Qwirk::Adapter::JMS::Worker
|
115
110
|
def perform(my_foo_object)
|
116
111
|
# Operate on my_foo_object
|
117
112
|
end
|
@@ -137,7 +132,7 @@ receives all messages instead of a group of workers (threads) collectively recei
|
|
137
132
|
problem). For instance, suppose you have the following workers:
|
138
133
|
|
139
134
|
class FooWorker
|
140
|
-
include Qwirk::
|
135
|
+
include Qwirk::Adapter::JMS::Worker
|
141
136
|
virtual_topic 'inquiry'
|
142
137
|
|
143
138
|
def perform(my_inquiry)
|
@@ -146,7 +141,7 @@ problem). For instance, suppose you have the following workers:
|
|
146
141
|
end
|
147
142
|
|
148
143
|
class BarWorker
|
149
|
-
include Qwirk::
|
144
|
+
include Qwirk::Adapter::JMS::Worker
|
150
145
|
virtual_topic 'inquiry'
|
151
146
|
|
152
147
|
def perform(my_inquiry)
|
@@ -156,7 +151,7 @@ problem). For instance, suppose you have the following workers:
|
|
156
151
|
|
157
152
|
Then you can create a publisher where messages are delivered to both workers:
|
158
153
|
|
159
|
-
@@publisher = Qwirk::
|
154
|
+
@@publisher = Qwirk::Adapter::JMS::Publisher.new(:virtual_topic_name => 'inquiry')
|
160
155
|
...
|
161
156
|
@@publisher.publish(my_inquiry)
|
162
157
|
|
@@ -166,7 +161,7 @@ Then you can create a publisher where messages are delivered to both workers:
|
|
166
161
|
TODO: See examples/requestor
|
167
162
|
|
168
163
|
|
169
|
-
## Requestor Pattern with Multiple
|
164
|
+
## Requestor Pattern with Multiple ReplyWorkers:
|
170
165
|
|
171
166
|
TODO: See examples/advanced_requestor
|
172
167
|
|
data/lib/qwirk.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require 'qwirk/marshal_strategy'
|
4
|
-
require 'qwirk/base_worker'
|
5
|
-
require 'qwirk/worker_config'
|
6
|
-
require 'qwirk/worker'
|
7
|
-
require 'qwirk/request_worker'
|
8
|
-
require 'qwirk/task'
|
9
|
-
require 'qwirk/publisher'
|
10
|
-
require 'qwirk/publish_handle'
|
11
|
-
require 'qwirk/adapter'
|
12
|
-
require 'qwirk/queue_adapter'
|
13
|
-
#require 'qwirk/batch'
|
14
|
-
require 'qwirk/manager'
|
2
|
+
require 'rumx'
|
15
3
|
require 'qwirk/loggable'
|
16
4
|
|
17
5
|
module Qwirk
|
@@ -25,7 +13,8 @@ module Qwirk
|
|
25
13
|
class MyBean
|
26
14
|
include Rumx::Bean
|
27
15
|
|
28
|
-
|
16
|
+
# These are actually AdapterFactory's but presenting as adapters to the user.
|
17
|
+
bean_attr_reader :adapters, :hash, 'Adapters', :hash_type => :bean
|
29
18
|
|
30
19
|
def initialize(hash)
|
31
20
|
@adapters = hash
|
@@ -37,7 +26,7 @@ module Qwirk
|
|
37
26
|
Rumx::Bean.root.bean_add_child(DEFAULT_NAME, MyBean.new(@@hash))
|
38
27
|
end
|
39
28
|
|
40
|
-
def self.[](
|
29
|
+
def self.[](adapter_key)
|
41
30
|
if @@config.nil?
|
42
31
|
if defined?(Rails)
|
43
32
|
# Allow user to use JMS w/o modifying qwirk.yml which could be checked in and hose other users
|
@@ -51,8 +40,13 @@ module Qwirk
|
|
51
40
|
}
|
52
41
|
end
|
53
42
|
end
|
54
|
-
raise 'Qwirk not configured' unless @@config && @@config[
|
55
|
-
|
43
|
+
raise 'Qwirk not configured' unless @@config && @@config[adapter_key]
|
44
|
+
Qwirk.logger.debug {"Creating Qwirk::AdapterFactory key=#{adapter_key} config=#{@@config[adapter_key].inspect}"}
|
45
|
+
@@hash[adapter_key] ||= Qwirk::AdapterFactory.new(adapter_key, @@config[adapter_key])
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.register_adapter(key, publisher_class, worker_config_class, &block)
|
49
|
+
AdapterFactory.register(key, publisher_class, worker_config_class, &block)
|
56
50
|
end
|
57
51
|
|
58
52
|
def self.fail_queue_name(queue_name)
|
@@ -60,4 +54,19 @@ module Qwirk
|
|
60
54
|
end
|
61
55
|
end
|
62
56
|
|
57
|
+
# We have to define the above before we define the adapters so the Qwirk#register_adapter call will work
|
58
|
+
# AdapterFactory is also required before adapter for this reason.
|
59
|
+
require 'qwirk/adapter_factory'
|
60
|
+
require 'qwirk/adapter'
|
61
|
+
require 'qwirk/base_worker'
|
62
|
+
#require 'qwirk/batch'
|
63
|
+
require 'qwirk/manager'
|
64
|
+
require 'qwirk/marshal_strategy'
|
65
|
+
require 'qwirk/publish_handle'
|
66
|
+
require 'qwirk/publisher'
|
67
|
+
require 'qwirk/remote_exception'
|
68
|
+
require 'qwirk/task'
|
69
|
+
require 'qwirk/worker'
|
70
|
+
require 'qwirk/reply_worker'
|
71
|
+
|
63
72
|
require 'qwirk/engine' if defined?(Rails)
|
data/lib/qwirk/adapter.rb
CHANGED
@@ -1,45 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class Adapter
|
5
|
-
include Rumx::Bean
|
6
|
-
|
7
|
-
attr_reader :config, :log_times, :adapter_info
|
8
|
-
|
9
|
-
def initialize(config)
|
10
|
-
@config = config.dup
|
11
|
-
@log_times = config.delete(:log_times)
|
12
|
-
|
13
|
-
adapter = config.delete(:adapter)
|
14
|
-
raise "No adapter definition" unless adapter
|
15
|
-
namespace = Qwirk::QueueAdapter.const_get(adapter)
|
16
|
-
@adapter_info = nil
|
17
|
-
if namespace.respond_to?(:init)
|
18
|
-
@adapter_info = namespace.init(config)
|
19
|
-
end
|
20
|
-
@publisher_klass = namespace.const_get('Publisher')
|
21
|
-
@worker_config_klass = namespace.const_get('WorkerConfig')
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_publisher(options={})
|
25
|
-
@publisher_parent ||= Rumx::Beans::Folder.new
|
26
|
-
publisher = Publisher.new(self, @config.merge(options))
|
27
|
-
@publisher_parent.bean_add_child(publisher.to_s, publisher)
|
28
|
-
return publisher
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_manager(options={})
|
32
|
-
manager = Manager.new(self, @config.merge(options))
|
33
|
-
bean_add_child(:Workers, manager)
|
34
|
-
return manager
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_adapter_publisher(queue_name, topic_name, options, response_options)
|
38
|
-
@publisher_klass.new(self, queue_name, topic_name, options, response_options)
|
39
|
-
end
|
40
|
-
|
41
|
-
def create_adapter_worker_config(parent, queue_name, topic_name, options, response_options)
|
42
|
-
@worker_config_klass.new(self, parent, queue_name, topic_name, options, response_options)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
1
|
+
require 'qwirk/adapter/base'
|
2
|
+
require 'qwirk/adapter/inline'
|
3
|
+
require 'qwirk/adapter/in_memory'
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Qwirk
|
2
|
+
module Adapter
|
3
|
+
module Base
|
4
|
+
class ExpandingWorkerConfig < WorkerConfig
|
5
|
+
|
6
|
+
bean_reader :count, :integer, 'Current number of workers'
|
7
|
+
bean_attr_accessor :min_count, :integer, 'Min number of workers allowed', :config_item => true
|
8
|
+
bean_attr_accessor :max_count, :integer, 'Max number of workers allowed', :config_item => true
|
9
|
+
bean_attr_accessor :idle_worker_timeout, :integer, 'Timeout where an idle worker will be removed from the worker pool and it\'s resources closed (0 for no removal)', :config_item => true
|
10
|
+
bean_attr_accessor :max_read_threshold, :float, 'Threshold where a new worker will be added if none of the workers have had to wait this amount of time on a read', :config_item => true
|
11
|
+
|
12
|
+
# Define the default config values for the attributes all workers will share. These will be sent as options to the constructor
|
13
|
+
def self.initial_default_config
|
14
|
+
super.merge(:min_count => 0, :max_count => 0, :idle_worker_timeout => 60, :max_read_threshold => 1.0)
|
15
|
+
end
|
16
|
+
|
17
|
+
def init
|
18
|
+
super
|
19
|
+
@workers = []
|
20
|
+
@min_count = 0
|
21
|
+
@max_count = 0
|
22
|
+
@index_count = 0
|
23
|
+
@index_mutex = Mutex.new
|
24
|
+
@worker_mutex = Mutex.new
|
25
|
+
@worker_condition = ConditionVariable.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def count
|
29
|
+
@worker_mutex.synchronize { return @workers.size }
|
30
|
+
end
|
31
|
+
|
32
|
+
def min_count=(new_min_count)
|
33
|
+
return if @min_count == new_min_count
|
34
|
+
raise "#{self.worker_class.name}-#{self.name}: Can't change count since we've been stopped" if self.stopped
|
35
|
+
Qwirk.logger.info "#{self.worker_class.name}: Changing min number of workers from #{@min_count} to #{new_min_count}"
|
36
|
+
self.max_count = new_min_count if @max_count < new_min_count
|
37
|
+
@worker_mutex.synchronize do
|
38
|
+
add_worker while @workers.size < new_min_count
|
39
|
+
@min_count = new_min_count
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def max_count=(new_max_count)
|
44
|
+
return if @max_count == new_max_count
|
45
|
+
raise "#{self.worker_class.name}-#{self.name}: Can't change count since we've been stopped" if self.stopped
|
46
|
+
Qwirk.logger.info "#{self.worker_class.name}: Changing max number of workers from #{@max_count} to #{new_max_count}"
|
47
|
+
self.min_count = new_max_count if @min_count > new_max_count
|
48
|
+
@min_count = 1 if @min_count == 0 && new_max_count > 0
|
49
|
+
@worker_mutex.synchronize do
|
50
|
+
@timer ||= Rumx::Beans::TimerAndError.new
|
51
|
+
if @workers.size > new_max_count
|
52
|
+
@workers[new_max_count..-1].each { |worker| worker.stop }
|
53
|
+
while @workers.size > new_max_count
|
54
|
+
@workers.last.stop
|
55
|
+
@worker_condition.wait(@worker_mutex)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
@max_count = new_max_count
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def stop
|
63
|
+
Qwirk.logger.debug { "In expanding_worker_config stop" }
|
64
|
+
# First stop the impl. For InMemory, this will not return until all the messages in the queue have
|
65
|
+
# been processed since these messages are not persistent.
|
66
|
+
@impl.stop
|
67
|
+
@worker_mutex.synchronize do
|
68
|
+
@workers.each { |worker| worker.stop }
|
69
|
+
while @workers.size > 0
|
70
|
+
@worker_condition.wait(@worker_mutex)
|
71
|
+
end
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def worker_stopped(worker)
|
77
|
+
remove_worker(worker)
|
78
|
+
end
|
79
|
+
|
80
|
+
def periodic_call(poll_time)
|
81
|
+
now = Time.now
|
82
|
+
add_new_worker = true
|
83
|
+
worker_stopped = false
|
84
|
+
@worker_mutex.synchronize do
|
85
|
+
# reverse_each to remove later workers first
|
86
|
+
@workers.reverse_each do |worker|
|
87
|
+
start_worker_time = worker.start_worker_time
|
88
|
+
start_read_time = worker.start_read_time
|
89
|
+
if !start_read_time || (now - start_worker_time) < (poll_time + @max_read_threshold)
|
90
|
+
#Qwirk.logger.debug { "#{self}: Skipping newly created worker" }
|
91
|
+
add_new_worker = false
|
92
|
+
next
|
93
|
+
end
|
94
|
+
end_read_time = worker.start_processing_time
|
95
|
+
# If the processing time is actually from the previous processing, then we're probably still waiting for the read to complete.
|
96
|
+
if !end_read_time || end_read_time < start_read_time
|
97
|
+
if !worker_stopped && @workers.size > @min_count && (now - start_read_time) > @idle_worker_timeout
|
98
|
+
worker.stop
|
99
|
+
worker_stopped = true
|
100
|
+
end
|
101
|
+
end_read_time = now
|
102
|
+
end
|
103
|
+
#Qwirk.logger.debug { "#{self}: start=#{start_read_time} end=#{end_read_time} thres=#{@max_read_threshold} add_new_worker=#{add_new_worker}" }
|
104
|
+
add_new_worker = false if (end_read_time - start_read_time) > @max_read_threshold
|
105
|
+
end
|
106
|
+
add_worker if add_new_worker && @workers.size < @max_count
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def add_worker
|
113
|
+
worker = self.worker_class.new
|
114
|
+
worker.init(@index_count, self)
|
115
|
+
worker.start
|
116
|
+
Qwirk.logger.debug {"#{self}: Adding worker #{worker}"}
|
117
|
+
@index_mutex.synchronize { @index_count += 1 }
|
118
|
+
@workers << worker
|
119
|
+
rescue Exception => e
|
120
|
+
Qwirk.logger.error("Unable to add #{self.worker_class} worker: #{e.message}\n\t#{e.backtrace.join("\n\t")}")
|
121
|
+
end
|
122
|
+
|
123
|
+
def remove_worker(worker)
|
124
|
+
Qwirk.logger.debug {"#{self}: Deleting worker #{worker}"}
|
125
|
+
@worker_mutex.synchronize do
|
126
|
+
@workers.delete(worker)
|
127
|
+
@worker_condition.broadcast
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rumx'
|
2
|
+
|
3
|
+
module Qwirk
|
4
|
+
module Adapter
|
5
|
+
module Base
|
6
|
+
class WorkerConfig
|
7
|
+
include Rumx::Bean
|
8
|
+
|
9
|
+
# Make explicit the instance variables available to the derived adapter classes
|
10
|
+
attr_reader :adapter_factory, :name, :manager, :worker_class, :default_options, :options,
|
11
|
+
:stopped, :queue_options, :response_options, :marshaler
|
12
|
+
attr_accessor :queue_name, :topic_name
|
13
|
+
|
14
|
+
bean_attr_reader :timer, :bean, 'Track the times for this worker'
|
15
|
+
bean_attr_accessor :log_times, :boolean, 'Log the times for this worker'
|
16
|
+
|
17
|
+
# Define the default config values for the attributes all workers will share. These will be sent as options to the constructor
|
18
|
+
def self.initial_default_config
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.default_marshal_sym
|
23
|
+
:ruby
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create new WorkerConfig to manage workers of a common class
|
27
|
+
def initialize(adapter_factory, name, manager, worker_class, default_options, options)
|
28
|
+
@adapter_factory = adapter_factory
|
29
|
+
@name = name
|
30
|
+
@manager = manager
|
31
|
+
@worker_class = worker_class
|
32
|
+
@default_options = default_options
|
33
|
+
@options = options
|
34
|
+
@stopped = false
|
35
|
+
@queue_name = worker_class.queue_name(@name)
|
36
|
+
@topic_name = worker_class.topic_name
|
37
|
+
@queue_options = worker_class.queue_options
|
38
|
+
@response_options = @queue_options[:response] || {}
|
39
|
+
|
40
|
+
# Defines how we will marshal the response
|
41
|
+
marshal_sym = (response_options[:marshal] || self.class.default_marshal_sym)
|
42
|
+
@marshaler = MarshalStrategy.find(marshal_sym)
|
43
|
+
@log_times = adapter_factory.log_times
|
44
|
+
|
45
|
+
init
|
46
|
+
|
47
|
+
#Qwirk.logger.debug { "options=#{options.inspect}" }
|
48
|
+
default_options.each do |key, value|
|
49
|
+
begin
|
50
|
+
send(key.to_s+'=', value)
|
51
|
+
rescue Exception => e
|
52
|
+
# Let config_reader's set a default value
|
53
|
+
begin
|
54
|
+
instance_variable_set("@#{key}", value)
|
55
|
+
rescue Exception => e
|
56
|
+
Qwirk.logger.warn "WARNING: During initialization of #{worker_class.name} config=#{@name}, default assignment of #{key}=#{value} was invalid"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
# Run the specified options after the default options, so that codependant options don't get overwritten (like min_count/max_count)
|
61
|
+
options.each do |key, value|
|
62
|
+
begin
|
63
|
+
send(key.to_s+'=', value)
|
64
|
+
rescue Exception => e
|
65
|
+
Qwirk.logger.warn "WARNING: During initialization of #{worker_class.name} config=#{@name}, assignment of #{key}=#{value} was invalid"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Allow extensions to initialize before setting the attributes
|
71
|
+
def init
|
72
|
+
end
|
73
|
+
|
74
|
+
def stop
|
75
|
+
@stopped = true
|
76
|
+
end
|
77
|
+
|
78
|
+
def worker_stopped(worker)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Override rumx bean method
|
82
|
+
def bean_attributes_changed
|
83
|
+
super
|
84
|
+
@manager.save_persist_state
|
85
|
+
end
|
86
|
+
|
87
|
+
def marshal_response(object)
|
88
|
+
@marshaler.marshal(object)
|
89
|
+
end
|
90
|
+
|
91
|
+
def unmarshal_response(marshaled_object)
|
92
|
+
@marshaler.unmarshal(marshaled_object)
|
93
|
+
end
|
94
|
+
|
95
|
+
def periodic_call(poll_time)
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
@name
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'qwirk/adapter/in_memory/factory'
|
2
|
+
require 'qwirk/adapter/in_memory/publisher'
|
3
|
+
require 'qwirk/adapter/in_memory/queue'
|
4
|
+
require 'qwirk/adapter/in_memory/reply_queue'
|
5
|
+
require 'qwirk/adapter/in_memory/topic'
|
6
|
+
require 'qwirk/adapter/in_memory/worker_config'
|
7
|
+
require 'qwirk/adapter/in_memory/worker'
|
8
|
+
|
9
|
+
::Qwirk.register_adapter(
|
10
|
+
:in_memory,
|
11
|
+
::Qwirk::Adapter::InMemory::Publisher,
|
12
|
+
::Qwirk::Adapter::InMemory::WorkerConfig
|
13
|
+
)
|