You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by mhutton86 <mh...@navsys.com> on 2010/08/11 19:17:00 UTC

@requires with late-binding headaches

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.

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: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by "Richard S. Hall" <he...@ungoverned.org>.
  On 8/11/10 14:53, Richard S. Hall wrote:
>  On 8/11/10 14:46, mhutton86 wrote:
>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-@Bind 
>>
>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-@Requires 
>>
>>
>> Is where I was convinced about the mutual relationship between 
>> @Bind/Unbind,
>> and @Requires. But if what you are saying is true, that would be 
>> great and
>> would solve my problem. It is not working when i take away the @Requires
>> dependency and then the id parameter. Is there any chance you have a
>> resource of how to accomplish this?
>>
>> This would be greatly appreciated.
>
> I'm not sure what you're doing wrong, but even the reference card you 
> cited describes the two approaches as field vs method injection. I'm 
> not sure if the iPOJO docs include a method injection example.
>
> If you download the example code for our book (it's big):
>
>     http://code.google.com/p/osgi-in-action/
>
> The example in chapter12/paint-example-ip/ has a component 
> org.foo.paint which uses @Bind/@Unbind without @Requires.

p.s. The component in question is org.foo.paint.PaintFrame...

>
> -> richard
>
>> Mark-Anthony
>>
>>
>> Richard S. Hall wrote:
>>>    On 8/11/10 14:16, mhutton86 wrote:
>>> I am not sure.
>>>
>>> I do know that @Requires and @Bind/@Unbind are independent of each
>>> other, although they can be used together. There are basically two ways
>>> to have your dependencies injected:
>>>
>>>     1. Field injection (i.e., @Requires)
>>>     2. Method injection (i.e., @Bind/@Unbind)
>>>
>>> iPOJO does allow you to use both at the same time, but typically in 
>>> such
>>> situations the bind/unbind methods are more for notification 
>>> purposes or
>>> for obtaining service properties.
>>>
>>> ->  richard
>>>
>>>>
>>>> Richard S. Hall wrote:
>>>>>     If you have @Bind/@Unbind and use them to maintain your own list,
>>>>> then
>>>>> why do you need @Requires at all?
>>>>>
>>>>> ->   richard
>>>>>
>>>>> On 8/11/10 13: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.
>>>>>>
>>>>>> Any ideas?
>>>>>>
>>>>>> Example Output:
>>>>>> adding: tidget-saasm COM22-0
>>>>>> adding: tidget-saasm COM9-0
>>>>>> adding: tidget-saasm COM22-1
>>>>>> adding: tidget-saasm COM29-0
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>>
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by mhutton86 <mh...@navsys.com>.
Richard, 

I am currently downloading the osgi book as I write this. But going back
over what I did. I added the id's again to @Bind, and @Unbind, when I did
this. it now adds a TidgetSaasmDevice, but only 1, then only until i close
the GUI driving these binding functions do the rest get added before it[GUI]
is completely closed. 

I am confused as to why the GUI added them correctly (except for the copy)
when I had the @Requires, but not now? 

I apologize for all the questions, I am relatively new to the felix
framework. 

Mark-Anthony 


Richard S. Hall wrote:
> 
> I'm not sure what you're doing wrong, but even the reference card you 
> cited describes the two approaches as field vs method injection. I'm not 
> sure if the iPOJO docs include a method injection example.
> 
> If you download the example code for our book (it's big):
> 
>      http://code.google.com/p/osgi-in-action/
> 
> The example in chapter12/paint-example-ip/ has a component org.foo.paint 
> which uses @Bind/@Unbind without @Requires.
> 
> -> richard
> 
>> Mark-Anthony
>>
>>
>> Richard S. Hall wrote:
>>>    On 8/11/10 14:16, mhutton86 wrote:
>>> I am not sure.
>>>
>>> I do know that @Requires and @Bind/@Unbind are independent of each
>>> other, although they can be used together. There are basically two ways
>>> to have your dependencies injected:
>>>
>>>     1. Field injection (i.e., @Requires)
>>>     2. Method injection (i.e., @Bind/@Unbind)
>>>
>>> iPOJO does allow you to use both at the same time, but typically in such
>>> situations the bind/unbind methods are more for notification purposes or
>>> for obtaining service properties.
>>>
>>> ->  richard
>>>
>>>>
>>>> Richard S. Hall wrote:
>>>>>     If you have @Bind/@Unbind and use them to maintain your own list,
>>>>> then
>>>>> why do you need @Requires at all?
>>>>>
>>>>> ->   richard
>>>>>
>>>>> On 8/11/10 13: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.
>>>>>>
>>>>>> Any ideas?
>>>>>>
>>>>>> Example Output:
>>>>>> adding: tidget-saasm COM22-0
>>>>>> adding: tidget-saasm COM9-0
>>>>>> adding: tidget-saasm COM22-1
>>>>>> adding: tidget-saasm COM29-0
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>>
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29411700.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by "Richard S. Hall" <he...@ungoverned.org>.
  On 8/11/10 14:46, mhutton86 wrote:
> http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-@Bind
> http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-@Requires
>
> Is where I was convinced about the mutual relationship between @Bind/Unbind,
> and @Requires. But if what you are saying is true, that would be great and
> would solve my problem. It is not working when i take away the @Requires
> dependency and then the id parameter. Is there any chance you have a
> resource of how to accomplish this?
>
> This would be greatly appreciated.

I'm not sure what you're doing wrong, but even the reference card you 
cited describes the two approaches as field vs method injection. I'm not 
sure if the iPOJO docs include a method injection example.

If you download the example code for our book (it's big):

     http://code.google.com/p/osgi-in-action/

The example in chapter12/paint-example-ip/ has a component org.foo.paint 
which uses @Bind/@Unbind without @Requires.

-> richard

> Mark-Anthony
>
>
> Richard S. Hall wrote:
>>    On 8/11/10 14:16, mhutton86 wrote:
>> I am not sure.
>>
>> I do know that @Requires and @Bind/@Unbind are independent of each
>> other, although they can be used together. There are basically two ways
>> to have your dependencies injected:
>>
>>     1. Field injection (i.e., @Requires)
>>     2. Method injection (i.e., @Bind/@Unbind)
>>
>> iPOJO does allow you to use both at the same time, but typically in such
>> situations the bind/unbind methods are more for notification purposes or
>> for obtaining service properties.
>>
>> ->  richard
>>
>>>
>>> Richard S. Hall wrote:
>>>>     If you have @Bind/@Unbind and use them to maintain your own list,
>>>> then
>>>> why do you need @Requires at all?
>>>>
>>>> ->   richard
>>>>
>>>> On 8/11/10 13: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.
>>>>>
>>>>> Any ideas?
>>>>>
>>>>> Example Output:
>>>>> adding: tidget-saasm COM22-0
>>>>> adding: tidget-saasm COM9-0
>>>>> adding: tidget-saasm COM22-1
>>>>> adding: tidget-saasm COM29-0
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>
>>>>
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by mhutton86 <mh...@navsys.com>.
Richard,

I am currently downloading the osgi book as I write this. But going back
over what I did. I added the id's again to @Bind, and @Unbind, when I did
this. it now adds a TidgetSaasmDevice, but only 1, then only until i close
the GUI driving these binding functions do the rest get added before it[GUI]
is completely closed. 

I am confused as to why the GUI added them correctly (except for the copy)
when I had the @Requires, but not now?

I apologize for all the questions, I am relatively new to the felix
framework.

Mark-Anthony


Richard S. Hall wrote:
> 
>   On 8/11/10 14:16, mhutton86 wrote:
> I am not sure.
> 
> I do know that @Requires and @Bind/@Unbind are independent of each 
> other, although they can be used together. There are basically two ways 
> to have your dependencies injected:
> 
>    1. Field injection (i.e., @Requires)
>    2. Method injection (i.e., @Bind/@Unbind)
> 
> iPOJO does allow you to use both at the same time, but typically in such 
> situations the bind/unbind methods are more for notification purposes or 
> for obtaining service properties.
> 
> -> richard
> 
>>
>>
>> Richard S. Hall wrote:
>>>    If you have @Bind/@Unbind and use them to maintain your own list,
>>> then
>>> why do you need @Requires at all?
>>>
>>> ->  richard
>>>
>>> On 8/11/10 13: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.
>>>>
>>>> Any ideas?
>>>>
>>>> Example Output:
>>>> adding: tidget-saasm COM22-0
>>>> adding: tidget-saasm COM9-0
>>>> adding: tidget-saasm COM22-1
>>>> adding: tidget-saasm COM29-0
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> 



-- 
View this message in context: http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29411687.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by mhutton86 <mh...@navsys.com>.
http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-@Bind
http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-@Requires

Is where I was convinced about the mutual relationship between @Bind/Unbind,
and @Requires. But if what you are saying is true, that would be great and
would solve my problem. It is not working when i take away the @Requires
dependency and then the id parameter. Is there any chance you have a
resource of how to accomplish this?

This would be greatly appreciated.

Mark-Anthony


Richard S. Hall wrote:
> 
>   On 8/11/10 14:16, mhutton86 wrote:
> I am not sure.
> 
> I do know that @Requires and @Bind/@Unbind are independent of each 
> other, although they can be used together. There are basically two ways 
> to have your dependencies injected:
> 
>    1. Field injection (i.e., @Requires)
>    2. Method injection (i.e., @Bind/@Unbind)
> 
> iPOJO does allow you to use both at the same time, but typically in such 
> situations the bind/unbind methods are more for notification purposes or 
> for obtaining service properties.
> 
> -> richard
> 
>>
>>
>> Richard S. Hall wrote:
>>>    If you have @Bind/@Unbind and use them to maintain your own list,
>>> then
>>> why do you need @Requires at all?
>>>
>>> ->  richard
>>>
>>> On 8/11/10 13: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.
>>>>
>>>> Any ideas?
>>>>
>>>> Example Output:
>>>> adding: tidget-saasm COM22-0
>>>> adding: tidget-saasm COM9-0
>>>> adding: tidget-saasm COM22-1
>>>> adding: tidget-saasm COM29-0
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29411502.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by "Richard S. Hall" <he...@ungoverned.org>.
  On 8/11/10 14:16, mhutton86 wrote:
> Thank you for the quick reply Richard,
>
> To be honest, I did not know this could be done without the @Requires.
>
> Although when I try without the @Requires, @Bind does not pickup any new
> tidgets at all.
> according to http://felix.apache.org/site/ipojo-reference-card.html @
> "Configuring service dependencies in the instance configuration" It appears
> I need the @Requires with a matching (id) option.
>
> Unless there is something else that I am missing?

I am not sure.

I do know that @Requires and @Bind/@Unbind are independent of each 
other, although they can be used together. There are basically two ways 
to have your dependencies injected:

   1. Field injection (i.e., @Requires)
   2. Method injection (i.e., @Bind/@Unbind)

iPOJO does allow you to use both at the same time, but typically in such 
situations the bind/unbind methods are more for notification purposes or 
for obtaining service properties.

-> richard

>
>
> Richard S. Hall wrote:
>>    If you have @Bind/@Unbind and use them to maintain your own list, then
>> why do you need @Requires at all?
>>
>> ->  richard
>>
>> On 8/11/10 13: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.
>>>
>>> Any ideas?
>>>
>>> Example Output:
>>> adding: tidget-saasm COM22-0
>>> adding: tidget-saasm COM9-0
>>> adding: tidget-saasm COM22-1
>>> adding: tidget-saasm COM29-0
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by mhutton86 <mh...@navsys.com>.
Thank you for the quick reply Richard,

To be honest, I did not know this could be done without the @Requires. 

Although when I try without the @Requires, @Bind does not pickup any new
tidgets at all.
according to http://felix.apache.org/site/ipojo-reference-card.html @
"Configuring service dependencies in the instance configuration" It appears
I need the @Requires with a matching (id) option.

Unless there is something else that I am missing?



Richard S. Hall wrote:
> 
>   If you have @Bind/@Unbind and use them to maintain your own list, then 
> why do you need @Requires at all?
> 
> -> richard
> 
> On 8/11/10 13: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.
>>
>> Any ideas?
>>
>> Example Output:
>> adding: tidget-saasm COM22-0
>> adding: tidget-saasm COM9-0
>> adding: tidget-saasm COM22-1
>> adding: tidget-saasm COM29-0
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29411154.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by "Richard S. Hall" <he...@ungoverned.org>.
  If you have @Bind/@Unbind and use them to maintain your own list, then 
why do you need @Requires at all?

-> richard

On 8/11/10 13: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.
>
> Any ideas?
>
> Example Output:
> adding: tidget-saasm COM22-0
> adding: tidget-saasm COM9-0
> adding: tidget-saasm COM22-1
> adding: tidget-saasm COM29-0

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by Clement Escoffier <cl...@gmail.com>.
On 12.08.2010, at 16:50, mhutton86 wrote:

> 
> Hi Clement and also Richard,
> 
> I was able to remove @Requires, I was already populating my own list luckily
> so removing the @Requires array didn't break a thing.
> 
> I did have to set the aggregate option to true in the bind annotation
> eg: @Bind(aggregate=true, id="tidgets")

Right, dependencies are scalar (not aggregate) by default. iPOJO is able to detect the 'aggregate' flavor with @Requires as it can inspect the field type (array, list, set, collection...). However, with bind method it can't be detected 'magically'.

Regards,

Clement

> 
> because I would only have one tidget be bound, and only until i decided to
> close the bundle waiting on tidgets did the rest load. aggregate fixed this,
> all the tidgets loaded correctly in the beginning and if any additional
> tidgets were added. This didn't quite solve my original problem, but I now
> believe the problem is not with this, but a @Publisher, @Subscriber setup I
> have. I will make a new post once I have more information.
> 
> Thanks to both of you for your help.
> 
> Mark-Anthony Hutton
> 
> 
> clement escoffier wrote:
>> 
>> Hi,
>> 
>> On 11.08.2010, at 19:17, mhutton86 wrote:
>> 
>> 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
>> 
>> 
> 
> -- 
> View this message in context: http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29419552.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by mhutton86 <mh...@navsys.com>.
Hi Clement and also Richard,

I was able to remove @Requires, I was already populating my own list luckily
so removing the @Requires array didn't break a thing.

I did have to set the aggregate option to true in the bind annotation
eg: @Bind(aggregate=true, id="tidgets")

because I would only have one tidget be bound, and only until i decided to
close the bundle waiting on tidgets did the rest load. aggregate fixed this,
all the tidgets loaded correctly in the beginning and if any additional
tidgets were added. This didn't quite solve my original problem, but I now
believe the problem is not with this, but a @Publisher, @Subscriber setup I
have. I will make a new post once I have more information.

Thanks to both of you for your help.

Mark-Anthony Hutton


clement escoffier wrote:
> 
> Hi,
> 
> On 11.08.2010, at 19:17, mhutton86 wrote:
> 
> 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
> 
> 

-- 
View this message in context: http://old.nabble.com/%40requires-with-late-binding-headaches-tp29410576p29419552.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: @requires with late-binding headaches

Posted by Clement Escoffier <cl...@gmail.com>.
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: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org