fmq 0.1.1 → 0.2.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.
@@ -1,261 +1,266 @@
1
- #
2
- # Copyright (c) 2008 Vincent Landgraf
3
- #
4
- # This file is part of the Free Message Queue.
5
- #
6
- # Free Message Queue is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Free Message Queue is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Free Message Queue. If not, see <http://www.gnu.org/licenses/>.
18
- #
19
- module FreeMessageQueue
20
- # All queue manager exceptions are raised using this class
21
- class QueueManagerException < Exception
22
- attr_accessor :message, :backtrace
23
-
24
- # Create exception with message and backtrace (if needed)
25
- def initialize(message, callstack = [])
26
- @message = message
27
- @backtrace = callstack
28
- end
29
-
30
- # Returns the message of the exception
31
- def to_s
32
- @message
33
- end
34
- end
35
-
36
- # The queue manager is one of the core components of the system.
37
- # This component manages the queues by pathname and checks on the
38
- # corresponding constraints. Every queue that is created by this
39
- # queue manager will get a reference (<em>manager</em>) for later use.
40
- class QueueManager
41
- # This value is used to decribe that a constraint has no limit e.g.
42
- # :max_messages => INFINITE
43
- # means that there is no limitation for messages
44
- INFINITE = -1
45
-
46
- # this is the default queue class if no other is specified this
47
- # class will be created when setting up a queue
48
- DEFAULT_QUEUE_CLASS = FreeMessageQueue::SyncronizedQueue
49
-
50
- # setup the queue manager using the configuration from the configuration
51
- # file (which is basically a hash)
52
- def initialize(config)
53
- @queue = {}
54
- @config = config
55
- @queue_constraints = {}
56
- @log = FreeMessageQueue.logger
57
- setup_queue_manager()
58
- end
59
-
60
- # returns if the creation of queues should be done on demand
61
- # (if someone sends a post to a queue)
62
- def auto_create_queues?
63
- @config["auto-create-queues"]
64
- end
65
-
66
- # Create a queue (<em>name</em> => <em>path</em>). The path must contain a leading "/" and a 3 character name
67
- # at minimum. Exceptions will be raised if the queue allready exists.
68
- def create_queue(name, max_messages = INFINITE, max_size = INFINITE, default_class = DEFAULT_QUEUE_CLASS)
69
- # path must begin with /
70
- raise QueueManagerException.new("[QueueManager] Leading / in path '#{name}' missing", caller) if name[0..0] != "/"
71
-
72
- # path must have a minimus lenght of 3 character
73
- raise QueueManagerException.new("[QueueManager] The queue path '#{name}' is to short 3 character is minimum", caller) if name.size - 1 < 3
74
-
75
- # don't create a queue twice
76
- raise QueueManagerException.new("[QueueManager] The queue '#{name}' allready exists", caller) if queue_exists? name
77
-
78
- @log.info("[QueueManager] Create queue '#{name}' {type: #{default_class}, max_messages: #{max_messages}, max_size: #{max_size}}")
79
-
80
- @queue[name] = default_class.new
81
- @queue[name].manager = self
82
- @queue_constraints[name] = {
83
- :max_messages => max_messages,
84
- :max_size => max_size
85
- }
86
-
87
- @queue[name]
88
- end
89
-
90
- # Delete the queue by name (path)
91
- def delete_queue(name)
92
- if @queue[name]
93
- @log.info("[QueueManager] Delete queue '#{name}' with #{@queue[name].size} messages")
94
- @queue[name].clear
95
- @queue.delete name
96
- true
97
- else
98
- raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
99
- end
100
- end
101
-
102
- # This returns one message from the passed queue
103
- def poll(name)
104
- if @queue[name]
105
- @log.debug("[QueueManager] Poll from queue '#{name}' with #{@queue[name].size} messages")
106
- if @queue[name].respond_to? :poll
107
- queue_item = @queue[name].poll
108
- else
109
- raise QueueManagerException.new("[QueueManager] You can't poll from queue '#{name}'", caller)
110
- end
111
- else
112
- raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
113
- end
114
- end
115
-
116
- alias get poll
117
-
118
- # Puts a message (<em>data</em>) to the queue and checks if the constraints are vaild otherwise
119
- # it will raise a QueueManagerException. If <em>auto_create_queues</em> is set to *true* the queue
120
- # will be generated if there isn't a queue with the passed name (path). Otherwise
121
- # it will raise a QueueManagerException if the passed queue doesn't exists.
122
- def put(name, data)
123
- unless @queue[name]
124
- # only auto create queues if it is configured
125
- if auto_create_queues?
126
- create_queue(name)
127
- else
128
- raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
129
- end
130
- end
131
-
132
- # check max size constraints
133
- if @queue_constraints[name][:max_size] != INFINITE &&
134
- @queue_constraints[name][:max_size] < queue(name).bytes + data.size
135
- raise QueueManagerException.new("[QueueManager] The queue '#{name}' is full, max amount of space (#{@queue_constraints[name][:max_size]}) is exceeded", caller)
136
- end
137
-
138
- # check max messages constraints
139
- if @queue_constraints[name][:max_messages] != INFINITE &&
140
- @queue_constraints[name][:max_messages] < queue(name).size + 1
141
- raise QueueManagerException.new("[QueueManager] The queue '#{name}' is full, max amount of messages (#{@queue_constraints[name][:max_messages]}) is exceeded", caller)
142
- end
143
-
144
- @log.debug("[QueueManager] put message to queue '#{name}' with #{@queue[name].size} messages")
145
- if @queue[name].respond_to? :put
146
- @queue[name].put(data)
147
- else
148
- raise QueueManagerException.new("[QueueManager] You can't put to queue '#{name}'", caller)
149
- end
150
- end
151
-
152
- alias post put
153
-
154
- # Returns the names (paths) of all queues managed by this queue manager
155
- def queues
156
- @queue.keys
157
- end
158
-
159
- # Returns the size of a queue in bytes
160
- def queue_size(name)
161
- @queue[name].size
162
- end
163
-
164
- # Returns the queue constrains as a hash. The hash has the following structure:
165
- # {
166
- # :max_size => "100mb",
167
- # :max_messages => 1000
168
- # }
169
- def queue_constraints(name)
170
- @queue_constraints[name]
171
- end
172
-
173
- # Returns the queue that is passed otherwise nil
174
- def queue(name)
175
- @queue[name]
176
- end
177
-
178
- # Is the name (path) of the queue in use allready
179
- def queue_exists?(name)
180
- !queue(name).nil?
181
- end
182
-
183
- # create a queue from a configuration hash.
184
- # The <em>queue_name</em> is just for debugging and organizing the queue.
185
- # The <em>queue_config</em> contains the following parameter:
186
- # * path: the path to the queue (with leading "/" and 3 characters at minimum) e.g. "/test_queue"
187
- # * [optional] max-size: the maximum size e.g. "10mb", "100kb", "2gb" or (black or -1) for infinite
188
- # * [optional] max-messages: the maximim messages that can be in the queue e.g. 1500 or (black or -1) for infinite
189
- # * [optional] class: the class that implements this queue e.g. FreeMessageQueue::SystemQueue
190
- # All other parameter will be send to the queue directly using a naming convention. So if you have the extra parameter
191
- # expire-date: 1h
192
- # the QueueManager will set the expire date using this assignment
193
- # queue.expire_date = "1h"
194
- # therefore your queue must implement this method
195
- # def expire_date=(time)
196
- # @expires_after = parse_seconds(time)
197
- # end
198
- def create_queue_from_config(queue_name, queue_config)
199
- @log.debug("[QueueManager] setup queue from config '#{queue_name}'")
200
-
201
- # path need to be specified
202
- raise QueueManagerException.new("[QueueManager] There is now path specified for queue '#{queue_name}'", caller) if queue_config["path"].nil?
203
- path = queue_config["path"]
204
- queue_config.delete "path"
205
-
206
- # set max size parameter -- this parameter is optional
207
- max_size = str_bytes(queue_config["max-size"])
208
- max_size = INFINITE if max_size.nil? || max_size <= 0
209
- queue_config.delete "max-size"
210
-
211
- # set max messages parameter -- this parameter is optional
212
- max_messages = queue_config["max-messages"].to_i
213
- max_messages = INFINITE if max_messages.nil? || max_messages <= 0
214
- queue_config.delete "max-messages"
215
-
216
- # set class parameter -- this parameter is optional
217
- default_class = queue_config["class"]
218
- default_class = eval(default_class) unless default_class.nil?
219
- queue_config.delete "class"
220
-
221
- if default_class.nil?
222
- queue = create_queue(path, max_messages, max_size)
223
- else
224
- queue = create_queue(path, max_messages, max_size, default_class)
225
- end
226
-
227
- if queue_config.size > 0
228
- @log.debug("[QueueManager] Configure addional parameters for queue '#{queue_name}'; parameter: #{queue_config.inspect}")
229
- for parameter in queue_config.keys
230
- method_name = parameter.gsub("-", "_")
231
- queue.send(method_name + "=", queue_config[parameter])
232
- end
233
- end
234
- end
235
-
236
- private
237
- # Retuns count of bytes to a expression with kb, mb or gb
238
- # e.g 10kb will return 10240
239
- def str_bytes(str)
240
- case str
241
- when /([0-9]+)kb/i
242
- bs = $1.to_i * 1024
243
- when /([0-9]+)mb/i
244
- bs = $1.to_i * 1024 * 1024
245
- when /([0-9]+)gb/i
246
- bs = $1.to_i * 1024 * 1024 * 1024
247
- else
248
- bs = INFINITE
249
- end
250
- bs
251
- end
252
-
253
- # Create the queues that are defined in the configuration
254
- def setup_queue_manager
255
- @log.info("[QueueManager] Create defined queues (#{@config["defined-queues"].size})")
256
- for defined_queue in @config["defined-queues"]
257
- create_queue_from_config(defined_queue[0], defined_queue[1])
258
- end
259
- end
260
- end
1
+ #
2
+ # Copyright (c) 2008 Vincent Landgraf
3
+ #
4
+ # This file is part of the Free Message Queue.
5
+ #
6
+ # Free Message Queue is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Free Message Queue is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Free Message Queue. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ module FreeMessageQueue
20
+ # All queue manager exceptions are raised using this class
21
+ class QueueManagerException < Exception
22
+ attr_accessor :message, :backtrace
23
+
24
+ # Create exception with message and backtrace (if needed)
25
+ def initialize(message, callstack = [])
26
+ @message = message
27
+ @backtrace = callstack
28
+ end
29
+
30
+ # Returns the message of the exception
31
+ def to_s
32
+ @message
33
+ end
34
+ end
35
+
36
+ # The queue manager is one of the core components of the system.
37
+ # This component manages the queues by pathname and checks on the
38
+ # corresponding constraints. Every queue that is created by this
39
+ # queue manager will get a reference (<em>manager</em>) for later use.
40
+ class QueueManager
41
+ # Returns the queue that is passed otherwise nil
42
+ attr_reader :queue
43
+
44
+ # Returns the queue constrains as a hash. The hash has the following structure:
45
+ # {
46
+ # :max_size => "100mb",
47
+ # :max_messages => 1000
48
+ # }
49
+ attr_reader :queue_constraints
50
+
51
+ # This value is used to decribe that a constraint has no limit e.g.
52
+ # :max_messages => INFINITE
53
+ # means that there is no limitation for messages
54
+ INFINITE = -1
55
+
56
+ # this is the default queue class if no other is specified this
57
+ # class will be created when setting up a queue
58
+ DEFAULT_QUEUE_CLASS = FreeMessageQueue::SyncronizedQueue
59
+
60
+ # setup the queue manager using the configuration from the configuration
61
+ # file (which is basically a hash)
62
+ def initialize(config)
63
+ @queue = {}
64
+ @config = config
65
+ @queue_constraints = {}
66
+ @log = FreeMessageQueue.logger
67
+ setup_queue_manager()
68
+ end
69
+
70
+ # returns if the creation of queues should be done on demand
71
+ # (if someone sends a post to a queue)
72
+ def auto_create_queues?
73
+ @config["auto-create-queues"]
74
+ end
75
+
76
+ # Create a queue (<em>name</em> => <em>path</em>). The path must contain a leading "/" and a 3 character name
77
+ # at minimum. Exceptions will be raised if the queue allready exists.
78
+ def create_queue(name, max_messages = INFINITE, max_size = INFINITE, default_class = DEFAULT_QUEUE_CLASS)
79
+ # path must begin with /
80
+ raise QueueManagerException.new("[QueueManager] Leading / in path '#{name}' missing", caller) if name[0..0] != "/"
81
+
82
+ # path must have a minimus lenght of 3 character
83
+ raise QueueManagerException.new("[QueueManager] The queue path '#{name}' is to short 3 character is minimum", caller) if name.size - 1 < 3
84
+
85
+ # don't create a queue twice
86
+ raise QueueManagerException.new("[QueueManager] The queue '#{name}' allready exists", caller) if queue_exists? name
87
+
88
+ @log.info("[QueueManager] Create queue '#{name}' {type: #{default_class}, max_messages: #{max_messages}, max_size: #{max_size}}")
89
+
90
+ @queue[name] = default_class.new(self)
91
+ @queue_constraints[name] = {
92
+ :max_messages => max_messages,
93
+ :max_size => max_size
94
+ }
95
+
96
+ @queue[name]
97
+ end
98
+
99
+ # Delete the queue by name (path)
100
+ def delete_queue(name)
101
+ if @queue[name]
102
+ @log.info("[QueueManager] Delete queue '#{name}' with #{@queue[name].size} messages")
103
+ @queue[name].clear
104
+ @queue.delete name
105
+ true
106
+ else
107
+ raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
108
+ end
109
+ end
110
+
111
+ # This returns one message from the passed queue
112
+ def poll(name)
113
+ if @queue[name]
114
+ @log.debug("[QueueManager] Poll from queue '#{name}' with #{@queue[name].size} messages")
115
+ if @queue[name].respond_to? :poll
116
+ queue_item = @queue[name].poll
117
+ else
118
+ raise QueueManagerException.new("[QueueManager] You can't poll from queue '#{name}'", caller)
119
+ end
120
+ else
121
+ raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
122
+ end
123
+ end
124
+
125
+ alias get poll
126
+
127
+ # Puts a message (<em>data</em>) to the queue and checks if the constraints are vaild otherwise
128
+ # it will raise a QueueManagerException. If <em>auto_create_queues</em> is set to *true* the queue
129
+ # will be generated if there isn't a queue with the passed name (path). Otherwise
130
+ # it will raise a QueueManagerException if the passed queue doesn't exists.
131
+ def put(name, message)
132
+ unless @queue[name]
133
+ # only auto create queues if it is configured
134
+ if auto_create_queues?
135
+ create_queue(name)
136
+ else
137
+ raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
138
+ end
139
+ end
140
+
141
+ # check max size constraints
142
+ if @queue_constraints[name][:max_size] != INFINITE &&
143
+ @queue_constraints[name][:max_size] < queue[name].bytes + message.bytes
144
+ raise QueueManagerException.new("[QueueManager] The queue '#{name}' is full, max amount of space (#{@queue_constraints[name][:max_size]}) is exceeded", caller)
145
+ end
146
+
147
+ # check max messages constraints
148
+ if @queue_constraints[name][:max_messages] != INFINITE &&
149
+ @queue_constraints[name][:max_messages] < queue[name].size + 1
150
+ raise QueueManagerException.new("[QueueManager] The queue '#{name}' is full, max amount of messages (#{@queue_constraints[name][:max_messages]}) is exceeded", caller)
151
+ end
152
+
153
+ @log.debug("[QueueManager] put message to queue '#{name}' with #{@queue[name].size} messages")
154
+ if @queue[name].respond_to? :put
155
+ @queue[name].put(message)
156
+ else
157
+ raise QueueManagerException.new("[QueueManager] You can't put to queue '#{name}'", caller)
158
+ end
159
+ end
160
+
161
+ alias post put
162
+
163
+ # Returns the names (paths) of all queues managed by this queue manager
164
+ def queues
165
+ @queue.keys
166
+ end
167
+
168
+ # Returns the size (number of messages)
169
+ def queue_size(name)
170
+ @queue[name].size
171
+ end
172
+
173
+ # Returns the byte size of the queue
174
+ def queue_bytes(name)
175
+ @queue[name].bytes
176
+ end
177
+
178
+ # Is the name (path) of the queue in use allready
179
+ def queue_exists?(name)
180
+ !queue[name].nil?
181
+ end
182
+
183
+ # create a queue from a configuration hash.
184
+ # The <em>queue_name</em> is just for debugging and organizing the queue.
185
+ # The <em>queue_config</em> contains the following parameter:
186
+ # * path: the path to the queue (with leading "/" and 3 characters at minimum) e.g. "/test_queue"
187
+ # * [optional] max-size: the maximum size e.g. "10mb", "100kb", "2gb" or (black or -1) for infinite
188
+ # * [optional] max-messages: the maximim messages that can be in the queue e.g. 1500 or (black or -1) for infinite
189
+ # * [optional] class: the class that implements this queue e.g. FreeMessageQueue::SystemQueue
190
+ # All other parameter will be send to the queue directly using a naming convention. So if you have the extra parameter
191
+ # expire-date: 1h
192
+ # the QueueManager will set the expire date using this assignment
193
+ # queue.expire_date = "1h"
194
+ # therefore your queue must implement this method
195
+ # def expire_date=(time)
196
+ # @expires_after = parse_seconds(time)
197
+ # end
198
+ def create_queue_from_config(queue_name, queue_config)
199
+ @log.debug("[QueueManager] setup queue from config '#{queue_name}'")
200
+
201
+ # path need to be specified
202
+ raise QueueManagerException.new("[QueueManager] There is now path specified for queue '#{queue_name}'", caller) if queue_config["path"].nil?
203
+ path = queue_config["path"]
204
+ queue_config.delete "path"
205
+
206
+ # set max size parameter -- this parameter is optional
207
+ max_size = str_bytes(queue_config["max-size"])
208
+ max_size = INFINITE if max_size.nil? || max_size <= 0
209
+ queue_config.delete "max-size"
210
+
211
+ # set max messages parameter -- this parameter is optional
212
+ max_messages = queue_config["max-messages"].to_i
213
+ max_messages = INFINITE if max_messages.nil? || max_messages <= 0
214
+ queue_config.delete "max-messages"
215
+
216
+ # set class parameter -- this parameter is optional
217
+ default_class = queue_config["class"]
218
+ puts default_class
219
+ default_class = eval(default_class) unless default_class.nil?
220
+ queue_config.delete "class"
221
+
222
+ if default_class.nil?
223
+ queue = create_queue(path, max_messages, max_size)
224
+ else
225
+ queue = create_queue(path, max_messages, max_size, default_class)
226
+ end
227
+
228
+ if queue_config.size > 0
229
+ @log.debug("[QueueManager] Configure addional parameters for queue '#{queue_name}'; parameter: #{queue_config.inspect}")
230
+ for parameter in queue_config.keys
231
+ method_name = parameter.gsub("-", "_")
232
+ queue.send(method_name + "=", queue_config[parameter])
233
+ end
234
+ end
235
+ end
236
+
237
+ private
238
+ # Retuns count of bytes to a expression with kb, mb or gb
239
+ # e.g 10kb will return 10240
240
+ def str_bytes(str)
241
+ case str
242
+ when /([0-9]+)kb/i
243
+ bs = $1.to_i * 1024
244
+ when /([0-9]+)mb/i
245
+ bs = $1.to_i * 1024 * 1024
246
+ when /([0-9]+)gb/i
247
+ bs = $1.to_i * 1024 * 1024 * 1024
248
+ else
249
+ bs = INFINITE
250
+ end
251
+ bs
252
+ end
253
+
254
+ # Create the queues that are defined in the configuration
255
+ def setup_queue_manager
256
+ if @config.nil?
257
+ raise QueueManagerException.new("[QueueManager] there is no queue manager configuration" , caller)
258
+ else
259
+ @log.info("[QueueManager] Create defined queues (#{@config["defined-queues"].size})")
260
+ for defined_queue in @config["defined-queues"]
261
+ create_queue_from_config(defined_queue[0], defined_queue[1])
262
+ end
263
+ end
264
+ end
265
+ end
261
266
  end
