Class: Baykit::BayServer::Util::ExecutorService
- Inherits:
-
Object
- Object
- Baykit::BayServer::Util::ExecutorService
- Defined in:
- lib/baykit/bayserver/util/executor_service.rb
Defined Under Namespace
Classes: Executor
Constant Summary collapse
- MAX_LEN_PER_EXECUTOR =
32
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#max_queue_len ⇒ Object
readonly
Returns the value of attribute max_queue_len.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#que ⇒ Object
readonly
Returns the value of attribute que.
Instance Method Summary collapse
-
#initialize(name, count) ⇒ ExecutorService
constructor
A new instance of ExecutorService.
-
#submit(tsk) ⇒ Object
post task.
- #to_s ⇒ Object
Constructor Details
#initialize(name, count) ⇒ ExecutorService
Returns a new instance of ExecutorService.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 44 def initialize(name, count) @que = Thread::Queue.new @count = count @max_queue_len = MAX_LEN_PER_EXECUTOR * count @name = name count.times do |i| started = false Thread.new do started = true id = i + 1 th_name = "Executor[#{name}]##{id}" Thread.current.name = th_name e = Executor.new @que, id, th_name e.run end while !started sleep(0.01) end end end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
40 41 42 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 40 def count @count end |
#max_queue_len ⇒ Object (readonly)
Returns the value of attribute max_queue_len.
41 42 43 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 41 def max_queue_len @max_queue_len end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
42 43 44 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 42 def name @name end |
#que ⇒ Object (readonly)
Returns the value of attribute que.
39 40 41 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 39 def que @que end |
Instance Method Details
#submit(tsk) ⇒ Object
post task
71 72 73 74 75 76 77 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 71 def submit(tsk) BayLog.debug("%s Submit: task=%s (qlen=%d/%d)", self, tsk, @que.length, @max_queue_len) if @que.length > @max_queue_len raise IOError("Task queue is full (>_<)") end @que.enq(tsk) end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 66 def to_s() return "ExecutorService[#{@name}]" end |