Module: Neo4jBolt::DriverRegistry

Defined in:
lib/neo4j_bolt.rb

Overview

Owns one process-wide upstream driver and its connection pool. Leases let cleanup wait for in-flight sessions without serializing independent queries.

Constant Summary collapse

LEASE_KEY =
:neo4j_bolt_driver_leases

Class Method Summary collapse

Class Method Details

.cleanupObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/neo4j_bolt.rb', line 145

def cleanup
  if Thread.current.thread_variable_get(LEASE_KEY).to_i.positive?
    raise Error, "cleanup_neo4j cannot run while this thread is using Neo4j"
  end

  driver = nil
  cleanup_started = false
  mutex.synchronize do
    condition.wait(mutex) while @closing
    @closing = true
    cleanup_started = true
    condition.wait(mutex) until leases.zero?
    driver = @driver
    @driver = nil
  end

  driver&.close
ensure
  if cleanup_started
    mutex.synchronize do
      @closing = false
      condition.broadcast
    end
  end
end

.with_driverObject



138
139
140
141
142
143
# File 'lib/neo4j_bolt.rb', line 138

def with_driver
  driver = acquire
  yield driver
ensure
  release if driver
end