@@ -6,31 +6,22 @@ First of all, this template is where you start.
6
6
  2. Name your file to the name of the queue. In this example we have the queue "MyTestQueue"
7
7
  so the file will be "my_test.rb". Save your new file to the queue folder of your projects folder "queues/my_test.rb"
8
8
  3. Change the queue implementation to something you like
9
- * every queue must have an <em>manager</em>.
10
- * this manager must be able to read <em>bytes</em> and <em>size</em>
11
- * the queue should have at least one of the <tt>put(data)</tt> or <tt>poll()</tt> methods defined
12
- * when implementing the poll queue the object you returning needs to have a <em>data</em> method.
13
- This examples uses OpenStruct for this purpose
9
+ * every queue must have an <em>manager</em>. (for this just inherit from FreeMessageQueue::BaseQueue)
10
+ * this manager must be able to read <em>bytes</em> and <em>size</em> (for this just inherit from FreeMessageQueue::BaseQueue)
11
+ * the queue should have at least one of the <tt>put(message)</tt> or <tt>poll()</tt> methods defined
12
+ * when implementing the poll queue the object you returning needs to have a <em>payload</em> method.
13
+ This examples uses FreeMessageQueue::Message for this purpose
14
14
 
15
15
  # FILE: my_project/queues/my_test.rb
