Module: Roby::Distributed::PlanModificationHooks
- Included in:
- Plan
- Defined in:
- lib/roby/distributed/notifications.rb
Overview
Set of hooks which send Plan updates to remote hosts
Class Method Summary collapse
-
.discovered_objects(plan, objects) ⇒ Object
Common implementation for the #discovered_events and #discovered_tasks hooks.
-
.finalized_object(plan, object) ⇒ Object
Common implementation for the #finalized_task and PeerServer#finalized_event hooks.
Instance Method Summary collapse
-
#discarded(task) ⇒ Object
Hook called when a new task is not a mission anymore.
-
#discovered_events(events) ⇒ Object
New free events have been discovered in the plan.
-
#discovered_tasks(tasks) ⇒ Object
New tasks have been discovered in the plan.
-
#finalized_event(event) ⇒ Object
Hook called when a free event has been removed from the plan.
-
#finalized_task(task) ⇒ Object
Hook called when a task has been removed from the plan.
-
#inserted(task) ⇒ Object
Hook called when a new task is marked as mission.
-
#replaced(from, to) ⇒ Object
Hook called when
fromhas been replaced bytoin the plan.
Class Method Details
.discovered_objects(plan, objects) ⇒ Object
Common implementation for the #discovered_events and #discovered_tasks hooks. It sends PeerServer#plan_discover for all tasks which can be shared among plan managers
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/roby/distributed/notifications.rb', line 97 def self.discovered_objects(plan, objects) unless Distributed.updating?(plan) relations = nil Distributed.each_updated_peer(plan) do |peer| # Compute +objects+ and +relations+ only if there is a # peer to update unless relations objects = objects.find_all { |t| t.distribute? && t.self_owned? && t.root_object? && !Distributed.updating?(t) } return if objects.empty? relations = Distributed.subgraph_of(objects) end peer.transmit(:plan_discover, plan, objects, relations) end Distributed.trigger(*objects) end end |
.finalized_object(plan, object) ⇒ Object
Common implementation for the #finalized_task and PeerServer#finalized_event hooks. It sends the plan_remove_object message.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/roby/distributed/notifications.rb', line 143 def self.finalized_object(plan, object) return unless object.distribute? && object.root_object? Distributed.keep.delete(object) if object.self_owned? Distributed.clean_triggered(object) if !Distributed.updating?(plan) Distributed.peers.each_value do |peer| if peer.connected? peer.transmit(:plan_remove_object, plan, object) end end end if object.remotely_useful? Distributed.removed_objects << object end else object.remote_siblings.keys.each do |peer| object.forget_peer(peer) unless peer == Roby::Distributed end end end |
Instance Method Details
#discarded(task) ⇒ Object
Hook called when a new task is not a mission anymore. It sends a PeerServer#plan_set_mission message to the remote host.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/roby/distributed/notifications.rb', line 83 def discarded(task) super if defined? super return unless task.distribute? && task.self_owned? unless Distributed.updating?(self) || Distributed.updating?(task) Distributed.each_updated_peer(self, task) do |peer| peer.transmit(:plan_set_mission, self, task, false) end end end |
#discovered_events(events) ⇒ Object
New free events have been discovered in the plan.
See PlanModificationHooks.discovered_objects
123 124 125 126 |
# File 'lib/roby/distributed/notifications.rb', line 123 def discovered_events(events) super if defined? super PlanModificationHooks.discovered_objects(self, events) end |
#discovered_tasks(tasks) ⇒ Object
New tasks have been discovered in the plan.
See PlanModificationHooks.discovered_objects
116 117 118 119 |
# File 'lib/roby/distributed/notifications.rb', line 116 def discovered_tasks(tasks) super if defined? super PlanModificationHooks.discovered_objects(self, tasks) end |
#finalized_event(event) ⇒ Object
Hook called when a free event has been removed from the plan.
See PlanModificationHooks.finalized_object
178 179 180 181 |
# File 'lib/roby/distributed/notifications.rb', line 178 def finalized_event(event) super if defined? super PlanModificationHooks.finalized_object(self, event) end |
#finalized_task(task) ⇒ Object
Hook called when a task has been removed from the plan.
See PlanModificationHooks.finalized_object
171 172 173 174 |
# File 'lib/roby/distributed/notifications.rb', line 171 def finalized_task(task) super if defined? super PlanModificationHooks.finalized_object(self, task) end |
#inserted(task) ⇒ Object
Hook called when a new task is marked as mission. It sends a PeerServer#plan_set_mission message to the remote host.
Note that plan will have called the #discovered_tasks hook beforehand
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/roby/distributed/notifications.rb', line 69 def inserted(task) super if defined? super return unless task.distribute? && task.self_owned? unless Distributed.updating?(self) || Distributed.updating?(task) Distributed.each_updated_peer(self, task) do |peer| peer.transmit(:plan_set_mission, self, task, true) end Distributed.trigger(task) end end |
#replaced(from, to) ⇒ Object
Hook called when from has been replaced by to in the plan. It sends a PeerServer#plan_replace message
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/roby/distributed/notifications.rb', line 130 def replaced(from, to) super if defined? super if (from.distribute? && to.distribute?) && (to.self_owned? || from.self_owned?) unless Distributed.updating?(self) || Distributed.updating_all?([from, to]) Distributed.each_updated_peer(from) do |peer| peer.transmit(:plan_replace, self, from, to) end end end end |