On 2010-12-09 17.58, Niclas Hedhman wrote:
Correction; Since I think the same ServiceImporter instance is used to
import all declared services;
module.importServices( Service1.class, Service2.class ).importedBy(
MyImporter.class );
a single instance of MyImporter is created and called twice
importService( ImportedServiceDescriptor )...
If so, then the release() method should have two arguments;
void release( ImportedServiceDescriptor desriptor , Object instance );
where instance is the same object returned in the importService method call.
WDYT?
Actually, no, for more complicated cases it is much better to have a
ServiceComposite implement ServiceImporter as it can then also implement
Activatable. I do this for a DataSource importer, which needs to keep
track of the pools, and shut them down on passivate. Works great! As the
ServiceImporter needs to be an object, I have a simple adapter that just
injects the real service into it and delegates.
Here's what the assembly looks like, so you can get a feel for how
things relate:
module.addServices( DataSourceService.class ).identifiedBy( "datasource"
).visibleIn( Visibility.application );
module.importServices( DataSource.class ).
importedBy( ServiceInstanceImporter.class ).
setMetaInfo( "datasource" ).
identifiedBy( "streamflowds" ).visibleIn( Visibility.application );
--
The ServiceInstanceImporter is completely generic, so I could add that
to to the org.qi4j.spi.service.importer package. It does a lookup of a
service that implements "ServiceImporter" and which has "datasource" as
service-id, which I then set as id for the real service.
DataSourceService implements ServiceImporter and Activatable.
Does that work for you?
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev