Class: Hazelcast::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/hazelcast-client.rb
Constant Summary
collapse
- GEM_ROOT =
File.expand_path(File.dirname(__FILE__))
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(username = nil, password = nil, host = nil) ⇒ Client
Returns a new instance of Client.
17
18
19
20
21
22
23
24
|
# File 'lib/hazelcast-client.rb', line 17
def initialize(username = nil, password = nil, host = nil)
@username = username || "dev"
@password = password || "dev-pass"
@host = host || "localhost"
@conn_id = self.class.connection_id @username, @password, @host
self.class.connect @username, @password, @host
client
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/hazelcast-client.rb', line 79
def method_missing(meth, *args, &blk)
if client.respond_to? meth
client.send meth, *args, &blk
else
super
end
end
|
Instance Attribute Details
#host ⇒ Object
java_import ‘java.util.Map’
15
16
17
|
# File 'lib/hazelcast-client.rb', line 15
def host
@host
end
|
#password ⇒ Object
java_import ‘java.util.Map’
15
16
17
|
# File 'lib/hazelcast-client.rb', line 15
def password
@password
end
|
#username ⇒ Object
java_import ‘java.util.Map’
15
16
17
|
# File 'lib/hazelcast-client.rb', line 15
def username
@username
end
|
Class Method Details
.connect(username, password, host) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/hazelcast-client.rb', line 95
def self.connect(username, password, host)
conn_id = connection_id(username, password, host)
if connections.key? conn_id
connections[conn_id]
else
puts ">> Connecting to [#{host}] as [#{username}] with [#{password}]..."
connections[conn_id] ||= HazelcastClient.newHazelcastClient username, password, host
end
end
|
.connection_id(username, password, host) ⇒ Object
91
92
93
|
# File 'lib/hazelcast-client.rb', line 91
def self.connection_id(username, password, host)
"#{username}:#{password}:#{host}"
end
|
.connections ⇒ Object
87
88
89
|
# File 'lib/hazelcast-client.rb', line 87
def self.connections
@connections ||= {}
end
|
Instance Method Details
#client ⇒ Object
26
27
28
|
# File 'lib/hazelcast-client.rb', line 26
def client
self.class.connections[@conn_id]
end
|
#cluster(name) ⇒ Object
30
31
32
|
# File 'lib/hazelcast-client.rb', line 30
def cluster(name)
client.getCluster name.to_s
end
|
#list(name) ⇒ Object
34
35
36
|
# File 'lib/hazelcast-client.rb', line 34
def list(name)
client.getList name.to_s
end
|
#lock(name) ⇒ Object
38
39
40
|
# File 'lib/hazelcast-client.rb', line 38
def lock(name)
client.getLock name.to_s
end
|
#map(name) ⇒ Object
42
43
44
|
# File 'lib/hazelcast-client.rb', line 42
def map(name)
client.getMap name.to_s
end
|
#multi_map(name) ⇒ Object
46
47
48
|
# File 'lib/hazelcast-client.rb', line 46
def multi_map(name)
client.getMultiMap name.to_s
end
|
#queue(name) ⇒ Object
50
51
52
|
# File 'lib/hazelcast-client.rb', line 50
def queue(name)
client.getQueue name.to_s
end
|
#respond_to?(meth) ⇒ Boolean
75
76
77
|
# File 'lib/hazelcast-client.rb', line 75
def respond_to?(meth)
super || client.respond_to?(meth)
end
|
#set(name) ⇒ Object
54
55
56
|
# File 'lib/hazelcast-client.rb', line 54
def set(name)
client.getSet name.to_s
end
|
#topic(name) ⇒ Object
58
59
60
|
# File 'lib/hazelcast-client.rb', line 58
def topic(name)
client.getTopic name.to_s
end
|
#transaction ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/hazelcast-client.rb', line 62
def transaction
txn = client.getTransaction
txn.begin
begin
yield
txn.commit
nil
rescue => e
txn.rollback
e
end
end
|