Class: Crimson::Agent::SteeringManager
- Inherits:
-
Object
- Object
- Crimson::Agent::SteeringManager
- Defined in:
- lib/crimson/agent/steering.rb
Overview
Thread-safe queue for steering messages and follow-ups injected into agent turns.
Instance Method Summary collapse
-
#clear_all ⇒ void
Clear all queued messages.
-
#follow_up(message) ⇒ void
Enqueue a follow-up message.
-
#follow_up_count ⇒ Integer
Number of queued follow-up messages.
-
#has_follow_up? ⇒ Boolean
Whether follow-up messages are queued.
-
#has_steering? ⇒ Boolean
Whether steering messages are queued.
-
#initialize ⇒ SteeringManager
constructor
A new instance of SteeringManager.
-
#pop_all_follow_up ⇒ Array<Message::User>
Dequeue all follow-up messages.
-
#pop_all_steering ⇒ Array<Message::User>
Dequeue all steering messages.
-
#pop_follow_up ⇒ Message::User?
Dequeue a single follow-up message.
-
#pop_steering ⇒ Message::User?
Dequeue a single steering message.
-
#steer(message) ⇒ void
Enqueue a steering message.
-
#steering_count ⇒ Integer
Number of queued steering messages.
Constructor Details
#initialize ⇒ SteeringManager
Returns a new instance of SteeringManager.
9 10 11 12 13 |
# File 'lib/crimson/agent/steering.rb', line 9 def initialize @steering_mutex = Mutex.new @steering_queue = [] @follow_up_queue = [] end |
Instance Method Details
#clear_all ⇒ void
This method returns an undefined value.
Clear all queued messages.
73 74 75 76 77 78 |
# File 'lib/crimson/agent/steering.rb', line 73 def clear_all @steering_mutex.synchronize do @steering_queue.clear @follow_up_queue.clear end end |
#follow_up(message) ⇒ void
This method returns an undefined value.
Enqueue a follow-up message.
25 26 27 |
# File 'lib/crimson/agent/steering.rb', line 25 def follow_up() @steering_mutex.synchronize { @follow_up_queue << } end |
#follow_up_count ⇒ Integer
Returns number of queued follow-up messages.
86 87 88 |
# File 'lib/crimson/agent/steering.rb', line 86 def follow_up_count @steering_mutex.synchronize { @follow_up_queue.size } end |
#has_follow_up? ⇒ Boolean
Returns whether follow-up messages are queued.
35 36 37 |
# File 'lib/crimson/agent/steering.rb', line 35 def has_follow_up? @steering_mutex.synchronize { !@follow_up_queue.empty? } end |
#has_steering? ⇒ Boolean
Returns whether steering messages are queued.
30 31 32 |
# File 'lib/crimson/agent/steering.rb', line 30 def has_steering? @steering_mutex.synchronize { !@steering_queue.empty? } end |
#pop_all_follow_up ⇒ Array<Message::User>
Dequeue all follow-up messages.
63 64 65 66 67 68 69 |
# File 'lib/crimson/agent/steering.rb', line 63 def pop_all_follow_up @steering_mutex.synchronize do msgs = @follow_up_queue.dup @follow_up_queue.clear msgs end end |
#pop_all_steering ⇒ Array<Message::User>
Dequeue all steering messages.
53 54 55 56 57 58 59 |
# File 'lib/crimson/agent/steering.rb', line 53 def pop_all_steering @steering_mutex.synchronize do msgs = @steering_queue.dup @steering_queue.clear msgs end end |
#pop_follow_up ⇒ Message::User?
Dequeue a single follow-up message.
47 48 49 |
# File 'lib/crimson/agent/steering.rb', line 47 def pop_follow_up @steering_mutex.synchronize { @follow_up_queue.shift } end |
#pop_steering ⇒ Message::User?
Dequeue a single steering message.
41 42 43 |
# File 'lib/crimson/agent/steering.rb', line 41 def pop_steering @steering_mutex.synchronize { @steering_queue.shift } end |
#steer(message) ⇒ void
This method returns an undefined value.
Enqueue a steering message.
18 19 20 |
# File 'lib/crimson/agent/steering.rb', line 18 def steer() @steering_mutex.synchronize { @steering_queue << } end |
#steering_count ⇒ Integer
Returns number of queued steering messages.
81 82 83 |
# File 'lib/crimson/agent/steering.rb', line 81 def steering_count @steering_mutex.synchronize { @steering_queue.size } end |