8
8
module Concurrent
9
9
extend Logging
10
10
11
+ # Suppresses all output when used for logging.
12
+ NULL_LOGGER = lambda { |level , progname , message = nil , &block | }
13
+
11
14
# initialize the global executors
12
15
class << self
13
16
14
17
# @!visibility private
15
- @@auto_terminate_global_executors = Concurrent ::AtomicBoolean . new ( true )
18
+ @@global_logger = Atomic . new ( NULL_LOGGER )
19
+
20
+ # @!visibility private
21
+ @@auto_terminate_global_executors = AtomicBoolean . new ( true )
16
22
17
23
# @!visibility private
18
- @@auto_terminate_all_executors = Concurrent :: AtomicBoolean . new ( true )
24
+ @@auto_terminate_all_executors = AtomicBoolean . new ( true )
19
25
20
26
# @!visibility private
21
27
@@global_fast_executor = LazyReference . new do
@@ -31,11 +37,18 @@ class << self
31
37
32
38
# @!visibility private
33
39
@@global_timer_set = LazyReference . new do
34
- Concurrent ::TimerSet . new (
35
- stop_on_exit : @@auto_terminate_global_executors . value )
40
+ TimerSet . new ( stop_on_exit : @@auto_terminate_global_executors . value )
36
41
end
37
42
end
38
43
44
+ def self . global_logger
45
+ @@global_logger . value
46
+ end
47
+
48
+ def self . global_logger = ( value )
49
+ @@global_logger . value = value
50
+ end
51
+
39
52
# Defines if global executors should be auto-terminated with an
40
53
# `at_exit` callback. When set to `false` it will be the application
41
54
# programmer's responsibility to ensure that the global thread pools
@@ -155,15 +168,15 @@ def self.kill_global_executors
155
168
end
156
169
157
170
def self . wait_for_global_executors_termination ( timeout = nil )
158
- latch = Concurrent :: CountDownLatch . new ( 3 )
171
+ latch = CountDownLatch . new ( 3 )
159
172
[ global_fast_executor , global_io_executor , global_timer_set ] . each do |executor |
160
173
Thread . new { executor . wait_for_termination ( timeout ) ; latch . count_down }
161
174
end
162
175
latch . wait ( timeout )
163
176
end
164
177
165
178
def self . new_fast_executor ( opts = { } )
166
- Concurrent :: FixedThreadPool . new (
179
+ FixedThreadPool . new (
167
180
[ 2 , Concurrent . processor_count ] . max ,
168
181
stop_on_exit : opts . fetch ( :stop_on_exit , true ) ,
169
182
idletime : 60 , # 1 minute
@@ -173,7 +186,7 @@ def self.new_fast_executor(opts = {})
173
186
end
174
187
175
188
def self . new_io_executor ( opts = { } )
176
- Concurrent :: ThreadPoolExecutor . new (
189
+ ThreadPoolExecutor . new (
177
190
min_threads : [ 2 , Concurrent . processor_count ] . max ,
178
191
max_threads : Concurrent . processor_count * 100 ,
179
192
stop_on_exit : opts . fetch ( :stop_on_exit , true ) ,
@@ -186,18 +199,33 @@ def self.new_io_executor(opts = {})
186
199
# A gem-level configuration object.
187
200
class Configuration
188
201
189
- # a proc defining how to log messages, its interface has to be:
190
- # lambda { |level, progname, message = nil, &block| _ }
191
- attr_accessor :logger
192
-
193
202
# Create a new configuration object.
194
203
def initialize
195
- @logger = no_logger
196
204
end
197
205
198
206
# if assigned to {#logger}, it will log nothing.
207
+ # @deprecated Use Concurrent::NULL_LOGGER instead
199
208
def no_logger
200
- lambda { |level , progname , message = nil , &block | }
209
+ warn '[DEPRECATED] Use Concurrent::NULL_LOGGER instead'
210
+ NULL_LOGGER
211
+ end
212
+
213
+ # a proc defining how to log messages, its interface has to be:
214
+ # lambda { |level, progname, message = nil, &block| _ }
215
+ #
216
+ # @deprecated Use Concurrent.global_logger instead
217
+ def logger
218
+ warn '[DEPRECATED] Use Concurrent.global_logger instead'
219
+ Concurrent . global_logger . value
220
+ end
221
+
222
+ # a proc defining how to log messages, its interface has to be:
223
+ # lambda { |level, progname, message = nil, &block| _ }
224
+ #
225
+ # @deprecated Use Concurrent.global_logger instead
226
+ def logger = ( value )
227
+ warn '[DEPRECATED] Use Concurrent.global_logger instead'
228
+ Concurrent . global_logger = value
201
229
end
202
230
203
231
# @deprecated Use Concurrent.global_io_executor instead
0 commit comments