Class: Roby::Interface::Async::NewJobListener
- Defined in:
- lib/roby/interface/async/new_job_listener.rb
Overview
Listener object for Interface#on_job
Instance Attribute Summary collapse
-
#action_name ⇒ String?
readonly
The name of the action whose job we are tracking.
-
#block ⇒ #call
readonly
The notification callback.
-
#interface ⇒ Interface
readonly
The interface we are connected to.
-
#last_job_id ⇒ Object
readonly
The last ID of the jobs received by this listener.
Instance Method Summary collapse
-
#call(job) ⇒ Object
Call the listener for the given job.
-
#ignored(job) ⇒ Object
Tell this listener that the given job was received, but ignored.
-
#initialize(interface, action_name, block) ⇒ NewJobListener
constructor
A new instance of NewJobListener.
-
#matches?(job) ⇒ Boolean
Tests whether the provided job matches what this listener wants.
-
#reset ⇒ Object
Resets the listener so that it can be used on a new connection.
-
#seen_job_with_id?(job_id) ⇒ Boolean
Tests whether this listener has already seen the job with the given ID.
-
#start ⇒ Object
Start listening for jobs.
-
#stop ⇒ Object
Stop listening for jobs.
Constructor Details
#initialize(interface, action_name, block) ⇒ NewJobListener
Returns a new instance of NewJobListener.
21 22 23 24 25 26 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 21 def initialize(interface, action_name, block) @interface = interface @action_name = action_name @block = block @last_job_id = -1 end |
Instance Attribute Details
#action_name ⇒ String? (readonly)
Returns the name of the action whose job we are tracking. If nil, tracks all actions.
10 11 12 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 10 def action_name @action_name end |
#block ⇒ #call (readonly)
Returns the notification callback.
12 13 14 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 12 def block @block end |
#interface ⇒ Interface (readonly)
Returns the interface we are connected to.
7 8 9 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 7 def interface @interface end |
#last_job_id ⇒ Object (readonly)
The last ID of the jobs received by this listener.
This is used to avoid double-notifications of new jobs. The assumption is that the job IDs are ever-increasing and that they are fed in-order to #call.
19 20 21 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 19 def last_job_id @last_job_id end |
Instance Method Details
#call(job) ⇒ Object
Call the listener for the given job
53 54 55 56 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 53 def call(job) @last_job_id = job.job_id block.call(job) end |
#ignored(job) ⇒ Object
Tell this listener that the given job was received, but ignored.
This is an optimization to avoid re-considering this listener for the given job
63 64 65 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 63 def ignored(job) @last_job_id = job.job_id end |
#matches?(job) ⇒ Boolean
Tests whether the provided job matches what this listener wants
46 47 48 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 46 def matches?(job) !action_name || (job.action_name == action_name) end |
#reset ⇒ Object
Resets the listener so that it can be used on a new connection
This currently only resets #last_job_id
31 32 33 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 31 def reset @last_job_id = -1 end |
#seen_job_with_id?(job_id) ⇒ Boolean
Tests whether this listener has already seen the job with the given ID
40 41 42 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 40 def seen_job_with_id?(job_id) last_job_id >= job_id end |
#start ⇒ Object
Start listening for jobs
68 69 70 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 68 def start interface.add_new_job_listener(self) end |
#stop ⇒ Object
Stop listening for jobs
73 74 75 |
# File 'lib/roby/interface/async/new_job_listener.rb', line 73 def stop interface.remove_new_job_listener(self) end |