Class: Roby::PlanningTask
- Inherits:
-
Task
- Object
- BasicObject
- PlanObject
- Task
- Roby::PlanningTask
- Defined in:
- lib/roby/planning/task.rb
Overview
An asynchronous planning task using Ruby threads
Defined Under Namespace
Classes: TransactionProxy
Constant Summary
Constants included from Log::TaskHooks
Constants included from Log::BasicObjectHooks
Instance Attribute Summary collapse
-
#planner ⇒ Object
readonly
Returns the value of attribute planner.
-
#result ⇒ Object
readonly
The planner result.
-
#thread ⇒ Object
readonly
The thread that is running the planner.
-
#transaction ⇒ Object
readonly
The transaction in which we build the new plan.
Attributes inherited from PlanObject
#executable, #plan, #removed_at
Attributes inherited from BasicObject
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ PlanningTask
constructor
A new instance of PlanningTask.
- #planned_model ⇒ Object
- #planned_task ⇒ Object
- #planning_thread(context) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Task
#_dump, _load, #droby_dump, improves, #improves?, improves?, match, needs, #needs?, needs?
Methods included from TaskStructure::ModelConflicts
#conflicts_with, #conflicts_with?
Methods included from Distributed::DRobyTaskModel::Dump
Methods included from Distributed::DRobyModel::Dump
Methods included from Distributed::TaskNotifications
Methods included from TaskOperations
Methods included from Log::TaskHooks
#added_child_object, #removed_child_object
Methods inherited from PlanObject
#add_child_object, #apply_relation_changes, child_plan_object, #each_plan_child, #executable?, #finalized?, #forget_peer, #read_write?, #remotely_useful?, #removing_child_object, #replace_by, #replace_subplan_by, #root_object, #root_object?, #subscribed?, #update_on?, #updated_by?
Methods included from Distributed::RelationModificationHooks
#added_child_object, #removed_child_object
Methods included from Transactions::PlanObjectUpdates
#adding_child_object, #removing_child_object
Methods included from DirectedRelationSupport
#add_child_object, #add_parent_object, #check_is_relation, #related_objects, #relations, #remove_child_object, #remove_children, #remove_parent_object, #remove_parents, #remove_relations
Methods inherited from BasicObject
#add_sibling_for, #distribute?, distribute?, #finalized?, #forget_peer, #has_sibling_on?, #initialize_copy, local_only, #read_write?, #remotely_useful?, #remove_sibling_for, #self_owned?, #sibling_of, #sibling_on, #subscribe, #subscribed?, #update_on?, #updated?, #updated_by?, #updated_peers
Methods included from Log::BasicObjectHooks
Constructor Details
#initialize(options) ⇒ PlanningTask
Returns a new instance of PlanningTask.
35 36 37 38 |
# File 'lib/roby/planning/task.rb', line 35 def initialize() = PlanningTask.() super() end |
Instance Attribute Details
#planner ⇒ Object (readonly)
Returns the value of attribute planner.
9 10 11 |
# File 'lib/roby/planning/task.rb', line 9 def planner @planner end |
#result ⇒ Object (readonly)
The planner result. It is either an exception or a task object
68 69 70 |
# File 'lib/roby/planning/task.rb', line 68 def result @result end |
#thread ⇒ Object (readonly)
The thread that is running the planner
63 64 65 |
# File 'lib/roby/planning/task.rb', line 63 def thread @thread end |
#transaction ⇒ Object (readonly)
The transaction in which we build the new plan. It gets committed on success.
66 67 68 |
# File 'lib/roby/planning/task.rb', line 66 def transaction @transaction end |
Class Method Details
.filter_options(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/roby/planning/task.rb', line 15 def self.() , = Kernel. , :planner_model => nil, :method_name => nil, :method_options => {}, :planned_model => nil, :planning_owners => nil if ![:planner_model] raise ArgumentError, "missing required argument 'planner_model'" elsif ![:method_name] raise ArgumentError, "missing required argument 'method_name'" end [:planned_model] ||= nil [:method_options] ||= Hash.new [:method_options].merge! [:planning_owners] ||= nil end |
Instance Method Details
#planned_model ⇒ Object
40 41 42 |
# File 'lib/roby/planning/task.rb', line 40 def planned_model arguments[:planned_model] ||= planner_model.model_of(method_name, ).returns || Roby::Task end |
#planned_task ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/roby/planning/task.rb', line 49 def planned_task if success? || result result elsif task = planned_tasks.find { true } task elsif pending? task = planned_model.new task.planned_by self task.executable = false task end end |
#planning_thread(context) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/roby/planning/task.rb', line 90 def planning_thread(context) result_task = planner.send(method_name, .merge(:context => context)) # Don't replace the planning task with ourselves if the # transaction specifies another planning task if !result_task.planning_task result_task.planned_by transaction[self] end if placeholder = planned_task placeholder = transaction[placeholder] transaction.replace(placeholder, result_task) placeholder.remove_planning_task transaction[self] end # If the transaction is distributed, and is not proposed to all # owners, do it transaction.propose transaction.commit_transaction do @result = result_task end end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/roby/planning/task.rb', line 45 def to_s "#{super}[#{method_name}:#{method_options}] -> #{@planned_task || "nil"}" end |