Class: Spinoza::Node
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
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Outgoing links to peer nodes, as a map ‘=> link, …`.
-
#lock_manager ⇒ Object
readonly
Returns the value of attribute lock_manager.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Attributes inherited from Model
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*tables, name: new_name, **rest) ⇒ Node
constructor
Create a node whose store contains the specified tables and which has its own lock manager.
- #inspect ⇒ Object
- #link(dst, **opts) ⇒ Object
- #new_name ⇒ Object
- #recv(msg: raise) ⇒ Object
- #tables ⇒ Object
- #to_s ⇒ Object
Methods inherited from Model
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
#links ⇒ Object (readonly)
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_manager ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/spinoza/system/node.rb', line 10 def name @name end |
#store ⇒ Object (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_name ⇒ Object
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
#inspect ⇒ Object
38 39 40 |
# File 'lib/spinoza/system/node.rb', line 38 def inspect "<Node #{name}>" end |
#link(dst, **opts) ⇒ Object
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_name ⇒ Object
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 |
#tables ⇒ Object
55 56 57 |
# File 'lib/spinoza/system/node.rb', line 55 def tables store.tables end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/spinoza/system/node.rb', line 42 def to_s name.to_s end |