Class: Txnap::Registry
- Inherits:
-
Object
- Object
- Txnap::Registry
- Defined in:
- lib/txnap/registry.rb
Instance Method Summary collapse
- #bind_transaction(connection, transaction) ⇒ Object
- #fetch(connection) ⇒ Object
- #finalize(connection, transaction) ⇒ Object
-
#initialize(&warning_handler) ⇒ Registry
constructor
A new instance of Registry.
- #reset! ⇒ Object
- #size ⇒ Object
- #start(connection, trace) ⇒ Object
Constructor Details
#initialize(&warning_handler) ⇒ Registry
Returns a new instance of Registry.
5 6 7 8 9 |
# File 'lib/txnap/registry.rb', line 5 def initialize(&warning_handler) @warning_handler = warning_handler @mutex = Mutex.new @traces = {}.compare_by_identity end |
Instance Method Details
#bind_transaction(connection, transaction) ⇒ Object
25 26 27 28 29 |
# File 'lib/txnap/registry.rb', line 25 def bind_transaction(connection, transaction) return unless transaction @mutex.synchronize { @traces[connection]&.bind_transaction(transaction) } end |
#fetch(connection) ⇒ Object
21 22 23 |
# File 'lib/txnap/registry.rb', line 21 def fetch(connection) @mutex.synchronize { @traces[connection] } end |
#finalize(connection, transaction) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/txnap/registry.rb', line 31 def finalize(connection, transaction) @mutex.synchronize do trace = @traces[connection] return unless trace matches_transaction = trace.matches_transaction?(transaction) matches_terminal_without_binding = trace.transaction.nil? && trace.terminal? return unless matches_transaction || matches_terminal_without_binding @traces.delete(connection) end end |
#reset! ⇒ Object
47 48 49 |
# File 'lib/txnap/registry.rb', line 47 def reset! @mutex.synchronize { @traces.clear } end |
#size ⇒ Object
43 44 45 |
# File 'lib/txnap/registry.rb', line 43 def size @mutex.synchronize { @traces.size } end |
#start(connection, trace) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/txnap/registry.rb', line 11 def start(connection, trace) stale_trace = @mutex.synchronize do stale = @traces[connection] @traces[connection] = trace stale end @warning_handler&.call("discarded a stale trace before a new BEGIN") if stale_trace trace end |