Class: Crimson::Agent::SteeringManager

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeSteeringManager

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_allvoid

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.

Parameters:



25
26
27
# File 'lib/crimson/agent/steering.rb', line 25

def follow_up(message)
  @steering_mutex.synchronize { @follow_up_queue << message }
end

#follow_up_countInteger

Returns number of queued follow-up messages.

Returns:

  • (Integer)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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_upArray<Message::User>

Dequeue all follow-up messages.

Returns:



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_steeringArray<Message::User>

Dequeue all steering messages.

Returns:



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_upMessage::User?

Dequeue a single follow-up message.

Returns:



47
48
49
# File 'lib/crimson/agent/steering.rb', line 47

def pop_follow_up
  @steering_mutex.synchronize { @follow_up_queue.shift }
end

#pop_steeringMessage::User?

Dequeue a single steering message.

Returns:



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.

Parameters:



18
19
20
# File 'lib/crimson/agent/steering.rb', line 18

def steer(message)
  @steering_mutex.synchronize { @steering_queue << message }
end

#steering_countInteger

Returns number of queued steering messages.

Returns:

  • (Integer)

    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