You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by John Stump <jo...@Navsys.com> on 2009/07/15 00:19:31 UTC

iPOJO temporary service instances?

There is a pattern I am trying to recreate within the iPOJO world, but I can't quite figure it out.

I want to be able to look up a service, create an instance of it, use it, and toss it away. What iPOJO seems to support is creating instances of services up front and have them ready and waiting. But I don't want that. I want a service to be instantiated on demand. How do I do this?

One thought I had was to not create an instance of the service in the metadata.xml, then the client can get the factory of the service, create an instance, then discard it when it is through with it. But this approach seems somewhat clumsy. Is there a better way?

Thanks!

john

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


Re: iPOJO temporary service instances?

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

On 15.07.2009, at 17:27, John Stump wrote:

> Yes, I have been reading about that, and I might go this route. I  
> also saw mentioned that the @Provides annotation supports a  
> "strategy" property to allow me to create a new instance for every  
> request, another requirement I have. Something like this:
>
> @Provides(strategy="instance")
>
> However, "strategy" is not documented in the iPOJO reference card at http://felix.apache.org/site/ipojo-reference-card.html 
> . Is strategy an officially supported property? Will I run into  
> problems in the future if I use it?

It is supported, just the doc is somewhat incomplete ....
Some more info are available here : http://ipojo-dark-side.blogspot.com/2009/04/customized-service-object-creation-with.html

In fact, it allows you to configure when service objects will be  
created and deleted. You can provide your own strategy (one per  
thread, limited life time ...). So, you create an instance providing a  
service. As soon as another iPOJO instance (it must be an iPOJO  
instance because the interaction pattern is different) uses this  
service, the creation strategy is applied. It might be useful in your  
case.

iPOJO provides several creation strategy:
- singleton : create one service object
- OSGi service factory : create one service object per asking bundle
- per instance : create one service object per component instance

In all case, those object are created only when required.

The main difference between creating / deleting instances and using a  
creation strategy is that you're not on the same layer : the first one  
creates component instances, the second one creates pojo objects.

Regards,

Clement


>
> Thanks for your help!
>
> john
>
> -----Original Message-----
> From: Clement Escoffier [mailto:clement.escoffier@gmail.com]
> Sent: Wednesday, July 15, 2009 9:21 AM
> To: users@felix.apache.org
> Subject: Re: iPOJO temporary service instances?
>
>
> On 15.07.2009, at 00:19, John Stump wrote:
>
>> There is a pattern I am trying to recreate within the iPOJO world,
>> but I can't quite figure it out.
>>
>> I want to be able to look up a service, create an instance of it,
>> use it, and toss it away. What iPOJO seems to support is creating
>> instances of services up front and have them ready and waiting. But
>> I don't want that. I want a service to be instantiated on demand.
>> How do I do this?
>>
>> One thought I had was to not create an instance of the service in
>> the metadata.xml, then the client can get the factory of the
>> service, create an instance, then discard it when it is through with
>> it. But this approach seems somewhat clumsy. Is there a better way?
>>
>
> By the way, iPOJO creates service objects only when they are needed
> (laziness) except if you configure it to be immediate.
>
>
>
> ---------------------------------------------------------------------
> 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: iPOJO temporary service instances?

Posted by John Stump <jo...@Navsys.com>.
Yes, I have been reading about that, and I might go this route. I also saw mentioned that the @Provides annotation supports a "strategy" property to allow me to create a new instance for every request, another requirement I have. Something like this:

@Provides(strategy="instance")

However, "strategy" is not documented in the iPOJO reference card at http://felix.apache.org/site/ipojo-reference-card.html. Is strategy an officially supported property? Will I run into problems in the future if I use it?

Thanks for your help!

john

-----Original Message-----
From: Clement Escoffier [mailto:clement.escoffier@gmail.com] 
Sent: Wednesday, July 15, 2009 9:21 AM
To: users@felix.apache.org
Subject: Re: iPOJO temporary service instances?


On 15.07.2009, at 00:19, John Stump wrote:

> There is a pattern I am trying to recreate within the iPOJO world,  
> but I can't quite figure it out.
>
> I want to be able to look up a service, create an instance of it,  
> use it, and toss it away. What iPOJO seems to support is creating  
> instances of services up front and have them ready and waiting. But  
> I don't want that. I want a service to be instantiated on demand.  
> How do I do this?
>
> One thought I had was to not create an instance of the service in  
> the metadata.xml, then the client can get the factory of the  
> service, create an instance, then discard it when it is through with  
> it. But this approach seems somewhat clumsy. Is there a better way?
>

By the way, iPOJO creates service objects only when they are needed  
(laziness) except if you configure it to be immediate.



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


Re: iPOJO temporary service instances?

Posted by Clement Escoffier <cl...@gmail.com>.
On 15.07.2009, at 00:19, John Stump wrote:

> There is a pattern I am trying to recreate within the iPOJO world,  
> but I can't quite figure it out.
>
> I want to be able to look up a service, create an instance of it,  
> use it, and toss it away. What iPOJO seems to support is creating  
> instances of services up front and have them ready and waiting. But  
> I don't want that. I want a service to be instantiated on demand.  
> How do I do this?
>
> One thought I had was to not create an instance of the service in  
> the metadata.xml, then the client can get the factory of the  
> service, create an instance, then discard it when it is through with  
> it. But this approach seems somewhat clumsy. Is there a better way?
>

By the way, iPOJO creates service objects only when they are needed  
(laziness) except if you configure it to be immediate.

> Thanks!
>
> john
>
> ---------------------------------------------------------------------
> 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: iPOJO temporary service instances?

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

On 15.07.2009, at 00:19, John Stump wrote:

> There is a pattern I am trying to recreate within the iPOJO world,  
> but I can't quite figure it out.
>
> I want to be able to look up a service, create an instance of it,  
> use it, and toss it away. What iPOJO seems to support is creating  
> instances of services up front and have them ready and waiting. But  
> I don't want that. I want a service to be instantiated on demand.  
> How do I do this?
>
> One thought I had was to not create an instance of the service in  
> the metadata.xml, then the client can get the factory of the  
> service, create an instance, then discard it when it is through with  
> it. But this approach seems somewhat clumsy. Is there a better way?

That's the main way. However, you can also use the iPOJO API. Then,  
you can declare you component type, directly and easily create  
instances and dispose them.

Regards,

Clement

>
> Thanks!
>
> john
>
> ---------------------------------------------------------------------
> 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