Il 12/15/20 6:34 PM, Eric Norman ha scritto:
For simplicity, you could probably let the framework do a bit more work for
you and remove the need for the BundleContext field by using the reference
bind method technique that sends you the service instance + the properties.

For example, something like this:

private Map<String, DataSource> dataSources = new ConcurrentHashMap<>();

@Reference(service=DataSource.class, policy = DYNAMIC, cardinality=MULTIPLE)
void bindDataSource(DataSource ds, Map<String, Object> properties) {
     dataSources.put((String) properties.getProperty("datasource.name"), ds);
}

void unbindDataSource(DataSource ds, Map<String, Object> properties) {
     dataSources.remove((String) properties.getProperty("datasource.name"),
ds);
}


On Tue, Dec 15, 2020 at 8:13 AM Bertrand Delacretaz <bdelacre...@apache.org>
wrote:

On Tue, Dec 15, 2020 at 4:58 PM Robert Munteanu <romb...@apache.org>
wrote:
...This way you get the datasources injected and via SCR and you get to
use the datasource.name as a key...
sounds good and it's certainly more efficient than what I suggested.

-Bertrand

Thank you Bertrand and Eric !
Your solution works fine !


--
Nicola Cisternino
CTO - Ergon Project Manager - IT Architect
Cointa s.r.l.
Tel. +39 080 9371015
ncis...@cointa.it
http://www.cointa.it

Reply via email to