Class: Keymap::ConnectionAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- Keymap::ConnectionAdapters::AbstractAdapter
- Includes:
- ActiveSupport::Callbacks, DataManagement, TransactionManagement, MonitorMixin
- Defined in:
- lib/keymap/connection_adapters/abstract_adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#in_use ⇒ Object
(also: #in_use?)
readonly
Returns the value of attribute in_use.
-
#last_use ⇒ Object
readonly
Returns the value of attribute last_use.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#pool ⇒ Object
Returns the value of attribute pool.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks whether the connection to the database is still active.
-
#adapter_name ⇒ Object
Returns the human-readable name of the adapter.
-
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
-
#clear_cache! ⇒ Object
Clear any caching the kv-store adapter may be doing.
-
#close ⇒ Object
Check the connection back in to the connection pool.
-
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
-
#disconnect! ⇒ Object
Disconnects from the kv-store if already connected.
- #expire ⇒ Object
-
#initialize(connection, logger = nil, pool = nil) ⇒ AbstractAdapter
constructor
:nodoc:.
- #lease ⇒ Object
-
#raw_connection ⇒ Object
Provides access to the underlying kv-store driver for this adapter.
-
#reconnect! ⇒ Object
Disconnects from the database if already connected, and establishes a new connection with the database.
-
#requires_reloading? ⇒ Boolean
Returns true if its required to reload the connection between requests for development mode.
-
#reset! ⇒ Object
Reset the state of this connection, directing the kv-store to clear transactions and other connection-related server-side state.
-
#rollback_db_transaction ⇒ Object
Rolls back the transaction (and turns on auto-committing).
-
#verify! ⇒ Object
Checks whether the connection to the kv-store is still active (i.e. not stale).
Methods included from DataManagement
Methods included from TransactionManagement
#outside_transaction?, #transaction
Constructor Details
#initialize(connection, logger = nil, pool = nil) ⇒ AbstractAdapter
:nodoc:
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 32 def initialize(connection, logger = nil, pool = nil) #:nodoc: super() @active = nil @connection = connection @logger = logger @pool = pool @in_use = false @last_use = false end |
Instance Attribute Details
#in_use ⇒ Object (readonly) Also known as: in_use?
Returns the value of attribute in_use.
29 30 31 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 29 def in_use @in_use end |
#last_use ⇒ Object (readonly)
Returns the value of attribute last_use.
29 30 31 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 29 def last_use @last_use end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
29 30 31 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 29 def logger @logger end |
#pool ⇒ Object
Returns the value of attribute pool.
28 29 30 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 28 def pool @pool end |
Instance Method Details
#active? ⇒ Boolean
Checks whether the connection to the database is still active. This includes checking whether the kv-store is actually capable of responding, i.e. whether the connection isn’t stale.
68 69 70 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 68 def active? @active end |
#adapter_name ⇒ Object
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
59 60 61 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 59 def adapter_name 'Abstract' end |
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
122 123 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 122 def begin_db_transaction() end |
#clear_cache! ⇒ Object
Clear any caching the kv-store adapter may be doing. This is kv-store specific.
97 98 99 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 97 def clear_cache! # this should be overridden by concrete adapters end |
#close ⇒ Object
Check the connection back in to the connection pool
135 136 137 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 135 def close pool.checkin self end |
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
126 127 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 126 def commit_db_transaction() end |
#disconnect! ⇒ Object
Disconnects from the kv-store if already connected. Otherwise, this method does nothing.
80 81 82 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 80 def disconnect! @active = false end |
#expire ⇒ Object
53 54 55 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 53 def expire @in_use = false end |
#lease ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 44 def lease synchronize do unless in_use @in_use = true @last_use = Time.now end end end |
#raw_connection ⇒ Object
Provides access to the underlying kv-store driver for this adapter. For example, this method returns a Redis object in case of RedisAdapter.
This is useful for when you need to call a proprietary method.
117 118 119 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 117 def raw_connection @connection end |
#reconnect! ⇒ Object
Disconnects from the database if already connected, and establishes a new connection with the database.
74 75 76 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 74 def reconnect! @active = true end |
#requires_reloading? ⇒ Boolean
Returns true if its required to reload the connection between requests for development mode.
102 103 104 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 102 def requires_reloading? false end |
#reset! ⇒ Object
Reset the state of this connection, directing the kv-store to clear transactions and other connection-related server-side state. Usually a implementation-dependent operation.
The default implementation does nothing; the implementation should be overridden by concrete adapters.
90 91 92 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 90 def reset! # this should be overridden by concrete adapters end |
#rollback_db_transaction ⇒ Object
Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
131 132 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 131 def rollback_db_transaction() end |
#verify! ⇒ Object
Checks whether the connection to the kv-store is still active (i.e. not stale). This is done under the hood by calling active?. If the connection is no longer active, then this method will reconnect to the kv-store.
109 110 111 |
# File 'lib/keymap/connection_adapters/abstract_adapter.rb', line 109 def verify! reconnect! unless active? end |