Class: Dolphin::DataStore::Cassandra
- Inherits:
-
Object
- Object
- Dolphin::DataStore::Cassandra
show all
- Includes:
- Util
- Defined in:
- lib/dolphin/data_stores/cassandra.rb
Defined Under Namespace
Classes: UnAvailableNodeException
Constant Summary
collapse
- PATH_SEPARATOR =
':'.freeze
Instance Method Summary
collapse
Methods included from Util
#logger
Constructor Details
#initialize(config) ⇒ Cassandra
Returns a new instance of Cassandra.
27
28
29
30
31
32
33
34
35
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 27
def initialize(config)
@keyspace = config[:keyspace]
raise "database hosts is blank" if config[:hosts].blank?
@hosts = config[:hosts].split(',')
@port = config[:port]
@max_retry_count = config[:max_retry_count] || 3
@retry_interval = config[:retry_interval] || 3
@retry_count = 0
end
|
Instance Method Details
#closed? ⇒ Boolean
63
64
65
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 63
def closed?
@connection.nil?
end
|
#connect ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 37
def connect
begin
if @connection.nil?
@connection = ::Cassandra.new(@keyspace, seeds)
@connection.ring
return @connection
end
rescue ThriftClient::NoServersAvailable => e
logger :error, e
@connection = nil
if @retry_count < @max_retry_count
@retry_count += 1
logger :error, "retry connection..#{@retry_count}"
sleep @retry_interval
retry
end
rescue UnAvailableNodeException => e
logger :error, e
rescue CassandraThrift::InvalidRequestException => e
logger :error, e
end
@connection
end
|
#delete_notification(notification) ⇒ Object
87
88
89
90
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 87
def delete_notification(notification)
n = Dolphin::Models::Cassandra::Notification.new(@connection)
n.delete(notification)
end
|
#get_event(params) ⇒ Object
77
78
79
80
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 77
def get_event(params)
e = Dolphin::Models::Cassandra::Event.new(@connection)
e.get(params)
end
|
#get_notification(id) ⇒ Object
#put_event(event) ⇒ Object
72
73
74
75
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 72
def put_event(event)
e = Dolphin::Models::Cassandra::Event.new(@connection)
e.put(event)
end
|
#put_notification(id, methods) ⇒ Object
82
83
84
85
|
# File 'lib/dolphin/data_stores/cassandra.rb', line 82
def put_notification(id, methods)
n = Dolphin::Models::Cassandra::Notification.new(@connection)
n.put(id, methods)
end
|