Class: Spinoza::Link

Inherits:
Model
  • Object
show all
Defined in:
lib/spinoza/system/link.rb

Overview

Models a comm link between nodes, including the latency between sender and receiver. The class is stateless: the state of the channnel (messages and their scheduled arrivals) is part of the global timeline.

Instance Attribute Summary collapse

Attributes inherited from Model

#timeline

Instance Method Summary collapse

Methods inherited from Model

#time_now

Constructor Details

#initialize(src: raise, dst: raise, latency: 0.100, **rest) ⇒ Link

Returns a new instance of Link.



14
15
16
17
# File 'lib/spinoza/system/link.rb', line 14

def initialize src: raise, dst: raise, latency: 0.100, **rest
  super **rest
  @src, @dst, @latency = src, dst, latency
end

Instance Attribute Details

#dstObject (readonly)

Source and destination nodes.



9
10
11
# File 'lib/spinoza/system/link.rb', line 9

def dst
  @dst
end

#latencyObject (readonly)

Delay between send by source and receive by destination.



12
13
14
# File 'lib/spinoza/system/link.rb', line 12

def latency
  @latency
end

#srcObject (readonly)

Source and destination nodes.



9
10
11
# File 'lib/spinoza/system/link.rb', line 9

def src
  @src
end

Instance Method Details

#inspectObject



23
24
25
# File 'lib/spinoza/system/link.rb', line 23

def inspect
  "<#{self.class}: #{src} -> #{dst}>"
end

#send_message(msg) ⇒ Object

The src node calls this to send a message. The message is scheduled for arrival at the destination.



29
30
31
32
# File 'lib/spinoza/system/link.rb', line 29

def send_message msg
  timeline << Spinoza::Event[actor: dst, time: time_now + latency,
    action: :recv, msg: msg]
end