Class: Roby::BasicObject::DRoby

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/distributed/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_siblings, owners) ⇒ DRoby

Create a BasicObject::DRoby object with the given information



12
13
14
# File 'lib/roby/distributed/proxy.rb', line 12

def initialize(remote_siblings, owners)
    @remote_siblings, @owners = remote_siblings, owners
end

Instance Attribute Details

#ownersObject (readonly)

The set of owners for that object.



10
11
12
# File 'lib/roby/distributed/proxy.rb', line 10

def owners
  @owners
end

#remote_siblingsObject (readonly)

The set of remote siblings for that object, as known by the peer who called #droby_dump. This is used to match object identity among plan managers.



8
9
10
# File 'lib/roby/distributed/proxy.rb', line 8

def remote_siblings
  @remote_siblings
end

Instance Method Details

#owners_to_sObject

:nodoc:



19
20
21
# File 'lib/roby/distributed/proxy.rb', line 19

def owners_to_s # :nodoc:
    "[ " << owners.map { |peer| peer.name }.join(", ") << " ]"
end

#remote_siblings_to_sObject

:nodoc:



16
17
18
# File 'lib/roby/distributed/proxy.rb', line 16

def remote_siblings_to_s # :nodoc:
    "{ " << remote_siblings.map { |peer, id| id.to_s(peer) }.join(", ") << " }"
end

#sibling_on(peer) ⇒ Object

If we know of a sibling on peer, return it. Otherwise, raises RemotePeerMismatch.

Raises:



27
28
29
30
31
32
33
34
# File 'lib/roby/distributed/proxy.rb', line 27

def sibling_on(peer)
    remote_siblings.each do |m_peer, remote_id|
  if m_peer.peer_id == peer.remote_id
      return remote_id
  end
    end
    raise RemotePeerMismatch, "#{self} has no known sibling on #{peer}"
end

#to_sObject

:nodoc:



22
23
24
# File 'lib/roby/distributed/proxy.rb', line 22

def to_s # :nodoc:
    "#<dRoby:BasicObject#{remote_siblings_to_s} owners=#{owners_to_s}>" 
end

#update(peer, proxy) ⇒ Object

Update an existing proxy, using the information stored in this DRoby object.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/roby/distributed/proxy.rb', line 38

def update(peer, proxy)
    proxy.owners.clear
    owners.each do |m_owner|
  proxy.owners << peer.local_object(m_owner)
    end

    remote_siblings.each do |m_peer_sibling, remote_id|
  peer_sibling = peer.local_object(m_peer_sibling)

  if current = proxy.remote_siblings[peer_sibling]
      if current != remote_id && peer_sibling != Roby::Distributed
    raise "inconsistency for sibling on #{peer_sibling}: #{proxy} has #{current} while #{self} has #{remote_id}"
      end
  else
      proxy.sibling_of(remote_id, peer_sibling)
  end
    end
end