Class: Neo4j::Core::CypherSession::Adaptors::DriverRegistry

Inherits:
Hash
  • Object
show all
Includes:
Singleton
Defined in:
lib/neo4j/core/cypher_session/adaptors/driver.rb

Overview

The registry is necessary due to the specs constantly creating new CypherSessions. Closing a driver is costly. Not closing it prevents the process from termination. The registry allows reusage of drivers which are thread safe and conveniently closing them in one call.

Instance Method Summary collapse

Constructor Details

#initializeDriverRegistry

Returns a new instance of DriverRegistry



21
22
23
24
# File 'lib/neo4j/core/cypher_session/adaptors/driver.rb', line 21

def initialize
  super
  @mutex = Mutex.new
end

Instance Method Details

#close(driver) ⇒ Object



38
39
40
41
# File 'lib/neo4j/core/cypher_session/adaptors/driver.rb', line 38

def close(driver)
  delete(key(driver))
  driver.close
end

#close_allObject



43
44
45
46
# File 'lib/neo4j/core/cypher_session/adaptors/driver.rb', line 43

def close_all
  values.each(&:close)
  clear
end

#driver_for(url) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/neo4j/core/cypher_session/adaptors/driver.rb', line 26

def driver_for(url)
  uri = URI(url)
  user = uri.user
  password = uri.password
  auth_token = if user
                 Neo4j::Driver::AuthTokens.basic(user, password)
               else
                 Neo4j::Driver::AuthTokens.none
               end
  @mutex.synchronize { self[url] ||= Neo4j::Driver::GraphDatabase.driver(url, auth_token) }
end