Module: Roby::Distributed::DistributedObject

Included in:
Transaction
Defined in:
lib/roby/distributed/distributed_object.rb

Overview

Module included in objects distributed across multiple pDBs

Instance Method Summary collapse

Instance Method Details

#add_owner(peer, distributed = true) ⇒ Object

Add the Peer peer to the list of owners



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/roby/distributed/distributed_object.rb', line 22

def add_owner(peer, distributed = true)
		return if owners.include?(peer)
		if distributed 
 if !self_owned?
			raise OwnershipError, "not object owner"
 end

 call_siblings(:add_owner, self, peer)
 added_owner(peer)
		else
 owners << peer
 if plan
			plan.task_index.add_owner(self, peer)
 end
 Distributed.debug { "added owner to #{self}: #{owners.to_a}" }
		end
end

#added_owner(peer) ⇒ Object



39
# File 'lib/roby/distributed/distributed_object.rb', line 39

def added_owner(peer); super if defined? super end

#call_owners(*args) ⇒ Object

:nodoc:

Raises:



78
79
80
81
82
83
84
85
86
# File 'lib/roby/distributed/distributed_object.rb', line 78

def call_owners(*args) # :nodoc:
		raise OwnershipError, "not owner" if !self_owned?
 
		if owners.any? { |peer| !has_sibling_on?(peer) }
 raise InvalidRemoteOperation, "cannot do #{args} if the object is not distributed on all its owners"
		end

		Distributed.call_peers(owners, *args)
end

#call_siblings(m, *args) ⇒ Object



74
75
76
# File 'lib/roby/distributed/distributed_object.rb', line 74

def call_siblings(m, *args)
		Distributed.call_peers(updated_peers.dup << Distributed, m, *args)
end

#owner=(peer) ⇒ Object



66
67
68
69
70
71
# File 'lib/roby/distributed/distributed_object.rb', line 66

def owner=(peer)
		add_owner(peer)
		owners.each do |owner|
 remove_owner(owner) unless owner == peer
		end
end

#prepare_remove_owner(peer) ⇒ Object



63
# File 'lib/roby/distributed/distributed_object.rb', line 63

def prepare_remove_owner(peer); super if defined? super end

#remove_owner(peer, distributed = true) ⇒ Object

Removes peer from the list of owners. Raises OwnershipError if there are modified tasks in this transaction which are owned by peer



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/roby/distributed/distributed_object.rb', line 44

def remove_owner(peer, distributed = true)
		return unless owners.include?(peer)

		if distributed
 results = call_siblings(:prepare_remove_owner, self, peer)
 if error = results.values.find { |error| error }
			raise error
 end
 call_siblings(:remove_owner, self, peer)
		else
 owners.delete(peer)
 removed_owner(peer)
 if plan
			plan.task_index.remove_owner(self, peer)
 end
 Distributed.debug { "removed owner to #{self}: #{owners.to_a}" }
		end
		nil
end

#removed_owner(peer) ⇒ Object



64
# File 'lib/roby/distributed/distributed_object.rb', line 64

def removed_owner(peer); super if defined? super end

#self_ownedObject

Makes this object owned by the local DB. This is equivalent to object.self_owned = true



10
# File 'lib/roby/distributed/distributed_object.rb', line 10

def self_owned; self.self_owned = true end

#self_owned=(flag) ⇒ Object

Adds or removes the local DB from the list of owners. This is equivalent to calling add_peer(Distributed) and remove_peer(Distributed)



15
16
17
18
19
# File 'lib/roby/distributed/distributed_object.rb', line 15

def self_owned=(flag)
		if flag then add_owner(Distributed)
		else remove_owner(Distributed)
		end
end