rubyhaze 0.0.2-jruby → 0.0.3-jruby
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.
- data/README.rdoc +7 -8
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/bin/{rh_console → rubyhaze_console} +0 -0
- data/jars/hazelcast-1.8.5.jar +0 -0
- data/jars/hazelcast-client-1.8.5.jar +0 -0
- data/lib/rubyhaze/client.rb +1 -1
- data/lib/rubyhaze/configs/config.rb +59 -0
- data/lib/rubyhaze/configs/group.rb +24 -0
- data/lib/rubyhaze/configs/map.rb +31 -0
- data/lib/rubyhaze/configs/network.rb +29 -0
- data/lib/rubyhaze/configs/queue.rb +30 -0
- data/lib/rubyhaze/configs/topic.rb +30 -0
- data/lib/rubyhaze/core_ext.rb +30 -9
- data/lib/rubyhaze/list.rb +2 -2
- data/lib/rubyhaze/lock.rb +2 -2
- data/lib/rubyhaze/map.rb +9 -9
- data/lib/rubyhaze/mixins/compare.rb +12 -0
- data/lib/rubyhaze/mixins/do_proxy.rb +27 -0
- data/lib/rubyhaze/mixins/native_exception.rb +13 -0
- data/lib/rubyhaze/mixins/proxy.rb +46 -0
- data/lib/rubyhaze/multi_map.rb +2 -2
- data/lib/rubyhaze/node.rb +1 -2
- data/lib/rubyhaze/queue.rb +2 -2
- data/lib/rubyhaze/set.rb +2 -2
- data/lib/rubyhaze/stores/fake_store.rb +11 -0
- data/lib/rubyhaze/topic.rb +3 -3
- data/lib/rubyhaze.rb +65 -25
- data/test/helper.rb +7 -0
- data/test/test_stored.rb +1 -2
- data/test/test_topic.rb +51 -0
- metadata +23 -9
- data/lib/rubyhaze/base_mixin.rb +0 -46
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
= rubyhaze
|
1
|
+
= rubyhaze
|
2
2
|
|
3
|
-
|
3
|
+
RubyHaze is a little gem that wraps the Java Hazelcast library into a more comfortable Ruby package (in JRuby, of course).
|
4
4
|
|
5
5
|
Hazelcast is an open source clustering and highly scalable data distribution platform for Java, which is:
|
6
6
|
|
@@ -13,10 +13,9 @@ Hazelcast is an open source clustering and highly scalable data distribution pla
|
|
13
13
|
|
14
14
|
Let's get the gem installed and test out the interactive console.
|
15
15
|
|
16
|
-
rvm jruby
|
17
|
-
gem install rubyhaze
|
18
|
-
|
19
|
-
rh_console
|
16
|
+
shell> rvm jruby
|
17
|
+
shell> gem install rubyhaze
|
18
|
+
shell> rubyhaze_console
|
20
19
|
|
21
20
|
hash = RH::Hash[:test]
|
22
21
|
hash[:a] = 1
|
@@ -24,7 +23,7 @@ Let's get the gem installed and test out the interactive console.
|
|
24
23
|
|
25
24
|
Let's open another console to check how this distributed hash works:
|
26
25
|
|
27
|
-
|
26
|
+
shell> rubyhaze_console
|
28
27
|
|
29
28
|
hash = RH::Hash[:test]
|
30
29
|
hash[:a]
|
@@ -35,7 +34,7 @@ Let's open another console to check how this distributed hash works:
|
|
35
34
|
|
36
35
|
Now let's share our own objects:
|
37
36
|
|
38
|
-
|
37
|
+
shell> rubyhaze_console
|
39
38
|
|
40
39
|
class Foo
|
41
40
|
include RubyHaze::Stored
|
data/Rakefile
CHANGED
@@ -7,12 +7,12 @@ begin
|
|
7
7
|
require 'jeweler'
|
8
8
|
Jeweler::Tasks.new do |gem|
|
9
9
|
gem.name = "rubyhaze"
|
10
|
-
gem.summary = %Q{JRuby
|
11
|
-
gem.description = %Q{
|
10
|
+
gem.summary = %Q{JRuby wrapper to play with Hazelcast}
|
11
|
+
gem.description = %Q{RubyHaze is a little gem that wraps the Java Hazelcast library into a more comfortable Ruby package (in JRuby, of course).}
|
12
12
|
gem.email = "aemadrid@gmail.com"
|
13
13
|
gem.homepage = "http://github.com/aemadrid/rubyhaze"
|
14
14
|
gem.authors = ["Adrian Madrid"]
|
15
|
-
gem.files = FileList['bin/*', 'lib/**/*.rb', 'test/**/*.rb', '[A-Z]*'].to_a
|
15
|
+
gem.files = FileList['bin/*', 'lib/**/*.rb', 'jars/**/*', 'test/**/*.rb', '[A-Z]*'].to_a
|
16
16
|
gem.test_files = Dir["test/test*.rb"]
|
17
17
|
gem.platform = "jruby"
|
18
18
|
gem.add_dependency "bitescript"
|
@@ -24,7 +24,7 @@ end
|
|
24
24
|
|
25
25
|
Rake::TestTask.new :test do |t|
|
26
26
|
t.libs << "lib"
|
27
|
-
t.test_files = FileList["test/**/
|
27
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
28
28
|
end
|
29
29
|
|
30
30
|
task :test => :check_dependencies
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
File without changes
|
Binary file
|
Binary file
|
data/lib/rubyhaze/client.rb
CHANGED
@@ -5,7 +5,7 @@ module RubyHaze
|
|
5
5
|
|
6
6
|
MODE = "client" unless defined? MODE
|
7
7
|
GEM_JAR_PATH = File.expand_path(File.dirname(__FILE__) + '/../../jars/hazelcast-client-1.8.5.jar') unless defined? GEM_JAR_PATH
|
8
|
-
JAR_PATH = ENV['
|
8
|
+
JAR_PATH = (ENV['HAZELCAST_CLIENT_JAR_PATH'] || GEM_JAR_PATH) unless defined? JAR_PATH
|
9
9
|
|
10
10
|
end
|
11
11
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/rubyhaze')
|
2
|
+
|
3
|
+
class RubyHaze::Config
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
|
7
|
+
java_import 'com.hazelcast.config.Config'
|
8
|
+
java_import 'java.net.URL'
|
9
|
+
java_import 'java.io.File'
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@proxy_object = Java::ComHazelcastConfig::Config.new
|
13
|
+
set_group options[:group]
|
14
|
+
set_network options[:network]
|
15
|
+
set_maps options[:maps]
|
16
|
+
set_queues options[:queues]
|
17
|
+
set_topics options[:topics]
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_group(options = nil)
|
21
|
+
options ||= RubyHaze::GroupConfig.default_options
|
22
|
+
proxy_object.setGroupConfig RubyHaze::GroupConfig.new(options).proxy_object
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_network(options = nil)
|
26
|
+
options ||= RubyHaze::NetworkConfig.default_options
|
27
|
+
proxy_object.setNetworkConfig RubyHaze::NetworkConfig.new(options).proxy_object
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_maps(hash = nil)
|
31
|
+
return if hash.nil? || hash.empty?
|
32
|
+
proxy_object.setMapConfigs hash.map{ |name, options| RubyHaze::MapConfig.new(name, options).proxy_object }
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_queues(hash = nil)
|
36
|
+
return if hash.nil? || hash.empty?
|
37
|
+
proxy_object.setMapQConfigs hash.map{ |name, options| RubyHaze::QueueConfig.new(name, options).proxy_object }
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_topics(hash = nil)
|
41
|
+
return if hash.nil? || hash.empty?
|
42
|
+
proxy_object.setTopicConfigs hash.map{ |name, options| RubyHaze::TopicConfig.new(name, options).proxy_object }
|
43
|
+
end
|
44
|
+
|
45
|
+
class << self
|
46
|
+
|
47
|
+
def yaml_hash
|
48
|
+
yml_path = File.expand_path('./hazelcast.yml')
|
49
|
+
YAML.load_file(yml_path) if File.file? yml_path
|
50
|
+
end
|
51
|
+
|
52
|
+
def new_from_yaml
|
53
|
+
hsh = yaml_hash
|
54
|
+
new(hsh) if hsh
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/rubyhaze')
|
2
|
+
|
3
|
+
class RubyHaze::GroupConfig
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
|
7
|
+
java_import 'com.hazelcast.config.GroupConfig'
|
8
|
+
|
9
|
+
proxy_accessors [:username, :name], :password
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@proxy_object = Java::ComHazelcastConfig::GroupConfig.new
|
13
|
+
options.each { |k,v| send "#{k}=", v }
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def default_options
|
19
|
+
{ :username => 'dev', :password => 'dev-pass' }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/rubyhaze')
|
2
|
+
|
3
|
+
class RubyHaze::MapConfig
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
|
7
|
+
java_import 'com.hazelcast.config.MapConfig'
|
8
|
+
|
9
|
+
proxy_accessors :backup_count, :eviction_delay_seconds, :eviction_percentage, :eviction_policy, :map_store_config,
|
10
|
+
:max_idle_seconds, :max_size, :name, :near_cache_config, :time_to_live_seconds
|
11
|
+
|
12
|
+
def initialize(name, options = nil)
|
13
|
+
@proxy_object = Java::ComHazelcastConfig::MapConfig.new
|
14
|
+
self.name = name.to_s
|
15
|
+
options ||= self.class.default_options
|
16
|
+
options.each { |k,v| send "#{k}=", v }
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
def default_options
|
22
|
+
{ :backup_count => 1, :eviction_policy => 'NONE', :max_size => 0, :eviction_percentage => 25 }
|
23
|
+
end
|
24
|
+
|
25
|
+
def [](name)
|
26
|
+
RubyHaze.config.map_config name.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/rubyhaze')
|
2
|
+
|
3
|
+
class RubyHaze::NetworkConfig
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
|
7
|
+
java_import 'com.hazelcast.config.NetworkConfig'
|
8
|
+
|
9
|
+
proxy_accessors [:global_ordering?, :global_ordering_enabled], :name
|
10
|
+
|
11
|
+
def initialize(name, options = nil)
|
12
|
+
@proxy_object = Java::ComHazelcastConfig::NetworkConfig.new
|
13
|
+
options ||= self.class.default_options
|
14
|
+
options.each { |k,v| send "#{k}=", v }
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
|
19
|
+
def default_options
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](name)
|
24
|
+
RubyHaze.config.topic_config name.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/rubyhaze')
|
2
|
+
|
3
|
+
class RubyHaze::QueueConfig
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
|
7
|
+
java_import 'com.hazelcast.config.QueueConfig'
|
8
|
+
|
9
|
+
proxy_accessors :max_size_per_jvm, :name, :time_to_live_seconds
|
10
|
+
|
11
|
+
def initialize(name, options = nil)
|
12
|
+
@proxy_object = Java::ComHazelcastConfig::QueueConfig.new
|
13
|
+
self.name = name.to_s
|
14
|
+
options ||= self.class.default_options
|
15
|
+
options.each { |k,v| send "#{k}=", v }
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
def default_options
|
21
|
+
{ :max_size_per_jvm => 10000, :time_to_live_seconds => 0 }
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](name)
|
25
|
+
RubyHaze.config.queue_config name.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/rubyhaze')
|
2
|
+
|
3
|
+
class RubyHaze::TopicConfig
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
|
7
|
+
java_import 'com.hazelcast.config.TopicConfig'
|
8
|
+
|
9
|
+
proxy_accessors [:global_ordering?, :global_ordering_enabled], :name
|
10
|
+
|
11
|
+
def initialize(name, options = nil)
|
12
|
+
@proxy_object = Java::ComHazelcastConfig::TopicConfig.new
|
13
|
+
self.name = name.to_s
|
14
|
+
options ||= self.class.default_options
|
15
|
+
options.each { |k,v| send "#{k}=", v }
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
def default_options
|
21
|
+
{}
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](name)
|
25
|
+
RubyHaze.config.topic_config name.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/rubyhaze/core_ext.rb
CHANGED
@@ -22,7 +22,7 @@ class Array
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Extracted from truthy (http://github.com/ymendel/truthy/tree/master/lib/truthy.rb)
|
25
|
-
# and Rails (http://github.com/rails/rails/commit/823b623fe2de8846c37aa13250010809ac940b57)
|
25
|
+
# and Rails (http://github.com/rails/rails/commit/823b623fe2de8846c37aa13250010809ac940b57)
|
26
26
|
|
27
27
|
class Object
|
28
28
|
|
@@ -47,7 +47,7 @@ class Object
|
|
47
47
|
# @people.try(:map) {|p| p.name}
|
48
48
|
#
|
49
49
|
def try(method, *args, &block)
|
50
|
-
send(method, *args, &block) if respond_to?(method
|
50
|
+
send(method, *args, &block) if respond_to?(method)
|
51
51
|
end
|
52
52
|
|
53
53
|
# List unique local methods
|
@@ -59,13 +59,6 @@ class Object
|
|
59
59
|
end
|
60
60
|
|
61
61
|
class String
|
62
|
-
def lines
|
63
|
-
self.split("\n").size
|
64
|
-
end
|
65
|
-
|
66
|
-
def valid_uuid_str(uuid)
|
67
|
-
end
|
68
|
-
|
69
62
|
def self.random_uuid
|
70
63
|
java.util.UUID.randomUUID.toString
|
71
64
|
end
|
@@ -73,4 +66,32 @@ class String
|
|
73
66
|
def valid_uuid?
|
74
67
|
!!(size == 36 && self =~ %r{^([A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12})$}i)
|
75
68
|
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Taken from ActiveSupport
|
72
|
+
class Hash
|
73
|
+
def slice(*keys)
|
74
|
+
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
75
|
+
hash = self.class.new
|
76
|
+
keys.each { |k| hash[k] = self[k] if has_key?(k) }
|
77
|
+
hash
|
78
|
+
end
|
79
|
+
|
80
|
+
def slice!(*keys)
|
81
|
+
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
82
|
+
omit = slice(*self.keys - keys)
|
83
|
+
hash = slice(*keys)
|
84
|
+
replace(hash)
|
85
|
+
omit
|
86
|
+
end
|
87
|
+
|
88
|
+
def except(*keys)
|
89
|
+
dup.except!(*keys)
|
90
|
+
end
|
91
|
+
|
92
|
+
def except!(*keys)
|
93
|
+
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
94
|
+
keys.each { |key| delete(key) }
|
95
|
+
self
|
96
|
+
end
|
76
97
|
end
|
data/lib/rubyhaze/list.rb
CHANGED
@@ -2,11 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::List
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
def initialize(name)
|
8
8
|
@name = name.to_s
|
9
|
-
@
|
9
|
+
@proxy_object = Hazelcast.get_list @name
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/lib/rubyhaze/lock.rb
CHANGED
@@ -2,11 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::Lock
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
def initialize(name)
|
8
8
|
@name = name.to_s
|
9
|
-
@
|
9
|
+
@proxy_object = Hazelcast.get_lock @name
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/lib/rubyhaze/map.rb
CHANGED
@@ -2,19 +2,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::Map
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
java_import 'com.hazelcast.query.SqlPredicate'
|
8
8
|
|
9
9
|
def initialize(name)
|
10
10
|
@name = name.to_s
|
11
|
-
@
|
11
|
+
@proxy_object = Hazelcast.get_map @name
|
12
12
|
rescue NativeException => x
|
13
13
|
rescue_native_exception x
|
14
14
|
end
|
15
15
|
|
16
16
|
def each
|
17
|
-
|
17
|
+
proxy_object.each do |(key, value)|
|
18
18
|
yield key, value
|
19
19
|
end
|
20
20
|
rescue NativeException => x
|
@@ -22,37 +22,37 @@ class RubyHaze::Map
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def [](key)
|
25
|
-
|
25
|
+
proxy_object[key.to_s]
|
26
26
|
rescue NativeException => x
|
27
27
|
rescue_native_exception x
|
28
28
|
end
|
29
29
|
|
30
30
|
def []=(key,value)
|
31
|
-
|
31
|
+
proxy_object[key.to_s] = value
|
32
32
|
rescue NativeException => x
|
33
33
|
rescue_native_exception x
|
34
34
|
end
|
35
35
|
|
36
36
|
def keys(predicate = nil)
|
37
|
-
|
37
|
+
proxy_object.key_set(prepare_predicate(predicate)).map
|
38
38
|
rescue NativeException => x
|
39
39
|
rescue_native_exception x
|
40
40
|
end
|
41
41
|
|
42
42
|
def values(predicate = nil)
|
43
|
-
|
43
|
+
proxy_object.values(prepare_predicate(predicate)).map
|
44
44
|
rescue NativeException => x
|
45
45
|
rescue_native_exception x
|
46
46
|
end
|
47
47
|
|
48
48
|
def local_keys(predicate = nil)
|
49
|
-
|
49
|
+
proxy_object.local_key_set(prepare_predicate(predicate)).map
|
50
50
|
rescue NativeException => x
|
51
51
|
rescue_native_exception x
|
52
52
|
end
|
53
53
|
|
54
54
|
def local_stats
|
55
|
-
lsm =
|
55
|
+
lsm = proxy_object.local_map_stats
|
56
56
|
{ :backup_count => lsm.backup_entry_count, :backup_memory => lsm.backup_entry_memory_cost,
|
57
57
|
:created => lsm.creation_time, :last_accessed => lsm.last_access_time, }
|
58
58
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RubyHaze
|
2
|
+
module Mixins
|
3
|
+
module DOProxy
|
4
|
+
|
5
|
+
include RubyHaze::Mixins::Proxy
|
6
|
+
include RubyHaze::Mixins::Compare
|
7
|
+
include RubyHaze::Mixins::NativeException
|
8
|
+
|
9
|
+
java_import 'com.hazelcast.core.Hazelcast'
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend ClassMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
|
19
|
+
def [](name)
|
20
|
+
new(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RubyHaze
|
2
|
+
module Mixins
|
3
|
+
module NativeException
|
4
|
+
|
5
|
+
def rescue_native_exception(exception)
|
6
|
+
exception = exception.cause while exception.cause
|
7
|
+
exception.print_stack_trace
|
8
|
+
raise RubyHaze::HazelcastException(exception)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RubyHaze
|
2
|
+
module Mixins
|
3
|
+
module Proxy
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :proxy_object
|
10
|
+
|
11
|
+
def respond_to?(meth)
|
12
|
+
proxy_object.respond_to?(meth) || super
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(meth, *args, &blk)
|
16
|
+
if proxy_object.respond_to? meth
|
17
|
+
proxy_object.send meth, *args, &blk
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
|
25
|
+
def proxy_accessor(aliased_name, real_name = nil)
|
26
|
+
real_name ||= aliased_name
|
27
|
+
aliased_name = aliased_name.to_s
|
28
|
+
if aliased_name[-1,1] == '?'
|
29
|
+
class_eval %{def #{aliased_name[0..-2]}() proxy_object.send :is_#{real_name}? end}
|
30
|
+
class_eval %{def #{aliased_name}() proxy_object.send :is_#{real_name}? end}
|
31
|
+
class_eval %{def #{aliased_name[0..-2]}=(v) proxy_object.send :set_#{real_name}, v end}
|
32
|
+
else
|
33
|
+
class_eval %{def #{aliased_name}() proxy_object.send :get_#{real_name}? end}
|
34
|
+
class_eval %{def #{aliased_name}=(v) proxy_object.send :set_#{real_name}, v end}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def proxy_accessors(*args)
|
39
|
+
args.each { |arg| proxy_accessor *arg }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/rubyhaze/multi_map.rb
CHANGED
@@ -2,11 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::MultiMap
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
def initialize(name)
|
8
8
|
@name = name.to_s
|
9
|
-
@
|
9
|
+
@proxy_object = Hazelcast.get_multi_map @name
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/lib/rubyhaze/node.rb
CHANGED
@@ -5,9 +5,8 @@ module RubyHaze
|
|
5
5
|
|
6
6
|
MODE = "node" unless defined? MODE
|
7
7
|
GEM_JAR_PATH = File.expand_path(File.dirname(__FILE__) + '/../../jars/hazelcast-1.8.5.jar') unless defined? GEM_JAR_PATH
|
8
|
-
JAR_PATH = ENV['
|
8
|
+
JAR_PATH = (ENV['HAZELCAST_NODE_JAR_PATH'] || GEM_JAR_PATH) unless defined? JAR_PATH
|
9
9
|
|
10
10
|
end
|
11
11
|
|
12
12
|
require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
13
|
-
|
data/lib/rubyhaze/queue.rb
CHANGED
@@ -2,11 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::Queue
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
def initialize(name)
|
8
8
|
@name = name.to_s
|
9
|
-
@
|
9
|
+
@proxy_object = Hazelcast.get_queue @name
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/lib/rubyhaze/set.rb
CHANGED
@@ -2,11 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::Set
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
def initialize(name)
|
8
8
|
@name = name.to_s
|
9
|
-
@
|
9
|
+
@proxy_object = Hazelcast.get_set @name
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -1,8 +1,19 @@
|
|
1
1
|
class RubyHaze::FakeStore
|
2
2
|
|
3
|
+
java_import 'com.hazelcast.core.MapLoader'
|
3
4
|
java_import 'com.hazelcast.core.MapStore'
|
4
5
|
|
5
6
|
include MapStore
|
7
|
+
include MapLoader
|
8
|
+
|
9
|
+
def load(key)
|
10
|
+
puts "[FakeStore] Loading key [#{key}]"
|
11
|
+
end
|
12
|
+
|
13
|
+
def load_all(keys)
|
14
|
+
puts "[FakeStore] Loading #{keys.size} keys"
|
15
|
+
keys.each { |key| load key }
|
16
|
+
end
|
6
17
|
|
7
18
|
def delete(key)
|
8
19
|
puts "[FakeStore] Deleting key [#{key}]"
|
data/lib/rubyhaze/topic.rb
CHANGED
@@ -2,20 +2,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../lib/rubyhaze')
|
|
2
2
|
|
3
3
|
class RubyHaze::Topic
|
4
4
|
|
5
|
-
include RubyHaze::
|
5
|
+
include RubyHaze::Mixins::DOProxy
|
6
6
|
|
7
7
|
java_import 'com.hazelcast.core.MessageListener'
|
8
8
|
|
9
9
|
def initialize(name)
|
10
10
|
@name = name.to_s
|
11
|
-
@
|
11
|
+
@proxy_object = Hazelcast.get_topic @name
|
12
12
|
end
|
13
13
|
|
14
14
|
def on_message(&blk)
|
15
15
|
klass = Class.new
|
16
16
|
klass.send :include, MessageListener
|
17
17
|
klass.send :define_method, :on_message, &blk
|
18
|
-
|
18
|
+
proxy_object.add_message_listener klass.new
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/lib/rubyhaze.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
raise "Rubyhaze only runs on JRuby. Sorry!" unless (RUBY_PLATFORM =~ /java/)
|
2
|
+
$: << File.dirname(__FILE__)
|
2
3
|
require 'java'
|
3
4
|
|
4
5
|
module RubyHaze
|
@@ -6,49 +7,88 @@ module RubyHaze
|
|
6
7
|
class Exception < StandardError; end
|
7
8
|
class HazelcastException < StandardError; end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
$CLASSPATH << TMP_PATH
|
14
|
-
|
15
|
-
unless defined? MODE
|
16
|
-
require LIB_PATH + '/' + (ENV['RUBYHAZE_MODE'] || 'node')
|
10
|
+
if $DEBUG
|
11
|
+
TMP_PATH = (ENV['RUBYHAZE_TMP_PATH'] || File.join(File.dirname(__FILE__), '..', 'TMP'))
|
12
|
+
$CLASSPATH << TMP_PATH
|
17
13
|
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
require JAR_PATH
|
22
|
-
java_import 'com.hazelcast.core.Hazelcast'
|
23
|
-
Hazelcast.get_cluster
|
24
|
-
puts ">> ... loaded!"
|
25
|
-
else
|
26
|
-
puts "ERROR! Could not find the Hazelcast JAR file in [#{JAR_PATH}]."
|
27
|
-
abort
|
15
|
+
unless defined? MODE
|
16
|
+
require 'rubyhaze/' + (ENV['RUBYHAZE_MODE'] || 'node')
|
28
17
|
end
|
29
18
|
|
30
|
-
|
31
|
-
|
19
|
+
unless @loaded
|
20
|
+
puts ">> Loading Hazelcast #{MODE} library ..."
|
21
|
+
if File.file?(JAR_PATH)
|
22
|
+
require JAR_PATH
|
23
|
+
puts ">> ... loaded!"
|
24
|
+
@loaded = true
|
25
|
+
else
|
26
|
+
puts "ERROR! Could not find the Hazelcast JAR file in [#{JAR_PATH}]."
|
27
|
+
abort
|
28
|
+
end
|
32
29
|
end
|
33
30
|
|
34
31
|
class << self
|
35
32
|
|
36
33
|
java_import 'com.hazelcast.core.Hazelcast'
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
# To start a cluster we can pass a hash of options or nil to load it from ./hazelcast.yml if available and a Config
|
36
|
+
# object will be generated.
|
37
|
+
def init(options = nil)
|
38
|
+
unless @connected
|
39
|
+
if options
|
40
|
+
config = RubyHaze::Config.new(options).proxy_object
|
41
|
+
Hazelcast.init config
|
42
|
+
end
|
43
|
+
at_exit do
|
44
|
+
puts ">> Shutting down Hazelcast ..."
|
45
|
+
Hazelcast.shutdown
|
46
|
+
puts ">> ... done!"
|
47
|
+
end
|
48
|
+
@connected = true
|
49
|
+
end
|
50
|
+
Hazelcast.cluster
|
40
51
|
end
|
41
52
|
|
42
|
-
|
43
|
-
|
53
|
+
# Proxying to Hazelcast class
|
54
|
+
def respond_to?(meth)
|
55
|
+
super || Hazelcast.respond_to?(meth)
|
44
56
|
end
|
45
57
|
|
46
|
-
|
47
|
-
|
58
|
+
# Proxying to Hazelcast class
|
59
|
+
def method_missing(meth, *args, &blk)
|
60
|
+
if Hazelcast.respond_to? meth
|
61
|
+
Hazelcast.send meth, *args, &blk
|
62
|
+
else
|
63
|
+
super
|
64
|
+
end
|
48
65
|
end
|
49
66
|
|
50
67
|
end
|
51
68
|
|
52
69
|
end
|
53
70
|
|
71
|
+
require 'rubyhaze/core_ext'
|
72
|
+
|
73
|
+
require 'rubyhaze/mixins/proxy'
|
74
|
+
require 'rubyhaze/mixins/compare'
|
75
|
+
require 'rubyhaze/mixins/native_exception'
|
76
|
+
require 'rubyhaze/mixins/do_proxy'
|
77
|
+
|
78
|
+
require 'rubyhaze/map'
|
79
|
+
require 'rubyhaze/multi_map'
|
80
|
+
require 'rubyhaze/set'
|
81
|
+
require 'rubyhaze/list'
|
82
|
+
require 'rubyhaze/queue'
|
83
|
+
require 'rubyhaze/topic'
|
84
|
+
require 'rubyhaze/lock'
|
85
|
+
|
86
|
+
require 'rubyhaze/configs/group'
|
87
|
+
require 'rubyhaze/configs/map'
|
88
|
+
require 'rubyhaze/configs/network'
|
89
|
+
require 'rubyhaze/configs/queue'
|
90
|
+
require 'rubyhaze/configs/config'
|
91
|
+
|
92
|
+
require 'rubyhaze/stored'
|
93
|
+
|
54
94
|
RH = RubyHaze unless defined? RH
|
data/test/helper.rb
ADDED
data/test/test_stored.rb
CHANGED
data/test/test_topic.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
class Notices
|
4
|
+
class << self
|
5
|
+
extend Forwardable
|
6
|
+
def all
|
7
|
+
@all ||= []
|
8
|
+
end
|
9
|
+
def_delegators :all, :size, :<<, :first, :last, :clear, :map
|
10
|
+
end
|
11
|
+
end unless defined? Notices
|
12
|
+
|
13
|
+
class TestListener
|
14
|
+
def initialize(name)
|
15
|
+
@name = name
|
16
|
+
end
|
17
|
+
def on_message(msg)
|
18
|
+
Notices << "[#{@name}] #{msg}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class TestRubyHazeTopic < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def test_block_listener
|
25
|
+
Notices.clear
|
26
|
+
topic = RubyHaze::Topic[:test_block]
|
27
|
+
topic.on_message do |msg|
|
28
|
+
Notices << "#{msg}"
|
29
|
+
end
|
30
|
+
assert_equal Notices.size, 0
|
31
|
+
topic.publish "Hola!"
|
32
|
+
sleep 0.25
|
33
|
+
assert_equal Notices.size, 1
|
34
|
+
assert_equal Notices.last, "Hola!"
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_class_listener
|
38
|
+
Notices.clear
|
39
|
+
topic = RubyHaze::Topic[:test_class]
|
40
|
+
topic.add_message_listener TestListener.new("test_class")
|
41
|
+
assert_equal Notices.size, 0
|
42
|
+
topic.publish "Hola!"
|
43
|
+
sleep 0.25
|
44
|
+
assert_equal Notices.size, 1
|
45
|
+
assert_equal Notices.last, "[test_class] Hola!"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_class2_listener
|
49
|
+
Notices.clear
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: jruby
|
11
11
|
authors:
|
12
12
|
- Adrian Madrid
|
@@ -14,8 +14,8 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
18
|
-
default_executable:
|
17
|
+
date: 2010-08-24 00:00:00 -06:00
|
18
|
+
default_executable: rubyhaze_console
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bitescript
|
@@ -29,10 +29,10 @@ dependencies:
|
|
29
29
|
version: "0"
|
30
30
|
type: :runtime
|
31
31
|
version_requirements: *id001
|
32
|
-
description:
|
32
|
+
description: RubyHaze is a little gem that wraps the Java Hazelcast library into a more comfortable Ruby package (in JRuby, of course).
|
33
33
|
email: aemadrid@gmail.com
|
34
34
|
executables:
|
35
|
-
-
|
35
|
+
- rubyhaze_console
|
36
36
|
extensions: []
|
37
37
|
|
38
38
|
extra_rdoc_files:
|
@@ -43,14 +43,25 @@ files:
|
|
43
43
|
- README.rdoc
|
44
44
|
- Rakefile
|
45
45
|
- VERSION
|
46
|
-
- bin/
|
46
|
+
- bin/rubyhaze_console
|
47
|
+
- jars/hazelcast-1.8.5.jar
|
48
|
+
- jars/hazelcast-client-1.8.5.jar
|
47
49
|
- lib/rubyhaze.rb
|
48
|
-
- lib/rubyhaze/base_mixin.rb
|
49
50
|
- lib/rubyhaze/client.rb
|
51
|
+
- lib/rubyhaze/configs/config.rb
|
52
|
+
- lib/rubyhaze/configs/group.rb
|
53
|
+
- lib/rubyhaze/configs/map.rb
|
54
|
+
- lib/rubyhaze/configs/network.rb
|
55
|
+
- lib/rubyhaze/configs/queue.rb
|
56
|
+
- lib/rubyhaze/configs/topic.rb
|
50
57
|
- lib/rubyhaze/core_ext.rb
|
51
58
|
- lib/rubyhaze/list.rb
|
52
59
|
- lib/rubyhaze/lock.rb
|
53
60
|
- lib/rubyhaze/map.rb
|
61
|
+
- lib/rubyhaze/mixins/compare.rb
|
62
|
+
- lib/rubyhaze/mixins/do_proxy.rb
|
63
|
+
- lib/rubyhaze/mixins/native_exception.rb
|
64
|
+
- lib/rubyhaze/mixins/proxy.rb
|
54
65
|
- lib/rubyhaze/multi_map.rb
|
55
66
|
- lib/rubyhaze/node.rb
|
56
67
|
- lib/rubyhaze/queue.rb
|
@@ -58,7 +69,9 @@ files:
|
|
58
69
|
- lib/rubyhaze/stored.rb
|
59
70
|
- lib/rubyhaze/stores/fake_store.rb
|
60
71
|
- lib/rubyhaze/topic.rb
|
72
|
+
- test/helper.rb
|
61
73
|
- test/test_stored.rb
|
74
|
+
- test/test_topic.rb
|
62
75
|
has_rdoc: true
|
63
76
|
homepage: http://github.com/aemadrid/rubyhaze
|
64
77
|
licenses: []
|
@@ -88,6 +101,7 @@ rubyforge_project:
|
|
88
101
|
rubygems_version: 1.3.6
|
89
102
|
signing_key:
|
90
103
|
specification_version: 3
|
91
|
-
summary: JRuby
|
104
|
+
summary: JRuby wrapper to play with Hazelcast
|
92
105
|
test_files:
|
93
106
|
- test/test_stored.rb
|
107
|
+
- test/test_topic.rb
|
data/lib/rubyhaze/base_mixin.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module RubyHaze::BaseMixin
|
2
|
-
|
3
|
-
java_import 'com.hazelcast.core.Hazelcast'
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.extend ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :name
|
10
|
-
|
11
|
-
def crc
|
12
|
-
@crc ||= RubyHaze.crc @name
|
13
|
-
end
|
14
|
-
|
15
|
-
def respond_to?(meth)
|
16
|
-
@hco.respond_to?(meth) || super
|
17
|
-
end
|
18
|
-
|
19
|
-
def method_missing(meth, *args, &blk)
|
20
|
-
if @hco.respond_to? meth
|
21
|
-
@hco.send meth, *args, &blk
|
22
|
-
else
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def ==(other)
|
28
|
-
return false unless other.class.name == self.class.name
|
29
|
-
name == other.name
|
30
|
-
end
|
31
|
-
|
32
|
-
def rescue_native_exception(exception)
|
33
|
-
exception = exception.cause while exception.cause
|
34
|
-
exception.print_stack_trace
|
35
|
-
raise RubyHaze::HazelcastException(exception)
|
36
|
-
end
|
37
|
-
|
38
|
-
module ClassMethods
|
39
|
-
|
40
|
-
def [](name)
|
41
|
-
new(name)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|