Class: Roby::BasicObject
- Includes:
- DRbUndumped, Log::BasicObjectHooks
- Defined in:
- lib/roby.rb,
lib/roby/basic_object.rb
Direct Known Subclasses
Defined Under Namespace
Classes: DRoby
Constant Summary
Constants included from Log::BasicObjectHooks
Instance Attribute Summary collapse
-
#distribute ⇒ Object
writeonly
Attribute which overrides the #distribute attribute on object classes.
Class Method Summary collapse
-
.distribute? ⇒ Boolean
True if instances of this class should be seen by remote hosts.
-
.local_only ⇒ Object
Call to make the object of this class never seen by remote hosts.
Instance Method Summary collapse
-
#add_sibling_for(peer, remote_object) ⇒ Object
Registers
remote_objectas the sibling ofselfonpeer. -
#distribute? ⇒ Boolean
True if this object can be seen by remote hosts.
- #finalized? ⇒ Boolean
-
#forget_peer(peer) ⇒ Object
Called when all links to
peershould be removed. -
#has_sibling_on?(peer) ⇒ Boolean
True if we know about a sibling on
peer. -
#initialize_copy(old) ⇒ Object
:nodoc:.
-
#read_write? ⇒ Boolean
True if this object can be modified in the current context.
-
#remotely_useful? ⇒ Boolean
True if this object is useful for our peers.
-
#remove_sibling_for(peer, id = nil) ⇒ Object
Remove references about the sibling registered for
peerand returns it. -
#self_owned? ⇒ Boolean
True if we own this object.
-
#sibling_of(remote_object, peer) ⇒ Object
Sets
remote_objectas the remote siblings forselfonpeer, and notifies peer thatselfis the remote siblings forremote_object. -
#sibling_on(peer) ⇒ Object
Returns the object representation of
selfonpeer. -
#subscribe ⇒ Object
Subscribe to this object on all the peers which own it.
-
#subscribed? ⇒ Boolean
True if we explicitely want this object to be updated by our peers.
-
#update_on?(peer) ⇒ Boolean
True if we shall send updates for this object on
peer. -
#updated? ⇒ Boolean
True if this object is maintained up-to-date.
-
#updated_by?(peer) ⇒ Boolean
True if
peerwill send us updates about this object. -
#updated_peers ⇒ Object
The set of peers that will get updates of this object.
Methods included from Log::BasicObjectHooks
Instance Attribute Details
#distribute=(value) ⇒ Object (writeonly)
Attribute which overrides the #distribute attribute on object classes
17 18 19 |
# File 'lib/roby/basic_object.rb', line 17 def distribute=(value) @distribute = value end |
Class Method Details
.distribute? ⇒ Boolean
True if instances of this class should be seen by remote hosts
24 |
# File 'lib/roby/basic_object.rb', line 24 def self.distribute?; !(@distribute == false) end |
.local_only ⇒ Object
Call to make the object of this class never seen by remote hosts
26 |
# File 'lib/roby/basic_object.rb', line 26 def self.local_only; @distribute = false end |
Instance Method Details
#add_sibling_for(peer, remote_object) ⇒ Object
Registers remote_object as the sibling of self on peer. Unlike #sibling_of, do not notify the peer about it.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/roby/basic_object.rb', line 84 def add_sibling_for(peer, remote_object) if old_sibling = remote_siblings[peer] if old_sibling != remote_object raise ArgumentError, "#{self} has already a sibling for #{peer} (#{old_sibling}) #{remote_siblings}" else # This is OK. The same sibling information can come from # different sources. We only check for inconsistencies return end end remote_siblings[peer] = remote_object peer.proxies[remote_object] = self Roby::Distributed.debug "added sibling #{remote_object.inspect} for #{self} on #{peer} (#{remote_siblings})" end |
#distribute? ⇒ Boolean
True if this object can be seen by remote hosts
19 20 21 |
# File 'lib/roby/basic_object.rb', line 19 def distribute? @distribute || (@distribute.nil? && self.class.distribute?) end |
#finalized? ⇒ Boolean
28 |
# File 'lib/roby/basic_object.rb', line 28 def finalized?; !remote_siblings[Distributed] end |
#forget_peer(peer) ⇒ Object
Called when all links to peer should be removed.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/roby/basic_object.rb', line 63 def forget_peer(peer) if remote_object = remove_sibling_for(peer) peer.removing_proxies[remote_object] << droby_dump(nil) if peer.connected? peer.transmit(:removed_sibling, remote_object, self.remote_id) do set = peer.removing_proxies[remote_object] set.shift if set.empty? peer.removing_proxies.delete(remote_object) end yield if block_given? end else peer.removing_proxies.delete(remote_object) end end end |
#has_sibling_on?(peer) ⇒ Boolean
True if we know about a sibling on peer
36 37 38 |
# File 'lib/roby/basic_object.rb', line 36 def has_sibling_on?(peer) peer == Roby::Distributed || remote_siblings.include?(peer) end |
#initialize_copy(old) ⇒ Object
:nodoc:
5 6 7 8 9 |
# File 'lib/roby/basic_object.rb', line 5 def initialize_copy(old) # :nodoc: super @remote_siblings = Hash[Distributed, Roby::Distributed::RemoteID.from_object(self)] end |
#read_write? ⇒ Boolean
True if this object can be modified in the current context
146 147 148 |
# File 'lib/roby/basic_object.rb', line 146 def read_write? owners.include?(Distributed) || Distributed.updating?(self) end |
#remotely_useful? ⇒ Boolean
True if this object is useful for our peers
143 |
# File 'lib/roby/basic_object.rb', line 143 def remotely_useful?; self_owned? && remote_siblings.size > 1 end |
#remove_sibling_for(peer, id = nil) ⇒ Object
Remove references about the sibling registered for peer and returns it
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/roby/basic_object.rb', line 101 def remove_sibling_for(peer, id = nil) if id && remote_siblings[peer] != id return end if remote_object = remote_siblings.delete(peer) peer.proxies.delete(remote_object) peer.subscriptions.delete(remote_object) Roby::Distributed.debug "removed sibling #{remote_object.inspect} for #{self} on #{peer}" remote_object end end |
#self_owned? ⇒ Boolean
True if we own this object
14 |
# File 'lib/roby/basic_object.rb', line 14 def self_owned?; owners.include?(Distributed) end |
#sibling_of(remote_object, peer) ⇒ Object
Sets remote_object as the remote siblings for self on peer, and notifies peer that self is the remote siblings for remote_object
53 54 55 56 57 58 59 60 |
# File 'lib/roby/basic_object.rb', line 53 def sibling_of(remote_object, peer) if !distribute? raise ArgumentError, "#{self} is local only" end add_sibling_for(peer, remote_object) peer.transmit(:added_sibling, remote_object, remote_id) end |
#sibling_on(peer) ⇒ Object
Returns the object representation of self on peer. The returned value is either a remote sibling (the DRbObject of the representation of self on peer), or self if peer is Roby::Distributed
43 44 45 46 47 48 49 |
# File 'lib/roby/basic_object.rb', line 43 def sibling_on(peer) if sibling = remote_siblings[peer] then sibling elsif Roby::Distributed == peer then self else raise RemotePeerMismatch, "#{self} has no known sibling on #{peer}" end end |
#subscribe ⇒ Object
Subscribe to this object on all the peers which own it.
This is a blocking operation, and cannot be used in the control thread.
121 122 123 124 125 126 127 |
# File 'lib/roby/basic_object.rb', line 121 def subscribe if !self_owned? && !subscribed? owners.each do |peer| peer.subscribe(self) unless peer.subcribed?(self) end end end |
#subscribed? ⇒ Boolean
True if we explicitely want this object to be updated by our peers
115 |
# File 'lib/roby/basic_object.rb', line 115 def subscribed?; owners.any? { |peer| peer.subscribed?(self) if peer != Distributed } end |
#update_on?(peer) ⇒ Boolean
True if we shall send updates for this object on peer
134 |
# File 'lib/roby/basic_object.rb', line 134 def update_on?(peer); (self_owned? || peer.owns?(self)) && remote_siblings[peer] end |
#updated? ⇒ Boolean
True if this object is maintained up-to-date
130 |
# File 'lib/roby/basic_object.rb', line 130 def updated?; self_owned? || owners.any?(&remote_siblings.method(:[])) end |
#updated_by?(peer) ⇒ Boolean
True if peer will send us updates about this object
132 |
# File 'lib/roby/basic_object.rb', line 132 def updated_by?(peer); self_owned? || (remote_siblings[peer] && peer.owns?(self)) end |
#updated_peers ⇒ Object
The set of peers that will get updates of this object
136 137 138 139 140 |
# File 'lib/roby/basic_object.rb', line 136 def updated_peers peers = remote_siblings.keys peers.delete(Distributed) peers end |