sessionm-cassandra_object 2.4.7 → 2.4.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'with_connection'
|
2
|
+
|
1
3
|
module CassandraObject
|
2
4
|
module AsyncConnection
|
3
5
|
extend ActiveSupport::Concern
|
@@ -6,15 +8,6 @@ module CassandraObject
|
|
6
8
|
class_attribute :connection_spec
|
7
9
|
|
8
10
|
class_eval do
|
9
|
-
@@fiber_connections = {}
|
10
|
-
def self.fiber_connections
|
11
|
-
@@fiber_connections
|
12
|
-
end
|
13
|
-
|
14
|
-
def fiber_connections
|
15
|
-
self.class.fiber_connections
|
16
|
-
end
|
17
|
-
|
18
11
|
def self.new_event_machine_connection
|
19
12
|
spec = connection_spec.dup
|
20
13
|
|
@@ -66,22 +59,36 @@ module CassandraObject
|
|
66
59
|
end
|
67
60
|
|
68
61
|
@@schema = nil
|
69
|
-
|
70
|
-
|
62
|
+
@@connection_pool = nil
|
63
|
+
def self.connection_pool
|
64
|
+
@@connection_pool ||=
|
71
65
|
begin
|
72
|
-
|
73
|
-
new_event_machine_connection
|
74
|
-
else
|
75
|
-
new_connection
|
66
|
+
adapter_method = Proc.new do
|
67
|
+
EM.reactor_running? ? self.new_event_machine_connection : self.new_connection
|
76
68
|
end
|
69
|
+
spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, adapter_method
|
70
|
+
WithConnection::ConnectionPool.new "cassandra", spec
|
77
71
|
end
|
78
72
|
end
|
73
|
+
def connection_pool
|
74
|
+
self.class.connection_pool
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.connection()
|
78
|
+
self.connection_pool.connection
|
79
|
+
end
|
79
80
|
def self.connection?() !!connection end
|
80
81
|
|
82
|
+
def self.with_connection(&block)
|
83
|
+
self.connection_pool.with_connection(&block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def with_connection(&block)
|
87
|
+
self.class.with_connection(&block)
|
88
|
+
end
|
89
|
+
|
81
90
|
def self.disconnect!
|
82
|
-
|
83
|
-
conn.disconnect! if conn
|
84
|
-
}
|
91
|
+
self.connection_pool.disconnect!
|
85
92
|
end
|
86
93
|
|
87
94
|
def connection
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 2.4.
|
8
|
+
- 8
|
9
|
+
version: 2.4.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Koziarski
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-06-
|
19
|
+
date: 2013-06-04 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|