class Zold::Entrance
The entrance
Public Class Methods
new(wallets, pipeline, log: Log::NULL)
click to toggle source
# 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
Public Instance Methods
push(id, body)
click to toggle source
Returns a list of modifed wallets (as Zold::Id
)
# 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| ... }
click to toggle source
# 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()
click to toggle source
# 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