Module: Roby::Transaction::TaskProxy
- Includes:
- GUI::GraphvizTask, GUI::RelationsCanvasTaskProxy
- Defined in:
- lib/roby/transaction/task_proxy.rb
Overview
Transaction proxy for Roby::Task
Constant Summary collapse
- STATE_PREDICATES =
[:pending?, :running?, :finished?, :success?, :failed?]
Instance Attribute Summary
Attributes included from GUI::RelationsCanvasTaskProxy
Attributes included from GUI::RelationsCanvasTask
Instance Method Summary collapse
-
#commit_transaction ⇒ Object
Perform the operations needed for the commit to be successful.
- #event(name) ⇒ Object
- #has_event?(name) ⇒ Boolean
- #initialize_replacement(task) ⇒ Object
-
#setup_proxy(object, transaction) ⇒ Object
Create a new proxy representing
objectintransaction. - #to_s ⇒ Object
Methods included from GUI::GraphvizTask
#apply_layout, #dot_label, #to_dot_events
Methods included from GUI::GraphvizPlanObject
#apply_layout, #dot_label, #to_dot
Methods included from GUI::RelationsCanvasTaskProxy
#display, #display_create, #display_name, #display_parent, #flags
Methods included from GUI::RelationsCanvasTask
#display, #display_create, #display_name, #display_time_end, #display_time_start, #layout_events, to_svg, #update_graphics
Methods included from GUI::RelationsCanvasPlanObject
#display, #display_create, #display_events, #display_name, #display_parent
Instance Method Details
#commit_transaction ⇒ Object
Perform the operations needed for the commit to be successful. In practice, it updates the task arguments as needed.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/roby/transaction/task_proxy.rb', line 73 def commit_transaction super # Update the task arguments. The original # Roby::Task#commit_transaction has already translated the proxy # objects into real objects arguments.each do |key, value| __getobj__.arguments.update!(key, value) end execute_handlers.each do |h| __getobj__.execute(h., &h.block) end poll_handlers.each do |h| __getobj__.poll(h., &h.block) end __getobj__.abstract = self.abstract? if @fullfilled_model __getobj__.fullfilled_model = @fullfilled_model.dup end __getobj__.do_not_reuse if !@reusable end |
#event(name) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/roby/transaction/task_proxy.rb', line 62 def event(name) if ev = find_event(name) ev else ev = __getobj__.event(name) bound_events[ev.symbol] = plan.create_and_register_proxy_event(ev) end end |
#has_event?(name) ⇒ Boolean
58 59 60 |
# File 'lib/roby/transaction/task_proxy.rb', line 58 def has_event?(name) super || __getobj__.has_event?(name) end |
#initialize_replacement(task) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/roby/transaction/task_proxy.rb', line 97 def initialize_replacement(task) super seen_events = bound_events.keys.to_set # Apply recursively all event handlers of this (proxied) task to # the new task # # We have to look at all levels as, in transactions, the "handlers" # set only contains new event handlers real_object = self while real_object.transaction_proxy? real_object = real_object.__getobj__ real_object.execute_handlers.each do |h| if h.copy_on_replace? task.execute(h., &h.block) end end real_object.poll_handlers.each do |h| if h.copy_on_replace? task.poll(h., &h.block) end end # Do the same for all events that are not present at this level # of the transaction real_object.each_event do |event| if !seen_events.include?(event.symbol) event.initialize_replacement(nil) { task.event(event.symbol) } seen_events << event.symbol end end end end |
#setup_proxy(object, transaction) ⇒ Object
Create a new proxy representing object in transaction
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/roby/transaction/task_proxy.rb', line 16 def setup_proxy(object, transaction) super(object, transaction) @poll_handlers.clear @execute_handlers.clear @arguments = Roby::TaskArguments.new(self) if !bound_events.empty? raise ArgumentError, "expected bound_events to be empty when setting the proxy up" end STATE_PREDICATES.each do |predicate_name| instance_variable_set "@#{predicate_name[0..-2]}", object.send(predicate_name) end object.arguments.each do |key, value| if value.kind_of?(Roby::PlanObject) arguments.update!(key, transaction[value]) else arguments.update!(key, value) end end proxied_events = Array.new events = object.each_event.to_a transaction.plan.each_event_relation_graph do |g| next if !g.root_relation? events.delete_if do |event| should_proxy = g.each_in_neighbour(event).any? { |e| !e.respond_to?(:task) || e.task != object } || g.each_out_neighbour(event).any? { |e| !e.respond_to?(:task) || e.task != object } if should_proxy proxied_events << event end end break if events.empty? end proxied_events.each do |ev| transaction.create_and_register_proxy_event(ev) end end |
#to_s ⇒ Object
7 |
# File 'lib/roby/transaction/task_proxy.rb', line 7 def to_s; "tProxy(#{__getobj__.name})#{arguments}" end |