Hi,
On 11.08.2010, at 19:17, mhutton86 wrote:
>
> I have a service that I require
>
> @Requires(optional=true, id="tidget_devices", filter="(!(serviceName=file
> reader))")
> private TidgetSaasmDevice[] initialTidgets;
>
> but these TidgetSaasmDevices are not ready off the bat, and have to be added
> via late-binding
> @Bind(id="tidget_devices")
> private synchronized void addTidgetSaasmDevice(TidgetSaasmDevice newTidget)
> {...}
>
> @Unbind(id="tidget_devices")
> private synchronized void removeTidgetSaasmDevice(TidgetSaasmDevice
> newTidget){...}
>
> since TidgetSaasmDevice[] is an array. adding to it is a pain. so I have a
> List to take care of this.
>
> // dynamic list for adding tidgets
> private List<TidgetSaasmDevice> tidgets = new
> ArrayList<TidgetSaasmDevice>();
>
> but the problem when I start felix, is that a tidget is always loaded twice
> (random). due to the initial @Requires dependency trying to be fulfilled.
> @optional = true, won't solve this (not surprising). I can solve this by
> checking if this node is already added before trying to add it again. but
> this does not work ans is more of a hack then a fix.
There is several way to fix this issue:
1) Richard's idea (removing the @Requires)
@Bind(id="tidget_devices", optional="true", filter="(...)"
and
@Unbind(id="tidget_devices")
In the method, populate your own list.
2) Using your current code but without adding the services inside the list
Indeed, they are already injected by iPOJO, you don't need to add them to the
list. Moreover, iPOJO checks that each matching service are injected only once
in the list.
So,
@Requires TidgetSaasmDevice[] devices;
@Bind(id=......)
public void bind(TidgetSaasmDevice device) {
// 'device' is already present in the devices list.
}
The devices array does not only contain initial values but all current matching
services.
Regards,
Clement
>
> Any ideas?
>
> Example Output:
> adding: tidget-saasm COM22-0
> adding: tidget-saasm COM9-0
> adding: tidget-saasm COM22-1
> adding: tidget-saasm COM29-0
> --
> View this message in context:
> http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29410576.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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]