liquid-ext 3.4.1 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -15
- data/lib/liquid/cli.rb +1 -1
- data/lib/liquid/ext/jmx4r.rb +36 -34
- data/lib/liquid/ext/socket.rb +2 -3
- data/lib/liquid/logger.rb +23 -9
- data/lib/liquid/metrics.rb +42 -40
- data/lib/liquid/server.rb +58 -56
- data/lib/liquid/timing.rb +24 -22
- data/lib/liquid/tracker.rb +11 -9
- data/lib/liquid/trove.rb +57 -55
- data/lib/liquid/zmq.rb +105 -103
- data/liquid-ext.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab68e51c9209484d0aa966b8498578a715ebba1
|
4
|
+
data.tar.gz: 13123b71496c35456f68419ac5868a06a730c1fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff8cddc75aef8e7e262451341db272c9e7fe2cf0003bead9d8cedb9247cef145b42d4513ebee0615b01461e06e5d0a9108b546b7003e0f5563f57fb0994ad2a
|
7
|
+
data.tar.gz: 8ca4dcdf20fdf87b1aa0714f5253e4f5f89a69b76a0219e3d670b983ddff16625be2fb49cb3b5ce46129e1dbb37cd538bba40007a21332bad442466581cac8e9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
liquid-ext (3.4.
|
4
|
+
liquid-ext (3.4.2)
|
5
5
|
activesupport
|
6
6
|
erubis
|
7
7
|
jmx4r
|
@@ -12,7 +12,7 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: http://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (4.1.
|
15
|
+
activesupport (4.1.1)
|
16
16
|
i18n (~> 0.6, >= 0.6.9)
|
17
17
|
json (~> 1.7, >= 1.7.7)
|
18
18
|
minitest (~> 5.1)
|
@@ -22,16 +22,16 @@ GEM
|
|
22
22
|
bond (0.5.1-java)
|
23
23
|
brice (0.2.9)
|
24
24
|
ruby-nuggets (>= 0.5.2)
|
25
|
-
cane (2.6.
|
25
|
+
cane (2.6.2)
|
26
26
|
parallel
|
27
27
|
coderay (1.1.0)
|
28
28
|
diff-lcs (1.2.5)
|
29
29
|
docile (1.1.3)
|
30
30
|
erubis (2.7.0)
|
31
31
|
ffi (1.9.3-java)
|
32
|
-
fuubar (1.3.
|
32
|
+
fuubar (1.3.3)
|
33
33
|
rspec (>= 2.14.0, < 3.1.0)
|
34
|
-
ruby-progressbar (~> 1.
|
34
|
+
ruby-progressbar (~> 1.4)
|
35
35
|
hirb (0.7.1)
|
36
36
|
i18n (0.6.9)
|
37
37
|
jmx4r (0.1.4)
|
@@ -55,12 +55,10 @@ GEM
|
|
55
55
|
yard
|
56
56
|
log_switch (0.4.0)
|
57
57
|
method_source (0.8.2)
|
58
|
-
|
59
|
-
minitest (5.3.3)
|
58
|
+
minitest (5.3.4)
|
60
59
|
mixlib-cli (1.5.0)
|
61
|
-
multi_json (1.
|
62
|
-
nokogiri (1.6.1-java)
|
63
|
-
mini_portile (~> 0.5.0)
|
60
|
+
multi_json (1.10.0)
|
61
|
+
nokogiri (1.6.2.1-java)
|
64
62
|
parallel (1.0.0)
|
65
63
|
pry (0.9.12.6-java)
|
66
64
|
coderay (~> 1.0)
|
@@ -68,7 +66,7 @@ GEM
|
|
68
66
|
slop (~> 3.4)
|
69
67
|
spoon (~> 0.0)
|
70
68
|
rainbow (2.0.0)
|
71
|
-
rake (10.3.
|
69
|
+
rake (10.3.2)
|
72
70
|
reek (1.3.7)
|
73
71
|
rainbow
|
74
72
|
ruby2ruby (~> 2.0.8)
|
@@ -84,12 +82,12 @@ GEM
|
|
84
82
|
rspec-expectations (2.14.5)
|
85
83
|
diff-lcs (>= 1.1.3, < 2.0)
|
86
84
|
rspec-mocks (2.14.6)
|
87
|
-
ruby-nuggets (0.9.
|
88
|
-
ruby-progressbar (1.
|
85
|
+
ruby-nuggets (0.9.9)
|
86
|
+
ruby-progressbar (1.5.1)
|
89
87
|
ruby2ruby (2.0.8)
|
90
88
|
ruby_parser (~> 3.1)
|
91
89
|
sexp_processor (~> 4.0)
|
92
|
-
ruby_parser (3.
|
90
|
+
ruby_parser (3.6.1)
|
93
91
|
sexp_processor (~> 4.1)
|
94
92
|
sexp_processor (4.4.3)
|
95
93
|
simplecov (0.8.2)
|
@@ -111,7 +109,7 @@ GEM
|
|
111
109
|
text-table (1.2.3)
|
112
110
|
thread_safe (0.3.3-java)
|
113
111
|
timecop (0.7.1)
|
114
|
-
tins (1.
|
112
|
+
tins (1.3.0)
|
115
113
|
tzinfo (1.1.0)
|
116
114
|
thread_safe (~> 0.1)
|
117
115
|
yard (0.8.7.4)
|
data/lib/liquid/cli.rb
CHANGED
data/lib/liquid/ext/jmx4r.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
require 'active_support/core_ext/hash/keys'
|
3
|
+
require 'jmx4r'
|
3
4
|
|
4
|
-
java_import 'javax.management.RuntimeMBeanException'
|
5
|
-
java_import 'java.lang.UnsupportedOperationException'
|
5
|
+
java_import 'javax.management.RuntimeMBeanException'
|
6
|
+
java_import 'java.lang.UnsupportedOperationException'
|
6
7
|
|
7
|
-
class JMX::MBean
|
8
|
+
class JMX::MBean
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def self.to_tree
|
11
|
+
find_all_by_name("*:*").inject({}) do |result, mbean|
|
12
|
+
domain = mbean.object_name.domain
|
13
|
+
properties = mbean.object_name.key_property_list_string.split(',')
|
14
|
+
mresult = result[domain] ||= {}
|
15
|
+
mresult = mresult[properties.shift] ||= {} until properties.empty?
|
16
|
+
mbean.to_h(mresult)
|
17
|
+
result
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
def to_h(hsh = {})
|
22
|
+
attributes.keys.inject(hsh) do |result, key|
|
23
|
+
result[key.to_sym] = get_value(key)
|
24
|
+
result
|
25
|
+
end.merge!({
|
26
|
+
object_name: object_name.to_s,
|
27
|
+
})
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def get_value(key)
|
31
|
+
case value = send(key)
|
32
|
+
when Java::JavaxManagementOpenmbean::CompositeDataSupport
|
33
|
+
Hash[value.to_a].symbolize_keys
|
34
|
+
when Enumerable
|
35
|
+
value.to_a
|
36
|
+
else
|
37
|
+
value
|
38
|
+
end
|
39
|
+
rescue RuntimeMBeanException => e
|
40
|
+
raise unless e.cause.is_a?(UnsupportedOperationException)
|
41
|
+
nil
|
37
42
|
end
|
38
|
-
rescue RuntimeMBeanException => e
|
39
|
-
raise unless e.cause.is_a?(UnsupportedOperationException)
|
40
|
-
nil
|
41
|
-
end
|
42
43
|
|
44
|
+
end
|
43
45
|
end
|
data/lib/liquid/ext/socket.rb
CHANGED
@@ -2,11 +2,10 @@ require 'ipaddr'
|
|
2
2
|
|
3
3
|
class Socket
|
4
4
|
def self.ipaddress
|
5
|
-
|
6
|
-
getaddrinfo(hostname, nil).first[3]
|
5
|
+
getaddrinfo(gethostname, nil).first[3]
|
7
6
|
end
|
8
7
|
|
9
8
|
def self.fqdn
|
10
|
-
|
9
|
+
gethostbyaddr(IPAddr.new(ipaddress).hton)[0]
|
11
10
|
end
|
12
11
|
end
|
data/lib/liquid/logger.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
java_import 'org.slf4j.LoggerFactory'
|
3
|
+
else
|
4
|
+
require 'logger'
|
5
|
+
end
|
2
6
|
|
3
7
|
module Liquid
|
4
8
|
class Logger
|
@@ -7,14 +11,16 @@ module Liquid
|
|
7
11
|
attr_accessor :appender
|
8
12
|
|
9
13
|
def initialize(name, progname = nil)
|
14
|
+
@java = RUBY_PLATFORM == "java"
|
10
15
|
@progname = progname || File.basename($0)
|
11
|
-
@logger = LoggerFactory.getLogger(name)
|
16
|
+
@logger = @java ? LoggerFactory.getLogger(name) : ::Logger.new(STDOUT)
|
12
17
|
@exceptions = {}
|
13
18
|
@exception_handlers = [method(:_log_error_exception)]
|
14
19
|
unmute!
|
15
20
|
end
|
16
21
|
|
17
22
|
def reload!
|
23
|
+
return unless @java
|
18
24
|
root = org.apache.log4j.Logger.getRootLogger
|
19
25
|
appender = @appender.new
|
20
26
|
appender.name = "default"
|
@@ -26,17 +32,25 @@ module Liquid
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def mute!
|
29
|
-
@
|
35
|
+
if @java
|
36
|
+
@appender = org.apache.log4j.varia.NullAppender
|
37
|
+
else
|
38
|
+
@logger = ::Logger.new("/dev/null")
|
39
|
+
end
|
30
40
|
reload!
|
31
41
|
end
|
32
42
|
|
33
43
|
def unmute!
|
34
|
-
@
|
44
|
+
if @java
|
45
|
+
@appender = org.apache.log4j.ConsoleAppender
|
46
|
+
else
|
47
|
+
@logger = ::Logger.new(STDOUT)
|
48
|
+
end
|
35
49
|
reload!
|
36
50
|
end
|
37
51
|
|
38
52
|
def trace?
|
39
|
-
@logger.trace_enabled?
|
53
|
+
@java ? @logger.trace_enabled? : @logger.trace?
|
40
54
|
end
|
41
55
|
|
42
56
|
def trace(*args, &block)
|
@@ -46,7 +60,7 @@ module Liquid
|
|
46
60
|
end
|
47
61
|
|
48
62
|
def debug?
|
49
|
-
@logger.debug_enabled?
|
63
|
+
@java ? @logger.debug_enabled? : @logger.debug?
|
50
64
|
end
|
51
65
|
|
52
66
|
def debug(*args, &block)
|
@@ -56,7 +70,7 @@ module Liquid
|
|
56
70
|
end
|
57
71
|
|
58
72
|
def info?
|
59
|
-
@logger.info_enabled?
|
73
|
+
@java ? @logger.info_enabled? : @logger.info?
|
60
74
|
end
|
61
75
|
|
62
76
|
def info(*args, &block)
|
@@ -66,7 +80,7 @@ module Liquid
|
|
66
80
|
end
|
67
81
|
|
68
82
|
def warn?
|
69
|
-
@logger.warn_enabled?
|
83
|
+
@java ? @logger.warn_enabled? : @logger.warn?
|
70
84
|
end
|
71
85
|
|
72
86
|
def warn(*args, &block)
|
@@ -76,7 +90,7 @@ module Liquid
|
|
76
90
|
end
|
77
91
|
|
78
92
|
def error?
|
79
|
-
@logger.error_enabled?
|
93
|
+
@java ? @logger.error_enabled? : @logger.error?
|
80
94
|
end
|
81
95
|
|
82
96
|
def error(*args, &block)
|
data/lib/liquid/metrics.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
|
-
|
2
|
-
java_import 'com.codahale.metrics.
|
3
|
-
java_import 'com.codahale.metrics.
|
4
|
-
java_import '
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
java_import 'com.codahale.metrics.Histogram'
|
3
|
+
java_import 'com.codahale.metrics.JmxReporter'
|
4
|
+
java_import 'com.codahale.metrics.MetricRegistry'
|
5
|
+
java_import 'java.util.concurrent.TimeUnit'
|
5
6
|
|
6
|
-
class Histogram
|
7
|
-
|
8
|
-
end
|
7
|
+
class Histogram
|
8
|
+
java_alias :update_long, :update, [Java::long]
|
9
|
+
end
|
9
10
|
|
10
|
-
module Metrics
|
11
|
-
|
12
|
-
|
11
|
+
module Metrics
|
12
|
+
@registry = MetricRegistry.new
|
13
|
+
@reporters = []
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def self.start(period = nil, unit = nil)
|
16
|
+
@period ||= 60
|
17
|
+
@unit ||= TimeUnit::SECONDS
|
18
|
+
JmxReporter.forRegistry(@registry).build.start
|
19
|
+
Signal.register_shutdown_handler { stop }
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def self.stop
|
23
|
+
@reporters.each do |reporter|
|
24
|
+
reporter.run if reporter.respond_to?(:run)
|
25
|
+
reporter.stop
|
26
|
+
end
|
27
|
+
@reporters.clear
|
25
28
|
end
|
26
|
-
@reporters.clear
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def self.register_reporter(reporter)
|
31
|
+
reporter.start(@period, @unit)
|
32
|
+
@reporters << reporter
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def self.registry
|
36
|
+
@registry
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def self.counter(name)
|
40
|
+
registry.counter(name)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def self.meter(name)
|
44
|
+
registry.meter(name)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def self.histogram(name)
|
48
|
+
registry.histogram(name)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
def self.timer(name)
|
52
|
+
registry.timer(name)
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/liquid/server.rb
CHANGED
@@ -1,70 +1,72 @@
|
|
1
|
-
|
2
|
-
require 'liquid/
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
require 'liquid/metrics'
|
3
|
+
require 'liquid/tracker'
|
3
4
|
|
4
|
-
module Liquid
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
module Liquid
|
6
|
+
class Server
|
7
|
+
def initialize
|
8
|
+
$log.info("#{self.class.name.downcase} #{RUBY_DESCRIPTION}")
|
9
|
+
$log.info("#{self.class.name.downcase}", env: Env.mode)
|
10
|
+
Signal.register_shutdown_handler { System.exit(0) }
|
11
|
+
Signal.register_shutdown_handler { ZContext.destroy }
|
12
|
+
initialize_raven
|
13
|
+
initialize_tracker
|
14
|
+
initialize_metrics
|
15
|
+
initialize_health_checks
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def initialize_raven
|
19
|
+
return unless $conf.raven
|
20
|
+
require 'raven'
|
21
|
+
Raven.configure do |config|
|
22
|
+
config.dsn = $conf.raven.dsn
|
23
|
+
config.logger = $log
|
24
|
+
end
|
25
|
+
$log.add_exception_handler do |exc, message, attribs|
|
26
|
+
Raven.capture_exception(exc)
|
27
|
+
end
|
23
28
|
end
|
24
|
-
|
25
|
-
|
29
|
+
|
30
|
+
def initialize_tracker
|
31
|
+
if $conf.tracker.kafka.enabled
|
32
|
+
# http://kafka.apache.org/documentation.html#producerconfigs
|
33
|
+
properties = java.util.Properties.new
|
34
|
+
properties['metadata.broker.list'] = $conf.tracker.kafka.brokers.join(',')
|
35
|
+
properties['producer.type'] = 'async'
|
36
|
+
properties['serializer.class'] = 'kafka.serializer.StringEncoder'
|
37
|
+
$tracker = ::Tracker::KafkaTracker.new(properties, $conf.tracker.dimensions)
|
38
|
+
else
|
39
|
+
$tracker = ::Tracker::LoggerTracker.new($conf.tracker.dimensions)
|
40
|
+
end
|
41
|
+
Signal.register_shutdown_handler { $tracker.shutdown }
|
26
42
|
end
|
27
|
-
end
|
28
43
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
properties['metadata.broker.list'] = $conf.tracker.kafka.brokers.join(',')
|
34
|
-
properties['producer.type'] = 'async'
|
35
|
-
properties['serializer.class'] = 'kafka.serializer.StringEncoder'
|
36
|
-
$tracker = ::Tracker::KafkaTracker.new(properties, $conf.tracker.dimensions)
|
37
|
-
else
|
38
|
-
$tracker = ::Tracker::LoggerTracker.new($conf.tracker.dimensions)
|
44
|
+
def initialize_metrics
|
45
|
+
::Metrics.start
|
46
|
+
::Metrics::TrackerReporter.new($tracker.with_topic('metrics'))
|
47
|
+
Signal.register_shutdown_handler { ::Metrics.stop }
|
39
48
|
end
|
40
|
-
Signal.register_shutdown_handler { $tracker.shutdown }
|
41
|
-
end
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
def initialize_health_checks
|
51
|
+
Thread.new do
|
52
|
+
Thread.name = "Health Check"
|
53
|
+
HealthCheck.poll
|
54
|
+
end
|
55
|
+
end
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
57
|
+
def initialize_zmachine
|
58
|
+
require 'zmachine'
|
59
|
+
ZMachine.logger = $log
|
60
|
+
ZMachine.debug = true if $conf.zmachine.debug
|
61
|
+
ZMachine.heartbeat_interval = 0.1
|
62
|
+
Signal.register_shutdown_handler { ZMachine.stop }
|
53
63
|
end
|
54
|
-
end
|
55
64
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
ZMachine.heartbeat_interval = 0.1
|
61
|
-
Signal.register_shutdown_handler { ZMachine.stop }
|
62
|
-
end
|
65
|
+
def run
|
66
|
+
# by default wait for all workers
|
67
|
+
Thread.join
|
68
|
+
end
|
63
69
|
|
64
|
-
def run
|
65
|
-
# by default wait for all workers
|
66
|
-
Thread.join
|
67
70
|
end
|
68
|
-
|
69
71
|
end
|
70
72
|
end
|
data/lib/liquid/timing.rb
CHANGED
@@ -1,30 +1,32 @@
|
|
1
|
-
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
java_import 'java.lang.System'
|
2
3
|
|
3
|
-
module Timing
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
class TimingContext
|
9
|
-
def initialize
|
10
|
-
reset!
|
4
|
+
module Timing
|
5
|
+
def self.start
|
6
|
+
TimingContext.new
|
11
7
|
end
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
class TimingContext
|
10
|
+
def initialize
|
11
|
+
reset!
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rt
|
21
|
-
end
|
14
|
+
def reset!
|
15
|
+
@start = @last_tick = System.nano_time
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
def tick
|
19
|
+
rt = System.nano_time - @last_tick
|
20
|
+
@last_tick = System.nano_time
|
21
|
+
rt
|
22
|
+
end
|
23
|
+
|
24
|
+
def stop
|
25
|
+
rt = System.nano_time - @start
|
26
|
+
reset!
|
27
|
+
rt
|
28
|
+
end
|
28
29
|
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/liquid/tracker.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
require 'liquid/metrics
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
require 'liquid/metrics'
|
3
|
+
require 'liquid/metrics/tracker_reporter'
|
3
4
|
|
4
|
-
module Tracker
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Tracker
|
6
|
+
class Metrics
|
7
|
+
def self.event
|
8
|
+
(@events ||= ::Metrics.meter("tracker.events")).mark
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
Dir[File.expand_path("../tracker/*.rb", __FILE__)].each do |f|
|
13
|
-
|
13
|
+
Dir[File.expand_path("../tracker/*.rb", __FILE__)].each do |f|
|
14
|
+
require f
|
15
|
+
end
|
14
16
|
end
|
data/lib/liquid/trove.rb
CHANGED
@@ -1,71 +1,73 @@
|
|
1
|
-
|
2
|
-
java_import 'gnu.trove.
|
3
|
-
java_import 'gnu.trove.set.hash.
|
4
|
-
java_import 'gnu.trove.
|
5
|
-
java_import 'gnu.trove.map.hash.
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
java_import 'gnu.trove.TIntCollection'
|
3
|
+
java_import 'gnu.trove.set.hash.TIntHashSet'
|
4
|
+
java_import 'gnu.trove.set.hash.TLongHashSet'
|
5
|
+
java_import 'gnu.trove.map.hash.TIntObjectHashMap'
|
6
|
+
java_import 'gnu.trove.map.hash.TLongObjectHashMap'
|
6
7
|
|
7
|
-
module TMap
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
module TMap
|
9
|
+
def each
|
10
|
+
it = iterator
|
11
|
+
while it.has_next
|
12
|
+
it.advance
|
13
|
+
yield it.key, it.value
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
module TSet
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
module TSet
|
19
|
+
def each
|
20
|
+
it = iterator
|
21
|
+
while it.has_next
|
22
|
+
yield it.next
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def inspect
|
27
|
+
if size > 1000
|
28
|
+
"#{self.class.name}{too large to display,l=#{size}}"
|
29
|
+
else
|
30
|
+
to_string
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
class TLongObjectHashMap
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
35
|
+
class TLongObjectHashMap
|
36
|
+
include TMap
|
37
|
+
alias :has_key? :containsKey
|
38
|
+
alias :[] :get
|
39
|
+
alias :[]= :put
|
40
|
+
alias :length :size
|
41
|
+
alias :delete :remove
|
42
|
+
end
|
42
43
|
|
43
|
-
class TIntObjectHashMap
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
44
|
+
class TIntObjectHashMap
|
45
|
+
include TMap
|
46
|
+
alias :has_key? :containsKey
|
47
|
+
alias :[] :get
|
48
|
+
alias :[]= :put
|
49
|
+
alias :length :size
|
50
|
+
alias :delete :remove
|
51
|
+
end
|
51
52
|
|
52
|
-
class TLongHashSet
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
53
|
+
class TLongHashSet
|
54
|
+
include TSet
|
55
|
+
alias :include? :contains
|
56
|
+
alias :length :size
|
57
|
+
alias :delete :remove
|
58
|
+
end
|
58
59
|
|
59
|
-
class TIntHashSet
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
class TIntHashSet
|
61
|
+
include TSet
|
62
|
+
alias :include? :contains
|
63
|
+
alias :length :size
|
64
|
+
alias :delete :remove
|
64
65
|
|
65
|
-
|
66
|
+
java_alias :concat_ints, :addAll, [TIntCollection.java_class]
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def concat(list)
|
69
|
+
return if !list
|
70
|
+
concat_ints list
|
71
|
+
end
|
70
72
|
end
|
71
73
|
end
|
data/lib/liquid/zmq.rb
CHANGED
@@ -1,130 +1,132 @@
|
|
1
|
-
|
2
|
-
java_import "org.zeromq.
|
3
|
-
java_import "org.zeromq.
|
4
|
-
java_import "org.zeromq.
|
5
|
-
java_import "org.zeromq.
|
6
|
-
java_import "org.zeromq.
|
7
|
-
java_import "org.zeromq.
|
8
|
-
java_import "org.zeromq.
|
9
|
-
|
10
|
-
|
11
|
-
class
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
if RUBY_PLATFORM == "java"
|
2
|
+
java_import "org.zeromq.ZContext"
|
3
|
+
java_import "org.zeromq.ZFrame"
|
4
|
+
java_import "org.zeromq.ZLoop"
|
5
|
+
java_import "org.zeromq.ZMQ"
|
6
|
+
java_import "org.zeromq.ZMQException"
|
7
|
+
java_import "org.zeromq.ZMQQueue"
|
8
|
+
java_import "org.zeromq.ZMsg"
|
9
|
+
java_import "org.zeromq.ZThread"
|
10
|
+
|
11
|
+
class ZMQ
|
12
|
+
class Socket
|
13
|
+
# for performance reason we alias the method here (otherwise it uses reflections all the time!)
|
14
|
+
# super ugly, since we need to dynamically infer the java class of byte[]
|
15
|
+
java_alias :send_byte_buffer, :sendByteBuffer, [Java::JavaNio::ByteBuffer.java_class, Java::int]
|
16
|
+
java_alias :send_byte_array, :send, [[].to_java(:byte).java_class, Java::int]
|
17
|
+
java_alias :recv_byte_array, :recv, [Java::int]
|
18
|
+
|
19
|
+
def write(buffer)
|
20
|
+
bytes = send_byte_buffer(buffer, 0)
|
21
|
+
buffer.position(buffer.position + bytes)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
class ZContext
|
26
|
+
class ZContext
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def create_socket_with_opts(type, opts = {})
|
29
|
+
socket = create_socket(type)
|
30
|
+
opts.each do |key, value|
|
31
|
+
next if key == :bind || key == :connect
|
32
|
+
socket.__send__("#{key}=", value)
|
33
|
+
end
|
34
|
+
socket.connect(opts[:connect]) if opts[:connect]
|
35
|
+
socket.bind(opts[:bind]) if opts[:bind]
|
36
|
+
socket
|
32
37
|
end
|
33
|
-
socket.connect(opts[:connect]) if opts[:connect]
|
34
|
-
socket.bind(opts[:bind]) if opts[:bind]
|
35
|
-
socket
|
36
|
-
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def router(opts = {})
|
40
|
+
create_socket_with_opts(ZMQ::ROUTER, opts)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def dealer(opts = {})
|
44
|
+
create_socket_with_opts(ZMQ::DEALER, opts)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def push(opts = {})
|
48
|
+
create_socket_with_opts(ZMQ::PUSH, opts)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def pull(opts = {})
|
52
|
+
create_socket_with_opts(ZMQ::PULL, opts)
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def pub(opts = {})
|
56
|
+
create_socket_with_opts(ZMQ::PUB, opts)
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def sub(opts = {})
|
60
|
+
create_socket_with_opts(ZMQ::SUB, opts)
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
+
## global context instance
|
63
64
|
|
64
|
-
|
65
|
+
@mutex = Mutex.new
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
def self.instance
|
68
|
+
@mutex.synchronize do
|
69
|
+
@context ||= new
|
70
|
+
end
|
69
71
|
end
|
70
|
-
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
def self.create_socket(type)
|
74
|
+
instance.create_socket(type)
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
def self.destroy_socket(socket)
|
78
|
+
instance.destroy_socket(socket)
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
81
|
+
# really incredible how many exceptions a simple shutdown can throw all over
|
82
|
+
# the place. if it's one thing ZMQ did never get right it is the shutdown
|
83
|
+
# logic ...
|
84
|
+
def self.destroy
|
85
|
+
instance.destroy
|
86
|
+
rescue Java::JavaLang::IllegalStateException, Java::JavaLang::NullPointerException
|
87
|
+
# ignore broken shutdown in zeromq
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
90
|
+
DestroyExceptions = [
|
91
|
+
Java::JavaNioChannels::AsynchronousCloseException,
|
92
|
+
Java::JavaNioChannels::ClosedChannelException,
|
93
|
+
Java::JavaNioChannels::ClosedSelectorException,
|
94
|
+
]
|
95
|
+
|
96
|
+
Exceptions = DestroyExceptions + [
|
97
|
+
Java::OrgZeromq::ZMQException,
|
98
|
+
Java::Zmq::ZError::IOException,
|
99
|
+
]
|
100
|
+
|
101
|
+
def self.destroy_exception?(e)
|
102
|
+
return true if e.is_a?(Java::OrgZeromq::ZMQException) && ZMQ::Error::ETERM.getCode == e.getErrorCode
|
103
|
+
return true if e.is_a?(Java::Zmq::ZError::IOException) && DestroyExceptions.include?(e.cause.class)
|
104
|
+
return true if DestroyExceptions.include?(e.class)
|
105
|
+
return false
|
106
|
+
end
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
def self.router(opts = {})
|
109
|
+
instance.router(opts)
|
110
|
+
end
|
110
111
|
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
def self.dealer(opts = {})
|
113
|
+
instance.dealer(opts)
|
114
|
+
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
def self.push(opts = {})
|
117
|
+
instance.push(opts)
|
118
|
+
end
|
118
119
|
|
119
|
-
|
120
|
-
|
121
|
-
|
120
|
+
def self.pull(opts = {})
|
121
|
+
instance.pull(opts)
|
122
|
+
end
|
122
123
|
|
123
|
-
|
124
|
-
|
125
|
-
|
124
|
+
def self.pub(opts = {})
|
125
|
+
instance.pub(opts)
|
126
|
+
end
|
126
127
|
|
127
|
-
|
128
|
-
|
128
|
+
def self.sub(opts = {})
|
129
|
+
instance.sub(opts)
|
130
|
+
end
|
129
131
|
end
|
130
132
|
end
|
data/liquid-ext.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LiquidM, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|