Class: Roby::Distributed::Peer::ConnectionToken
- 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
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize ⇒ ConnectionToken
constructor
A new instance of ConnectionToken.
Constructor Details
#initialize ⇒ ConnectionToken
28 29 30 31 |
# File 'lib/roby/distributed/communication.rb', line 28 def initialize @time = Time.now @value = rand end |
Instance Attribute Details
#time ⇒ Object (readonly)
Returns the value of attribute time.
27 28 29 |
# File 'lib/roby/distributed/communication.rb', line 27 def time @time end |
#value ⇒ Object (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 |