Class: Lapidar::Runner
- Inherits:
-
Object
- Object
- Lapidar::Runner
- Defined in:
- lib/lapidar/runner.rb
Instance Attribute Summary collapse
-
#buschtelefon_endpoint ⇒ Object
readonly
Returns the value of attribute buschtelefon_endpoint.
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#punch_queue ⇒ Object
readonly
Returns the value of attribute punch_queue.
Instance Method Summary collapse
-
#initialize(buschtelefon_endpoint) ⇒ Runner
constructor
A new instance of Runner.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(buschtelefon_endpoint) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lapidar/runner.rb', line 7 def initialize(buschtelefon_endpoint) @logger = Logger.new(StringIO.new) @buschtelefon_endpoint = buschtelefon_endpoint @chain = Persistence.load_chain("#{@buschtelefon_endpoint.port}.json") || Chain.new @incoming_blocks = Queue.new @punch_queue = SizedQueue.new(1) @should_stop = nil @threads = [] # Reload currently strongest chain into buschtelefon_endpoint if @chain.blocks.any? @buschtelefon_endpoint.(@chain.blocks.map(&:to_h).map(&:to_json)) end end |
Instance Attribute Details
#buschtelefon_endpoint ⇒ Object (readonly)
Returns the value of attribute buschtelefon_endpoint.
5 6 7 |
# File 'lib/lapidar/runner.rb', line 5 def buschtelefon_endpoint @buschtelefon_endpoint end |
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
5 6 7 |
# File 'lib/lapidar/runner.rb', line 5 def chain @chain end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/lapidar/runner.rb', line 5 def logger @logger end |
#punch_queue ⇒ Object (readonly)
Returns the value of attribute punch_queue.
5 6 7 |
# File 'lib/lapidar/runner.rb', line 5 def punch_queue @punch_queue end |
Instance Method Details
#start ⇒ Object
22 23 24 25 26 27 |
# File 'lib/lapidar/runner.rb', line 22 def start @should_stop = false @threads = [consumer, local_producer, network_producer] @threads.each { |t| t.abort_on_exception = true } @threads.each(&:join) end |
#stop ⇒ Object
29 30 31 32 33 34 |
# File 'lib/lapidar/runner.rb', line 29 def stop @should_stop = true Thread.pass Persistence.save_chain("#{@buschtelefon_endpoint.port}.json", @chain) @threads.each(&:exit) end |