Class: Roby::Distributed::Peer::ConnectionToken

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/roby/distributed/communication.rb

Overview

ConnectionToken objects are used to sort out concurrent connections, i.e. cases where two peers are trying to initiate a connection with each other at the same time.

When this situation appears, each peer compares its own token with the one sent by the remote peer. The greatest token wins and is considered the initiator of the connection.

See #initiate_connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnectionToken



28
29
30
31
# File 'lib/roby/distributed/communication.rb', line 28

def initialize
    @time  = Time.now
    @value = rand
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



27
28
29
# File 'lib/roby/distributed/communication.rb', line 27

def time
  @time
end

#valueObject (readonly)

Returns the value of attribute value.



27
28
29
# File 'lib/roby/distributed/communication.rb', line 27

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/roby/distributed/communication.rb', line 32

def <=>(other)
    result = (time <=> other.time)
    if result == 0
  value <=> other.value
    else
  result
    end
end