You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by fabiolf <fa...@gmail.com> on 2012/06/12 20:38:42 UTC

How is the most efficient way to know when a bundle is started?

Hello!

In OSGI, the call to Bundle.start() is asynchronous. So when I issue the
call, I have to code something to let me know when the Bundle is really
started. The first thing that came to my mind is to create a polling process
to check if the bundle is already started, but it is not the most efficient
and quick way to achieve that. I need to know as soon as possible the moment
when the bundle is started. I was thinking about listening to bundle start
events and then filter to find my bundle start event. Is it possible? Is it
efficient? How can I do it?

Thanks in advance!
Fabio

--
View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996.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: How is the most efficient way to know when a bundle is started?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 6/12/12 14:38 , fabiolf wrote:
> Hello!
>
> In OSGI, the call to Bundle.start() is asynchronous.

This call is not asynchronous.

> So when I issue the
> call, I have to code something to let me know when the Bundle is really
> started. The first thing that came to my mind is to create a polling process
> to check if the bundle is already started, but it is not the most efficient
> and quick way to achieve that. I need to know as soon as possible the moment
> when the bundle is started. I was thinking about listening to bundle start
> events and then filter to find my bundle start event. Is it possible? Is it
> efficient? How can I do it?

Yes, sounds like you should be using a BundleListener...perhaps even a 
SynchronousBundleListener if you really cannot be notified 
asynchronously...although you should try not to do too much in 
synchronous callbacks.

-> richard

>
> Thanks in advance!
> Fabio
>
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by fabiolf <fa...@gmail.com>.
Hi Clement,


clement escoffier wrote
> 
> If you create the instance directly using the API, you can register an
> 'InstanceStateListener'. However, I would recommend to use services to
> detect the instance validation. For example, tracking the apparition of
> the Architecture service, or the registration of a 'business' service is
> probably easier and avoids to deal with iPOJO specific behavior.
> 

I saw that InstanceStateListener, but I cannot guarantee that I will always
create the instance through API. I can receive a JAR containing some
components and the framework will initialize it for me. So I think I cannot
use the InstanceStateListener as I will need the Factory to register the
listener.

I liked your other suggestion. If I create an Architecture[] member in my
class and let iPOJO bind it for me, it will add another register in the
array when the instance I just started is ready? Maybe I could build a
notification system based on that behavior. How can I track new inserts into
this array? Can I be notified when that happens?

I'm sorry, what do you mean by the registration of a 'business' service?

Thanks!
Fabio

--
View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998043.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: What is the most efficient way to know when a iPOJO instance is validated?

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

If you create the instance directly using the API, you can register an 'InstanceStateListener'. However, I would recommend to use services to detect the instance validation. For example, tracking the apparition of the Architecture service, or the registration of a 'business' service is probably easier and avoids to deal with iPOJO specific behavior.

Regards,

Clement

On 12.06.2012, at 22:00, fabiolf wrote:

> Hi all,
> 
> I'm sorry, I did a terrible mistake here! Of course you and Richard are
> right, the Bundle.start() is not asynchronous. I got myself confused here!
> Let me explain it.
> 
> I am using iPOJO to make my life easier when binding services. So, I declare
> the iPOJO components in my bundle and, in runtime, the component instances
> are created. When all their handlers are valid, the instance is then
> validated.
> 
> So, the question I wanted to have made in first place was: how can I know,
> from the moment I start the iPOJO components bundle with Bundle.start(),
> that its component instance is validated (without having to code something
> in the validate callback of the component)? The process I wanted to have
> said that is asynchronous is the iPOJO instance validation, not the
> Bundle.start() call... sorry about that. (I have fixed the message subject
> to reflect the real problem)
> 
> At first time I thought about using some kind of listener, but it would have
> to be an iPOJO listener, right? Because the component instance lifecycle is
> managed by iPOJO, right?
> 
> Thanks in advance!
> Fabio
> 
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998002.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 6/18/12 21:46 , fabiolf wrote:
> Richard,
>
> On another point in my project I solved a problem using temporal
> dependencies because I didn't want my application to be restarted when I
> switched an instance inside a composite. But I am curious. Why have you said
> that I would want to use temporal dependencies all over the place

Actually, I said you don't want to...

> Are there
> any side effects of using temporal dependencies? I am asking because I am
> considering using it exactly all over the place :)

They are the equivalent of having no dependencies and just doing 
on-demand lookups of services. So, you never really know if a service 
will be available when you go to use it. It may be there, it may block 
you for a long period of time, or it may throw an exception.

To some degree, this is similar to the default behavior of Blueprint (it 
calls this damping; it is not 100% equivalent to temporal dependencies, 
but pretty close). It is like trying to pretend service dynamism doesn't 
exist.

In systems where you don't expect to have any dynamism except for the 
occasional update, this may be ok. However, it is not ok in a truly 
dynamic system.

-> richard

>
> Thanks,
> Fabio
>
>
> Richard S. Hall wrote
>> Granted, I haven't been completely paying attention so this may not be
>> relevant, but...
>>
>> Perhaps you could use a temporal dependency. In that case, your
>> application thread would get blocked while the service provider was
>> being switched instead of invalidated.
>>
>> You don't want to use temporal dependencies all over the place, but if
>> used strategically they can be useful.
>>
>> -> richard
>>
>>
>
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998170.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by fabiolf <fa...@gmail.com>.
Richard,

On another point in my project I solved a problem using temporal
dependencies because I didn't want my application to be restarted when I
switched an instance inside a composite. But I am curious. Why have you said
that I would want to use temporal dependencies all over the place? Are there
any side effects of using temporal dependencies? I am asking because I am
considering using it exactly all over the place :)

Thanks,
Fabio


Richard S. Hall wrote
> 
> Granted, I haven't been completely paying attention so this may not be 
> relevant, but...
> 
> Perhaps you could use a temporal dependency. In that case, your 
> application thread would get blocked while the service provider was 
> being switched instead of invalidated.
> 
> You don't want to use temporal dependencies all over the place, but if 
> used strategically they can be useful.
> 
> -> richard
> 
> 


--
View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998170.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Granted, I haven't been completely paying attention so this may not be 
relevant, but...

Perhaps you could use a temporal dependency. In that case, your 
application thread would get blocked while the service provider was 
being switched instead of invalidated.

You don't want to use temporal dependencies all over the place, but if 
used strategically they can be useful.

-> richard


On 6/13/12 13:17 , fabiolf wrote:
> Hi Christian,
>
> You got it all right, except for one scenery that is the reason why I think
> I need to wait to the instance to be valid, considering I want to avoid
> application downtime at all costs, that is, I want to avoid the application
> to be restarted as it could lose requests during the restarts.
>
> Imagine I want to change the behavior of one component by exchanging it for
> another one that implements the same interface. The steps I would have to do
> are simple: stop the old component bundle and start the new component
> bundle. Then iPOJO would rebind everything and the application would be
> valid again.
>
> But, depending on the order of the steps above, the application may have to
> be restarted or not. If I call the stop before the start, then iPOJO will
> process the stop, and the other application components would be invalidated
> as a side effect.
>
> If I start the new component before stopping the old one, the application
> may have to be restarted or not, depending how I achieve this. If I stop the
> old components bundle just after the new component bundle starts (which is
> synchronous) the application may end up with no implementation available for
> a specific service (for a shot period of time), which means that the
> application would be invalidated and restarted. That's why I need to wait
> for the new component to be up and valid to iPOJO. By doing this, iPOJO will
> just change the implementation of the service without stopping the
> application, because no components ever get invalidated (except the ones
> being exchanged).
>
> I am trying to achieve this by issuing the Bundle.start() for the new
> component and waiting until I got a callback to a method that listens to new
> Architectures appearing (by creating a aggregate attribute in other
> component and configuring a method to be called whenever a new bind to this
> attribute is made) and the Architecture reference is the one of the new
> component instance. But I am still trying to figure out how to deal with the
> concurrency issues. I think I'm going to get there sometime still in this
> life. :-)
>
> But the the original question for this thread was if anyone knew some
> easier/more efficient way, different of the one I am trying to achieve,
> because I was afraid of having to deal with all the concurrency issues. This
> is all new to me.
>
> Regards,
> Fabio
>
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998057.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by Christian Schneider <ch...@die-schneider.net>.
If you want to avoid downtime then you can simply install and start the 
new service and stop the old one later.

The question is though if a short downtime is a big problem at all. You 
typically will have failover with two machines so if one is not 
available for a short time it typically will not hurt. Additionally your 
service clients will typically have some means of retrying if a call 
fails as this can happen at any time.

When I do remote services I often use JMS this has the advantage that it 
is no problem if a service goes down for some time. It also provides 
some nice failover and load balancing out of the box. So that may also 
be an option for you to scale well.

Christian


Am 13.06.2012 19:17, schrieb fabiolf:
> Hi Christian,
>
> You got it all right, except for one scenery that is the reason why I think
> I need to wait to the instance to be valid, considering I want to avoid
> application downtime at all costs, that is, I want to avoid the application
> to be restarted as it could lose requests during the restarts.
>
> Imagine I want to change the behavior of one component by exchanging it for
> another one that implements the same interface. The steps I would have to do
> are simple: stop the old component bundle and start the new component
> bundle. Then iPOJO would rebind everything and the application would be
> valid again.
>
> But, depending on the order of the steps above, the application may have to
> be restarted or not. If I call the stop before the start, then iPOJO will
> process the stop, and the other application components would be invalidated
> as a side effect.
>
> If I start the new component before stopping the old one, the application
> may have to be restarted or not, depending how I achieve this. If I stop the
> old components bundle just after the new component bundle starts (which is
> synchronous) the application may end up with no implementation available for
> a specific service (for a shot period of time), which means that the
> application would be invalidated and restarted. That's why I need to wait
> for the new component to be up and valid to iPOJO. By doing this, iPOJO will
> just change the implementation of the service without stopping the
> application, because no components ever get invalidated (except the ones
> being exchanged).
>
> I am trying to achieve this by issuing the Bundle.start() for the new
> component and waiting until I got a callback to a method that listens to new
> Architectures appearing (by creating a aggregate attribute in other
> component and configuring a method to be called whenever a new bind to this
> attribute is made) and the Architecture reference is the one of the new
> component instance. But I am still trying to figure out how to deal with the
> concurrency issues. I think I'm going to get there sometime still in this
> life. :-)
>
> But the the original question for this thread was if anyone knew some
> easier/more efficient way, different of the one I am trying to achieve,
> because I was afraid of having to deal with all the concurrency issues. This
> is all new to me.
>
> Regards,
> Fabio
>
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998057.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
>


-- 

Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


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


Re: What is the most efficient way to know when a iPOJO instance is validated?

Posted by fabiolf <fa...@gmail.com>.
Hi Christian,

You got it all right, except for one scenery that is the reason why I think
I need to wait to the instance to be valid, considering I want to avoid
application downtime at all costs, that is, I want to avoid the application
to be restarted as it could lose requests during the restarts.

Imagine I want to change the behavior of one component by exchanging it for
another one that implements the same interface. The steps I would have to do
are simple: stop the old component bundle and start the new component
bundle. Then iPOJO would rebind everything and the application would be
valid again.

But, depending on the order of the steps above, the application may have to
be restarted or not. If I call the stop before the start, then iPOJO will
process the stop, and the other application components would be invalidated
as a side effect.

If I start the new component before stopping the old one, the application
may have to be restarted or not, depending how I achieve this. If I stop the
old components bundle just after the new component bundle starts (which is
synchronous) the application may end up with no implementation available for
a specific service (for a shot period of time), which means that the
application would be invalidated and restarted. That's why I need to wait
for the new component to be up and valid to iPOJO. By doing this, iPOJO will
just change the implementation of the service without stopping the
application, because no components ever get invalidated (except the ones
being exchanged).

I am trying to achieve this by issuing the Bundle.start() for the new
component and waiting until I got a callback to a method that listens to new
Architectures appearing (by creating a aggregate attribute in other
component and configuring a method to be called whenever a new bind to this
attribute is made) and the Architecture reference is the one of the new
component instance. But I am still trying to figure out how to deal with the
concurrency issues. I think I'm going to get there sometime still in this
life. :-)

But the the original question for this thread was if anyone knew some
easier/more efficient way, different of the one I am trying to achieve,
because I was afraid of having to deal with all the concurrency issues. This
is all new to me.

Regards,
Fabio

--
View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998057.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Fabio,

so let me try to explain in my words what you try to do.

Parts of the behaviour of your application should be able to change at 
runtime. I guess you are implementing this by defining a service and 
referencing it. So what really happens depends on the service 
implementation.

If you have only one implementation at a time for a service then a 
mandatory service is the way to go. I have an example for this at:
http://www.liquid-reality.de/display/liquid/2011/02/15/Karaf+Tutorial+Part+1+-+Installation+and+First+application

The example uses blueprint not iPojo but the idea should be similar. It 
has a model, persistence and UI. If you just install the model and UI 
the UI will not start as it depends on the peristence service. As soon 
as you install and start the persistence bundle it will come up. This 
allows to exchange the persistence at runtime. Uninstall the old bundle 
install the new one and the UI will restart and use the new persistence. 
There is no need to wait for bundle start / stop as the mandatory 
service reference already implements the needed behaviour.

If you want to use more than one service then you can also refer to a 
service list in blueprint. This list will then always reflect all the 
service impls for an interface. This way you can implement event 
listeners easily.

So to sum it up:
Simply use service references and let blueprint (I hope iPojo can do the 
same) wire your application. When you have to adapt to a change simply 
exchange the impl bundles and the application will set itself up with 
the new impls. There should be no need to wait for bundle start / stop.

One really nice thing is that by implementing your application using 
services at the right points you can already prepare for your adaptive 
scenario without putting a lot of effort into it in the start.

Christian

Am 13.06.2012 15:12, schrieb fabiolf:
> Hi Christian,
>
>
> Christian Schneider wrote
>> The startup of dependency injection frameworks like iPojo or blueprint
>> happens after the bundle start. So this is really asynchronous. The
>> question is why do you need to know when the component is up?
>>
> I'll try to give an overview of what I'm working on.
>
> I am currently working on a centralized adaptation mechanism. This
> centralized mechanism is part of a bigger project that uses planning as a
> technique to achieve a self-adaptive behavior. In other words, I'm trying to
> make a foundation to build adaptive applications, that is, an application
> that can change itself in response of environment changes. And I'm doing it
> in the architectural level. At this level, the adaptation comes to be a
> architectural reconfiguration, that is, change some components and, with
> this, change the behavior of the application.
>
> After some research, I found OSGi, which gives a good foundation to build
> adaptive applications. Moreover, I found iPOJO, that makes the
> reconfiguration easier by taking care of the bindings and everything.
>
> My centralized mechanism receives an adaptation plan that needs to be
> executed and do not know in advance which components the application will
> have because it needs to be generic. The adaptation plan is a series of
> commands with the objective of rearranging the application components. These
> commands are meant to activate and deactivate components. I am translating
> it to start and stop bundle commands.
>
> This all happens when the application is running and the objective is to
> preserve the responsive state of the application as much as I can. And, to
> avoid putting the application in a inconsistent state, I have to execute the
> commands in a specific order. So, summing everything up, I need to execute
> some start and stop commands in a specific order and as quick as I can. This
> is why I need to know when the component is up as soon as possible, for me
> to be able to fire the next command.
>
>
> Christian Schneider wrote
>> Do you want to use it as soon as it is up? If yes then simply reference
>> a service and make the reference mandatory. You can also use a
>> ServiceTracker and react on the service coming up.
>>
> If I understood what you said I cannot create a mandatory reference to the
> service, because my mechanism is meant to be generic. I would have to have a
> reference to all possible services, right?
>
> I also thought about using some listener like ServiceTracker, but when
> thinking of it, I ended with a doubt: The ServiceTracker is an OSGi thing.
> As far as I know, as iPOJO is built over OSGi, I thought I would need some
> listener that considers the iPOJO events not the OSGi events. I thought I
> needed to listen to instance activation events, not service availability
> events (as far as I know, correct me if I am wrong, they are not the same).
> The next command in my list (suppose a stop command) should be executed only
> when the current start command finished to put the instance in a active
> state, meaning all its iPOJO handlers are valid and the instance is ready to
> be bound to some other instance when needed. Can I be notified by the
> ServiceTracker at this specific moment? Do these iPOJO instance validation
> steps happen after the end od the service initialization process by OSGi,
> meaning that the ServiceTracker will notify me a little bit earlier than the
> iPOJO instance is really valid? Or these steps happens during the service
> initialization, in which case the ServiceTracker will notify me always after
> every iPOJO things are done?
>
> I hope I made myself clear... It is a little bit difficult for me to explain
> these internal iPOJO/OSGi behavior because I am in the process of learning
> it yet :-) Please correct me if I am wrong here.
>
> Thanks in advance and sorry for the big message.
> Fabio
>
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998037.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
>


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


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


Re: What is the most efficient way to know when a iPOJO instance is validated?

Posted by fabiolf <fa...@gmail.com>.
Hi Christian,


Christian Schneider wrote
> 
> The startup of dependency injection frameworks like iPojo or blueprint 
> happens after the bundle start. So this is really asynchronous. The 
> question is why do you need to know when the component is up?
> 

I'll try to give an overview of what I'm working on.

I am currently working on a centralized adaptation mechanism. This
centralized mechanism is part of a bigger project that uses planning as a
technique to achieve a self-adaptive behavior. In other words, I'm trying to
make a foundation to build adaptive applications, that is, an application
that can change itself in response of environment changes. And I'm doing it
in the architectural level. At this level, the adaptation comes to be a
architectural reconfiguration, that is, change some components and, with
this, change the behavior of the application.

After some research, I found OSGi, which gives a good foundation to build
adaptive applications. Moreover, I found iPOJO, that makes the
reconfiguration easier by taking care of the bindings and everything.

My centralized mechanism receives an adaptation plan that needs to be
executed and do not know in advance which components the application will
have because it needs to be generic. The adaptation plan is a series of
commands with the objective of rearranging the application components. These
commands are meant to activate and deactivate components. I am translating
it to start and stop bundle commands.

This all happens when the application is running and the objective is to
preserve the responsive state of the application as much as I can. And, to
avoid putting the application in a inconsistent state, I have to execute the
commands in a specific order. So, summing everything up, I need to execute
some start and stop commands in a specific order and as quick as I can. This
is why I need to know when the component is up as soon as possible, for me
to be able to fire the next command.


Christian Schneider wrote
> 
> Do you want to use it as soon as it is up? If yes then simply reference 
> a service and make the reference mandatory. You can also use a 
> ServiceTracker and react on the service coming up.
> 

If I understood what you said I cannot create a mandatory reference to the
service, because my mechanism is meant to be generic. I would have to have a
reference to all possible services, right?

I also thought about using some listener like ServiceTracker, but when
thinking of it, I ended with a doubt: The ServiceTracker is an OSGi thing.
As far as I know, as iPOJO is built over OSGi, I thought I would need some
listener that considers the iPOJO events not the OSGi events. I thought I
needed to listen to instance activation events, not service availability
events (as far as I know, correct me if I am wrong, they are not the same).
The next command in my list (suppose a stop command) should be executed only
when the current start command finished to put the instance in a active
state, meaning all its iPOJO handlers are valid and the instance is ready to
be bound to some other instance when needed. Can I be notified by the
ServiceTracker at this specific moment? Do these iPOJO instance validation
steps happen after the end od the service initialization process by OSGi,
meaning that the ServiceTracker will notify me a little bit earlier than the
iPOJO instance is really valid? Or these steps happens during the service
initialization, in which case the ServiceTracker will notify me always after
every iPOJO things are done?

I hope I made myself clear... It is a little bit difficult for me to explain
these internal iPOJO/OSGi behavior because I am in the process of learning
it yet :-) Please correct me if I am wrong here.

Thanks in advance and sorry for the big message.
Fabio

--
View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998037.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: What is the most efficient way to know when a iPOJO instance is validated?

Posted by Christian Schneider <ch...@die-schneider.net>.
The startup of dependency injection frameworks like iPojo or blueprint 
happens after the bundle start. So this is really asynchronous. The 
question is why do you need to know when the component is up?

Do you want to use it as soon as it is up? If yes then simply reference 
a service and make the reference mandatory. You can also use a 
ServiceTracker and react on the service coming up.

Can you explain a bit more what you try to achieve? Pehaps there are 
better ways than waiting for the bundle.

Christian

Am 12.06.2012 22:00, schrieb fabiolf:
> Hi all,
>
> I'm sorry, I did a terrible mistake here! Of course you and Richard are
> right, the Bundle.start() is not asynchronous. I got myself confused here!
> Let me explain it.
>
> I am using iPOJO to make my life easier when binding services. So, I declare
> the iPOJO components in my bundle and, in runtime, the component instances
> are created. When all their handlers are valid, the instance is then
> validated.
>
> So, the question I wanted to have made in first place was: how can I know,
> from the moment I start the iPOJO components bundle with Bundle.start(),
> that its component instance is validated (without having to code something
> in the validate callback of the component)? The process I wanted to have
> said that is asynchronous is the iPOJO instance validation, not the
> Bundle.start() call... sorry about that. (I have fixed the message subject
> to reflect the real problem)
>
> At first time I thought about using some kind of listener, but it would have
> to be an iPOJO listener, right? Because the component instance lifecycle is
> managed by iPOJO, right?
>
> Thanks in advance!
> Fabio
>
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998002.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
>


-- 

Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


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


What is the most efficient way to know when a iPOJO instance is validated?

Posted by fabiolf <fa...@gmail.com>.
Hi all,

I'm sorry, I did a terrible mistake here! Of course you and Richard are
right, the Bundle.start() is not asynchronous. I got myself confused here!
Let me explain it.

I am using iPOJO to make my life easier when binding services. So, I declare
the iPOJO components in my bundle and, in runtime, the component instances
are created. When all their handlers are valid, the instance is then
validated.

So, the question I wanted to have made in first place was: how can I know,
from the moment I start the iPOJO components bundle with Bundle.start(),
that its component instance is validated (without having to code something
in the validate callback of the component)? The process I wanted to have
said that is asynchronous is the iPOJO instance validation, not the
Bundle.start() call... sorry about that. (I have fixed the message subject
to reflect the real problem)

At first time I thought about using some kind of listener, but it would have
to be an iPOJO listener, right? Because the component instance lifecycle is
managed by iPOJO, right?

Thanks in advance!
Fabio

--
View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996p4998002.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: How is the most efficient way to know when a bundle is started?

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am 12.06.2012 um 14:38 schrieb fabiolf:

> Hello!
> 
> In OSGI, the call to Bundle.start() is asynchronous.

I may be terribly wrong, but me thinks that Bundle.start is synchronous unless you have lazy activation in which case the actually only starts, when its used.

> So when I issue the
> call, I have to code something to let me know when the Bundle is really
> started. The first thing that came to my mind is to create a polling process
> to check if the bundle is already started, but it is not the most efficient
> and quick way to achieve that. I need to know as soon as possible the moment
> when the bundle is started. I was thinking about listening to bundle start
> events and then filter to find my bundle start event. Is it possible? Is it
> efficient? How can I do it?

You can certainly listen for the bundle start event. But, as I said, this is not required since the bundle starts synchronously.

Of course, there is no guarantee, that no asynchronous actions take place as a result.

Regards
Felix

> 
> Thanks in advance!
> Fabio
> 
> --
> View this message in context: http://apache-felix.18485.n6.nabble.com/How-is-the-most-efficient-way-to-know-when-a-bundle-is-started-tp4997996.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