16
16
 
17
- require "ostruct"
18
-
19
- class MyTestQueue
20
- attr_accessor :manager
21
- attr_reader :bytes, :size
22
-
23
- def initialize
24
- @bytes = @size = 1
25
- end
26
-
27
- def put(data)
28
- puts "NEW MESSAGE"
17
+ class MyTestQueue < FreeMessageQueue::BaseQueue
18
+ def put(message)
19
+ puts "INCOMMING: #{message.payload}"
29
20
  end
30
-
21
+
31
22
  def poll
32
- item = OpenStruct.new
33
- item.data = "Hello World"
34
- item
23
+ msg = FreeMessageQueue::Message.new "Hello World", "text/plain"
24
+ msg.option["Time"] = Time.now
25
+ msg
35
26
  end
36
27
  end
@@ -16,7 +16,7 @@
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Free Message Queue. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
- require 'ostruct'
19
+ require File.dirname(__FILE__) + '/base'
20
20
 
21
21
  module FreeMessageQueue
22
22
  # This queue is dedicated to the AJAX based admin interface.
@@ -29,24 +29,14 @@ module FreeMessageQueue
29
29
  # path: /admin/queue
30
30
  # class: FreeMessageQueue::AdminQueue
31
31
  # filter: /admin
32
- class AdminQueue
33
- # QueueManager refrence
34
- attr_accessor :manager
35
-
36
- # Bytes size is -1. Size is allways 1 message
37
- attr_reader :bytes, :size
38
-
39
- def initialize()
40
- super
41
- @bytes = -1
42
- @size = 1
32
+ class AdminQueue < BaseQueue
33
+ def initialize(manager)
34
+ super(manager)
43
35
  @filter_queues = []
