Clement Escoffier a écrit :
Hi,

On 28.06.2010, at 18:27, Joel Schuster wrote:

Having a little issue with @Requires within iPojo.

I have an interface (in my case it's called Communications).

I also have various implementations of that interface. Within a specific Felix 
runtime environment there may be multiple instances of a specific 
implementation (in my case numerous UDPService implementations) and also 
multiple different implementation instances (both UDPService and SerialService 
for example) ... all with the same Interface implemented.

Using @Requires causes some problems:

@Requires
Communications[] comms;

This ends up giving me all the instances that implement the Communications 
interface. But only those that have started before the component that has the 
@Requires. There doesn't seem to be any way to guarantee that all the component 
instances are started before the array is put together.

Even when I use the 'Default-Implementation' attribute this still doesn't give 
me all of them.

I'd like to use a 'Filter' attribute but am having a hard time there too. I've 
also created a ServiceName interface for all my services to implement that 
allows me to 'manually' filter through the array based on name. However, if I 
use something like this:

@Requires
ServiceName[] allMyServices;

I can't cast back to the other interface to do the job that I need.


Anyhow. I think there must be a better way that I'm doing it! One thought was 
to use the ServiceListener interface and wait for everything I'm dependant upon 
to come up before doing any work.

It just seems to be a very non-ipojo way of going about things.

Any thoughts would be welcome.

The issue here is that the instance is created and started before all Communication services are exposed. So, you only get the services exposed at the injection time. There is now way currently to know that all services are exposed because it can change at anytime.
Using @Bind / @Unbind method will allow you to be notified when a new service 
will arrive (or disappear), but you cannot be sure that a new service will not 
arrive later.

If you know the number of services that must be injected, you can wait until they are. Or, you can also introduce a start order to be sure that services are exposed before the consumption.
You can use also the Whiteboard Pattern Handler

http://felix.apache.org/site/white-board-pattern-handler.html

Kind regards

Didier

Regards,

Clement


- Joel





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]





--
--------------------------------------------------------------
Didier DONSEZ

Laboratoire LIG, Equipe ADELE
Universite Joseph Fourier
Bat. C, 220 rue de la Chimie, Domaine Universitaire
BP 53, 38041 Grenoble Cedex 9, France
Tel : +33 4 76 63 55 49           Fax : +33 4 76 63 55 50
GPS : lat 45° 11' 38.28" lon 5° 46' 14.79" E, alt 223m

mailto:[email protected]
URL: http://membres-liglab.imag.fr/donsez
Map:http://membres-liglab.imag.fr/donsez/map/map.html
--------------------------------------------------------------

Reply via email to