Hey,
Here is an example of Service instance selection which is done in the
actual class instead of in the assembly:
public class ServiceConsumer
{
private TestService service;
public ServiceConsumer( @Uses String id, @Service
Iterable<ServiceReference<TestService>> serviceRefs)
{
service = new ServiceSelector<TestService>(serviceRefs, id).get();
}
public TestService getService()
{
return service;
}
}
I'm creating a ServiceSelector which takes an iterable of Services as
input and the id to match. When the code calls get() it will iterate
over the available Services and find an instance whose Service identity
matches the given one.
This is a simple example of how to do service selection in the code. It
could do more advanced checks on the service, such as asking it for
other properties like "location", "capacity", "throughput" or whatever
makes sense. With this pattern you can do arbitrily complex "queries"
for Service instances, which was one of the ideas when we specifically
said that we do *not* want to be able to specify "names" in the @Service
injection annotation.
Makes sense?
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev