Module: Roby::Distributed::RelationModificationHooks

Included in:
PlanObject
Defined in:
lib/roby/distributed/notifications.rb

Overview

This module defines the hooks needed to notify our peers of relation modifications. It is included in plan objects.

Instance Method Summary collapse

Instance Method Details

#added_child_object(child, relations, info) ⇒ Object

Hook called when a new relation is added. It sends the PeerServer#update_relation message.



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/roby/distributed/notifications.rb', line 299

def added_child_object(child, relations, info)
    super if defined? super

    return if Distributed.updating?(plan)
    return if Distributed.updating_all?([self.root_object, child.root_object])
    return unless Distributed.state

    # Remove all relations that should not be distributed, and if
    # there is a relation remaining, notify our peer only of the
    # first one: this is the child of all others
    if notified_relation = relations.find { |rel| rel.distribute? }
 Distributed.each_updated_peer(self.root_object, child.root_object) do |peer|
      peer.transmit(:update_relation, plan, self, :add_child_object, child, notified_relation, info)
 end
 Distributed.trigger(self, child)
    end
end

#removed_child_object(child, relations) ⇒ Object

Hook called when a relation is removed. It sends the PeerServer#update_relation message.



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/roby/distributed/notifications.rb', line 319

def removed_child_object(child, relations)
    super if defined? super
    return unless Distributed.state

    # If our peer is pushing a distributed transaction, children
    # can be removed Avoid sending unneeded updates by testing on
    # plan update
    return if Distributed.updating?(plan)
    return if Distributed.updating_all?([self.root_object, child.root_object])

    # Remove all relations that should not be distributed, and if
    # there is a relation remaining, notify our peer only of the
    # first one: this is the child of all others
    if notified_relation = relations.find { |rel| rel.distribute? }
 Distributed.each_updated_peer(self.root_object, child.root_object) do |peer|
      peer.transmit(:update_relation, plan, self, :remove_child_object, child, notified_relation)
 end
 Distributed.trigger(self, child)
    end
end