Class: Zold::Entrance
- Inherits:
-
Object
- Object
- Zold::Entrance
- Defined in:
- lib/zold/node/entrance.rb
Overview
The entrance
Instance Method Summary collapse
-
#initialize(wallets, pipeline, log: Log::NULL) ⇒ Entrance
constructor
A new instance of Entrance.
-
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id).
- #start {|_self| ... } ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(wallets, pipeline, log: Log::NULL) ⇒ Entrance
Returns a new instance of Entrance.
34 35 36 37 38 39 40 41 |
# File 'lib/zold/node/entrance.rb', line 34 def initialize(wallets, pipeline, log: Log::NULL) @wallets = wallets @pipeline = pipeline @log = log @history = [] @speed = [] @mutex = Mutex.new end |
Instance Method Details
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/zold/node/entrance.rb', line 58 def push(id, body) raise 'Id can\'t be nil' if id.nil? raise 'Id must be of type Id' unless id.is_a?(Id) raise 'Body can\'t be nil' if body.nil? start = Time.now modified = @pipeline.push(id, body, @wallets, @log) sec = (Time.now - start).round(2) @mutex.synchronize do @history.shift if @history.length >= 16 @speed.shift if @speed.length >= 64 @wallets.acq(id) do |wallet| @history << "#{sec}/#{modified.count}/#{wallet.mnemo}" end @speed << sec end modified end |
#start {|_self| ... } ⇒ Object
43 44 45 46 |
# File 'lib/zold/node/entrance.rb', line 43 def start raise 'Block must be given to start()' unless block_given? yield(self) end |
#to_json ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/zold/node/entrance.rb', line 48 def to_json { 'history': @history.join(', '), 'history_size': @history.count, 'speed': @speed.empty? ? 0 : (@speed.inject(&:+) / @speed.count), 'pipeline': @pipeline.to_json } end |