Skip to content

Commit 21173aa

Browse files
committed
Add Java 7 deprecatin warning
1 parent cfef2d4 commit 21173aa

File tree

5 files changed

+62
-40
lines changed

5 files changed

+62
-40
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
MRI 1.9.3, 2.0, 2.1, 2.2, JRuby (1.9 mode), and Rubinius 2.x are supported.
4141
This gem should be fully compatible with any interpreter that is compliant with Ruby 1.9.3 or newer.
42+
Java 8 is required for JRuby (Java 7 support is deprecated in version 0.9 and will be removed in 1.0).
4243

4344
## Features & Documentation
4445

lib/concurrent/concern/deprecation.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ module Deprecation
1010
include Concern::Logging
1111

1212
def deprecated(message, strip = 2)
13-
caller_line = caller(strip).first
14-
klass = if Class === self
13+
caller_line = caller(strip).first if strip > 0
14+
klass = if Module === self
1515
self
1616
else
1717
self.class
1818
end
19-
log WARN, klass.to_s, format("[DEPRECATED] %s\ncalled on: %s", message, caller_line)
19+
message = if strip > 0
20+
format("[DEPRECATED] %s\ncalled on: %s", message, caller_line)
21+
else
22+
format('[DEPRECATED] %s', message)
23+
end
24+
log WARN, klass.to_s, message
2025
end
2126

2227
def deprecated_method(old_name, new_name)
2328
deprecated "`#{old_name}` is deprecated and it'll removed in next release, use `#{new_name}` instead", 3
2429
end
30+
31+
extend self
2532
end
2633
end
2734
end

lib/concurrent/concern/logging.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'logger'
2+
require 'concurrent/configuration'
23

34
module Concurrent
45
module Concern

lib/concurrent/configuration.rb

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,6 @@ module Concurrent
1111
extend Concern::Logging
1212
extend Concern::Deprecation
1313

14-
# Suppresses all output when used for logging.
15-
NULL_LOGGER = lambda { |level, progname, message = nil, &block| }
16-
17-
# @!visibility private
18-
GLOBAL_LOGGER = AtomicReference.new(NULL_LOGGER)
19-
private_constant :GLOBAL_LOGGER
20-
21-
# @!visibility private
22-
GLOBAL_FAST_EXECUTOR = Delay.new { Concurrent.new_fast_executor(auto_terminate: true) }
23-
private_constant :GLOBAL_FAST_EXECUTOR
24-
25-
# @!visibility private
26-
GLOBAL_IO_EXECUTOR = Delay.new { Concurrent.new_io_executor(auto_terminate: true) }
27-
private_constant :GLOBAL_IO_EXECUTOR
28-
29-
# @!visibility private
30-
GLOBAL_TIMER_SET = Delay.new { TimerSet.new(auto_terminate: true) }
31-
private_constant :GLOBAL_TIMER_SET
32-
33-
# @!visibility private
34-
GLOBAL_IMMEDIATE_EXECUTOR = ImmediateExecutor.new
35-
private_constant :GLOBAL_IMMEDIATE_EXECUTOR
36-
37-
def self.global_logger
38-
GLOBAL_LOGGER.value
39-
end
40-
41-
def self.global_logger=(value)
42-
GLOBAL_LOGGER.value = value
43-
end
44-
4514
# @return [Logger] Logger with provided level and output.
4615
def self.create_stdlib_logger(level = Logger::FATAL, output = $stderr)
4716
logger = Logger.new(output)
@@ -62,17 +31,48 @@ def self.create_stdlib_logger(level = Logger::FATAL, output = $stderr)
6231
progname,
6332
formatted_message
6433
end
65-
logger
34+
35+
lambda do |level, progname, message = nil, &block|
36+
logger.add level, message, progname, &block
37+
end
6638
end
6739

6840
# Use logger created by #create_stdlib_logger to log concurrent-ruby messages.
6941
def self.use_stdlib_logger(level = Logger::FATAL, output = $stderr)
70-
logger = create_stdlib_logger level, output
71-
Concurrent.global_logger = lambda do |level, progname, message = nil, &block|
72-
logger.add level, message, progname, &block
73-
end
42+
Concurrent.global_logger = create_stdlib_logger level, output
7443
end
7544

45+
# Suppresses all output when used for logging.
46+
NULL_LOGGER = lambda { |level, progname, message = nil, &block| }
47+
48+
# @!visibility private
49+
GLOBAL_LOGGER = AtomicReference.new(create_stdlib_logger(Logger::WARN))
50+
private_constant :GLOBAL_LOGGER
51+
52+
def self.global_logger
53+
GLOBAL_LOGGER.value
54+
end
55+
56+
def self.global_logger=(value)
57+
GLOBAL_LOGGER.value = value
58+
end
59+
60+
# @!visibility private
61+
GLOBAL_FAST_EXECUTOR = Delay.new { Concurrent.new_fast_executor(auto_terminate: true) }
62+
private_constant :GLOBAL_FAST_EXECUTOR
63+
64+
# @!visibility private
65+
GLOBAL_IO_EXECUTOR = Delay.new { Concurrent.new_io_executor(auto_terminate: true) }
66+
private_constant :GLOBAL_IO_EXECUTOR
67+
68+
# @!visibility private
69+
GLOBAL_TIMER_SET = Delay.new { TimerSet.new(auto_terminate: true) }
70+
private_constant :GLOBAL_TIMER_SET
71+
72+
# @!visibility private
73+
GLOBAL_IMMEDIATE_EXECUTOR = ImmediateExecutor.new
74+
private_constant :GLOBAL_IMMEDIATE_EXECUTOR
75+
7676
# Disables AtExit handlers including pool auto-termination handlers.
7777
# When disabled it will be the application programmer's responsibility
7878
# to ensure that the handlers are shutdown properly prior to application
@@ -275,4 +275,18 @@ def self.configuration
275275
def self.configure
276276
yield(configuration)
277277
end
278+
279+
# for dependency reasons this check cannot be in concurrent/synchronization
280+
if Concurrent.on_jruby?
281+
require 'java'
282+
283+
version_string = java.lang.System.getProperties['java.runtime.version']
284+
version = version_string.split('.', 3)[0..1].map(&:to_i)
285+
if (version <=> [1, 8]) < 0
286+
deprecated <<-TXT.gsub(/^\s*\|/, '').chop, 0
287+
|Java 7 is deprecated, please use Java 8.
288+
|Java 7 support is only best effort, it may not work. It will be removed in next release (1.0).
289+
TXT
290+
end
291+
end
278292
end

lib/concurrent/synchronization/java_object.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module Concurrent
44
module Synchronization
55

66
if Concurrent.on_jruby?
7-
require 'jruby'
87

98
# @!visibility private
109
# @!macro internal_implementation_note

0 commit comments

Comments
 (0)