Class: DLogReader::SimpleThreadPool
- Inherits:
-
Object
- Object
- DLogReader::SimpleThreadPool
- Defined in:
- lib/distributed_logreader/distributer/simple_thread_pool.rb
Instance Attribute Summary collapse
-
#max_queue_size ⇒ Object
Returns the value of attribute max_queue_size.
-
#num_threads ⇒ Object
Returns the value of attribute num_threads.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#thread_pool ⇒ Object
Returns the value of attribute thread_pool.
-
#worker ⇒ Object
Returns the value of attribute worker.
Instance Method Summary collapse
-
#initialize(worker, num_threads = 5) ⇒ SimpleThreadPool
constructor
A new instance of SimpleThreadPool.
- #join ⇒ Object
- #process(line) ⇒ Object
Constructor Details
#initialize(worker, num_threads = 5) ⇒ SimpleThreadPool
Returns a new instance of SimpleThreadPool.
6 7 8 9 10 11 12 13 14 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 6 def initialize(worker, num_threads = 5) self.worker = worker self.num_threads = num_threads self.queue = Queue.new self.max_queue_size = 100 num_threads.times do create_thread end end |
Instance Attribute Details
#max_queue_size ⇒ Object
Returns the value of attribute max_queue_size.
5 6 7 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 5 def max_queue_size @max_queue_size end |
#num_threads ⇒ Object
Returns the value of attribute num_threads.
5 6 7 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 5 def num_threads @num_threads end |
#queue ⇒ Object
Returns the value of attribute queue.
5 6 7 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 5 def queue @queue end |
#thread_pool ⇒ Object
Returns the value of attribute thread_pool.
5 6 7 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 5 def thread_pool @thread_pool end |
#worker ⇒ Object
Returns the value of attribute worker.
5 6 7 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 5 def worker @worker end |
Instance Method Details
#join ⇒ Object
23 24 25 26 27 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 23 def join while(queue.size > 0) sleep 0.1 end end |
#process(line) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/distributed_logreader/distributer/simple_thread_pool.rb', line 16 def process(line) while(queue.size > self.max_queue_size) sleep(0.01) end self.queue << line end |