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.
-
#executors ⇒ Object
readonly
Returns the value of attribute executors.
-
#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.
- #shutdown ⇒ Object
-
#submit(&block) ⇒ Object
post task.
- #to_s ⇒ Object
Constructor Details
#initialize(name, count) ⇒ ExecutorService
Returns a new instance of ExecutorService.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 53 def initialize(name, count) @que = Thread::Queue.new @count = count @max_queue_len = MAX_LEN_PER_EXECUTOR * count @name = name @executors = [] count.times do |i| started = false Thread.new do begin started = true id = i + 1 th_name = "Executor[#{name}]##{id}" Thread.current.name = th_name e = Executor.new @que, id, th_name e.run @executors << e rescue => e BayLog.error_e(e) end end while !started sleep(0.01) end end end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
48 49 50 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 48 def count @count end |
#executors ⇒ Object (readonly)
Returns the value of attribute executors.
51 52 53 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 51 def executors @executors end |
#max_queue_len ⇒ Object (readonly)
Returns the value of attribute max_queue_len.
49 50 51 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 49 def max_queue_len @max_queue_len end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
50 51 52 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 50 def name @name end |
#que ⇒ Object (readonly)
Returns the value of attribute que.
47 48 49 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 47 def que @que end |
Instance Method Details
#shutdown ⇒ Object
94 95 96 97 98 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 94 def shutdown @executors.each do |exe| exe.shutdown end end |
#submit(&block) ⇒ Object
post task
86 87 88 89 90 91 92 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 86 def submit(&block) BayLog.debug("%s Submit: (qlen=%d/%d)", self, @que.length, @max_queue_len) if @que.length > @max_queue_len raise IOError("Task queue is full (>_<)") end @que.enq(block) end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/baykit/bayserver/util/executor_service.rb', line 81 def to_s return "ExecutorService[#{@name}]" end |