Class: ConnectionPool
- Inherits:
-
Object
- Object
- ConnectionPool
- Defined in:
- lib/active_rdf/federation/connection_pool.rb
Constant Summary collapse
- @@adapter_pool =
pool of all adapters
Array.new
- @@adapter_parameters =
pool of connection parameters to all adapter
Array.new
- @@registered_adapter_types =
adapters-classes known to the pool, registered by the adapter-class itself using register_adapter method, used to select new adapter-instance for requested connection type
Hash.new
Class Attribute Summary collapse
-
.write_adapter ⇒ Object
Returns the value of attribute write_adapter.
Class Method Summary collapse
- .adapter_types ⇒ Object
-
.add_data_source(connection_params) ⇒ Object
(also: add)
returns adapter-instance for given parameters (either existing or new).
-
.clear ⇒ Object
clears the pool: removes all registered data sources.
-
.flush ⇒ Object
flushes all openstanding changes into the original datasource.
-
.read_adapters ⇒ Object
returns the set of currently registered read-access datasources.
-
.register_adapter(type, klass) ⇒ Object
adapter-types can register themselves with connection pool by indicating which adapter-type they are.
Class Attribute Details
.write_adapter ⇒ Object
Returns the value of attribute write_adapter.
13 14 15 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 13 def write_adapter @write_adapter end |
Class Method Details
.adapter_types ⇒ Object
51 52 53 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 51 def ConnectionPool.adapter_types @@registered_adapter_types.keys end |
.add_data_source(connection_params) ⇒ Object Also known as: add
returns adapter-instance for given parameters (either existing or new)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 61 def ConnectionPool.add_data_source(connection_params) $log.info "ConnectionPool: add_data_source with params: #{connection_params.inspect}" # either get the adapter-instance from the pool # or create new one (and add it to the pool) index = @@adapter_parameters.index(connection_params) if index.nil? # adapter not in the pool yet: create it, # register its connection parameters in parameters-array # and add it to the pool (at same index-position as parameters) $log.debug("Create a new adapter for parameters #{connection_params.inspect}") adapter = create_adapter(connection_params) @@adapter_parameters << connection_params @@adapter_pool << adapter else # if adapter parametrs registered already, # then adapter must be in the pool, at the same index-position as its parameters $log.debug("Reusing existing adapter") adapter = @@adapter_pool[index] end # sets the adapter as current write-source if it can write self.write_adapter = adapter if adapter.writes? return adapter end |
.clear ⇒ Object
clears the pool: removes all registered data sources
39 40 41 42 43 44 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 39 def ConnectionPool.clear $log.info "ConnectionPool: clear called" @@adapter_pool = [] @@adapter_parameters = [] self.write_adapter = nil end |
.flush ⇒ Object
flushes all openstanding changes into the original datasource.
47 48 49 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 47 def ConnectionPool.flush write_adapter.flush end |
.read_adapters ⇒ Object
returns the set of currently registered read-access datasources
56 57 58 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 56 def ConnectionPool.read_adapters @@adapter_pool.select {|adapter| adapter.reads? } end |
.register_adapter(type, klass) ⇒ Object
adapter-types can register themselves with connection pool by indicating which adapter-type they are
96 97 98 99 |
# File 'lib/active_rdf/federation/connection_pool.rb', line 96 def ConnectionPool.register_adapter(type, klass) $log.info "ConnectionPool: registering adapter of type #{type} for class #{klass}" @@registered_adapter_types[type] = klass end |