44
36
  end
45
37
 
46
38
  # returns an json list of visible queues
47
39
  def poll()
48
- item = OpenStruct.new
49
-
50
40
  queues_code = []
51
41
  manager.queues.each do |queue_name|
52
42
  # skip if it is filterd
@@ -56,16 +46,15 @@ module FreeMessageQueue
56
46
  queues_code << queue_to_json(queue_name)
57
47
  end
58
48
 
59
- item.data = "[%s]" % queues_code.join(",")
60
- item
49
+ Message.new("[%s]" % queues_code.join(","), "application/json")
61
50
  end
62
51
 
63
52
  # can be either used to *create* or *delete* a queue
64
- def put(data)
65
- if data.match(/_method=delete&path=(.*)/)
53
+ def put(message)
54
+ if message.payload.match(/_method=delete&path=(.*)/)
66
55
  # delete queue
67
56
  manager.delete_queue($1)
68
- elsif data.match(/_method=create&data=(.*)/)
57
+ elsif message.payload.match(/_method=create&data=(.*)/)
69
58
  # create queue
70
59
  conf = eval($1.gsub(":", "=>").gsub("null", "-1"))
71
60
  manager.create_queue_from_config("dynamic-created-queue", conf)
@@ -91,13 +80,13 @@ module FreeMessageQueue
91
80
 
92
81
  # converts the data of one queue to json format
93
82
  def queue_to_json(queue_name)
94
- constraints = manager.queue_constraints(queue_name)
83
+ constraints = manager.queue_constraints[queue_name]
95
84
 
96
85
  "[\"%s\", %d, %d, %d, %d]" % [
97
86
  queue_name,
98
- manager.queue(queue_name).bytes,
87
+ manager.queue[queue_name].bytes,
99
88
  constraints[:max_size],
100
- manager.queue(queue_name).size,
89
+ manager.queue[queue_name].size,
101
90
  constraints[:max_messages],
102
91
  ]
103
92
  end