Class: Spinoza::Node

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

Overview

A top level entity in the system model, representing one node of the distributed system, typically one per host. Nodes are connected by Links. Node is stateful.

Direct Known Subclasses

Calvin::Node

Instance Attribute Summary collapse

Attributes inherited from Model

#timeline

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#time_now

Constructor Details

#initialize(*tables, name: new_name, **rest) ⇒ Node

Create a node whose store contains the specified tables and which has its own lock manager.



30
31
32
33
34
35
36
# File 'lib/spinoza/system/node.rb', line 30

def initialize *tables, name: new_name, **rest
  super **rest
  @store = Spinoza::Store.new *tables
  @name = name
  @lock_manager = Spinoza::LockManager.new
  @links = {}
end

Instance Attribute Details

Outgoing links to peer nodes, as a map ‘=> link, …`. Use `links.send_message(msg)` to send a message to a peer. Use Node#recv to handle received messages.



17
18
19
# File 'lib/spinoza/system/node.rb', line 17

def links
  @links
end

#lock_managerObject (readonly)

Returns the value of attribute lock_manager.



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

def lock_manager
  @lock_manager
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/spinoza/system/node.rb', line 10

def name
  @name
end

#storeObject (readonly)

Returns the value of attribute store.



11
12
13
# File 'lib/spinoza/system/node.rb', line 11

def store
  @store
end

Class Method Details

.new_nameObject



20
21
22
# File 'lib/spinoza/system/node.rb', line 20

def self.new_name
  @next_name.tap {@next_name += 1}.to_s
end

Instance Method Details

#inspectObject



38
39
40
# File 'lib/spinoza/system/node.rb', line 38

def inspect
  "<Node #{name}>"
end


46
47
48
49
50
51
52
53
# File 'lib/spinoza/system/node.rb', line 46

def link dst, **opts
  require 'spinoza/system/link'

  if links[dst]
    raise "Link from #{self} to #{dst} already exists."
  end
  links[dst] = Spinoza::Link[timeline: timeline, src: self, dst: dst, **opts]
end

#new_nameObject



24
25
26
# File 'lib/spinoza/system/node.rb', line 24

def new_name
  Spinoza::Node.new_name
end

#recv(msg: raise) ⇒ Object



63
64
65
# File 'lib/spinoza/system/node.rb', line 63

def recv msg: raise
  # Defined in subclasses.
end

#tablesObject



55
56
57
# File 'lib/spinoza/system/node.rb', line 55

def tables
  store.tables
end

#to_sObject



42
43
44
# File 'lib/spinoza/system/node.rb', line 42

def to_s
  name.to_s
end