-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
19 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
module AmqpActors | ||
class MemoryQueues | ||
def initialize | ||
@threads = {} | ||
def initialize(type, &_blk) | ||
@threads = [] | ||
@type = type | ||
end | ||
|
||
# @TODO remove dead threads from the array periodically | ||
def start_actor(type) | ||
type.inbox = Queue.new | ||
type.running = true | ||
@threads[type] = Array.new(type.thread_count) do | ||
def start | ||
@threads = Array.new(@type.thread_count) do | ||
Thread.new do | ||
loop do | ||
break unless System.running? && type.running | ||
break unless System.running? && @type.running | ||
begin | ||
msg = type.inbox.pop | ||
type.new.push(msg) | ||
msg = @type.inbox.pop | ||
@type.new.push(msg) | ||
rescue => e | ||
print "[ERROR] \n #{e.backtrace.join("\n ")}\n" | ||
end | ||
end | ||
end | ||
end | ||
Queue.new | ||
end | ||
|
||
def stop | ||
# noop | ||
end | ||
|
||
def running_threads(type = nil) | ||
if type | ||
@threads[type].select(&:alive?).count | ||
else | ||
@threads.values.flatten.select(&:alive?).count | ||
end | ||
def running_threads | ||
@threads.select(&:alive?).count | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters