Have you tried using a BundleTracker?

It doesn't give you internal access to the Framework's locks... nothing
does I believe (and hope!).

It does however handle the complexity of getting current state and
listening at the same time. When you open the tracker, the addingBundle()
method (which you should override) is invoked with any bundles that are
*already* in the state that you are looking for. Then addingBundle() is
invoked for any bundles that later enter the state you are looking for. In
any case it is only invoked once, unless of course a bundle transitions in
and out of the required state multiple times. This should solve your
non-idempotent problem.

Neil

On Fri, 1 Mar 2019 at 12:39, Michael Lipp via osgi-dev <
osgi-dev@mail.osgi.org> wrote:

> Hi,
>
> I just want to make sure: there's no method for obtaining the "state
> change" lock on a Bundle, right?
>
> I'm asking because I want an action to be performed once the bundle has
> reached a particular state. Without this lock I have to follow the usual
> procedure for such cases:
>
> * Check for target state
>
> * Register listener
>
> * Check for target state again (because target state may have been
> reached between previous check and registration of listener, so listener
> is never invoked).
>
> ... which gets a bit more complicated still if the action to be
> performed when the target state is reached isn't idempotent.
>
> A bundle "state change" lock is mentioned in the
> SynchronousBundleListener API, but I couldn't find a way to access it.
>
> Best regards,
>
>     Michael
>
> _______________________________________________
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to