Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » How to prevent bundle resume on restart
How to prevent bundle resume on restart [message #780478] Wed, 18 January 2012 08:44 Go to next message
Jan Mauersberger is currently offline Jan MauersbergerFriend
Messages: 119
Registered: July 2009
Senior Member
I have a bundle with lazy bundle activation policy, so the bundle is
started when using the first time. I have a bundle activator that
dynamically adds fragments to the bundle depending on certain
environment conditions and user preferences. That is working fine so far.

However, after a restart the framework is resuming all bundles that were
active on shutdown, among others also my bundle. Thus the
activator.start() method is called rather early in the startup phase
before(!) anything as application or product or eve even workspace is
known. Since my startup code depends on that I would like to know
whether it is possible to prevent suspension/resumption by any means or
whether someone had similar problems and a solution.

Thanks in advance
Jan
Re: How to prevent bundle resume on restart [message #780492 is a reply to message #780478] Wed, 18 January 2012 10:06 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 452
Registered: July 2009
Location: Germany ✈ Vancouver
Senior Member

Am 18.01.2012 09:44, schrieb Jan Mauersberger:
> However, after a restart the framework is resuming all bundles that were
> active on shutdown, among others also my bundle. Thus the
> activator.start() method is called rather early in the startup phase
> before(!) anything as application or product or eve even workspace is
> known. Since my startup code depends on that I would like to know
> whether it is possible to prevent suspension/resumption by any means or
> whether someone had similar problems and a solution.

Relying on startup order and lazy start behavior is nearly impossible.
You may set explicit set start levels to ensure a specific start order
but then you won't have lazy activation.

I think it could work if you defer your processing until the bundles are
available. For example, in your start method check if everything is
available and if not register a bundle listener. The listener will be
notified about bundle changes and you could attach fragments more
dynamically (eventually also supporting detaching when a dependency is
stopped). Doesn't make the implementation easier, though.

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: How to prevent bundle resume on restart [message #780530 is a reply to message #780492] Wed, 18 January 2012 13:31 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 437
Registered: July 2009
Senior Member
It sounds to me that something is eagerly starting your bundle which persistently marks it for eager (non-lazy) start on restart of the framework. Or perhaps there is another bundle starting which loads a class from your lazy-start bundle which is causing it to get lazy activated, but you think it is getting started too early.

You can enable the following trace option to see if something is eagerly starting your bundle:

org.eclipse.osgi/monitor/activation=true

HTH

Tom.
Re: How to prevent bundle resume on restart [message #780569 is a reply to message #780530] Wed, 18 January 2012 16:17 Go to previous messageGo to next message
Jan Mauersberger is currently offline Jan MauersbergerFriend
Messages: 119
Registered: July 2009
Senior Member
Thomas,

I could confirm that the bundle seems to be lazily started having
eclipse started the first time (configuration space empty). The bundle
is started by a classloader "cascade".

On second start the activation stack is as following, so it seems to be
directly forced by the framework only:

MyActivator.start(BundleContext) line: 74
BundleContextImpl$1.run() line: 711
AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not
available [native method]
BundleContextImpl.startActivator(BundleActivator) line: 702
BundleContextImpl.start() line: 683
BundleHost.startWorker(int) line: 381
BundleHost(AbstractBundle).resume() line: 389
Framework.resumeBundle(AbstractBundle) line: 1131
StartLevelManager.resumeBundles(AbstractBundle[], boolean, int) line: 559
StartLevelManager.resumeBundles(AbstractBundle[], int) line: 544
StartLevelManager.incFWSL(int, AbstractBundle[]) line: 457
....


Using your trace option hint I get something like the following when the
bundle is started the first time lazily:



java.lang.Exception: A persistent start has been called on bundle:
XXXXX_1.0.0.qualifier
at
org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:306)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:291)
at
de.ikv.analyze.adapter.rhapsody.ui.AnalyzeRhapsodyAdapterUiPlugin.start(AnalyzeRhapsodyAdapterUiPlugin.java:40)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)

What exactly does this debug output mean?

Thnaks for the help
Jan

> It sounds to me that something is eagerly starting your bundle which
> persistently marks it for eager (non-lazy) start on restart of the
> framework. Or perhaps there is another bundle starting which loads a
> class from your lazy-start bundle which is causing it to get lazy
> activated, but you think it is getting started too early.
>
> You can enable the following trace option to see if something is eagerly
> starting your bundle:
>
> org.eclipse.osgi/monitor/activation=true
>
> HTH
>
> Tom.
Re: How to prevent bundle resume on restart [message #780575 is a reply to message #780569] Wed, 18 January 2012 16:33 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 437
Registered: July 2009
Senior Member
Further up the stack from the debug should show you the class that is calling Bundle.start(). This is causing a persistent eager activation of the bundle when you restart.

HTH

Tom.
Re: How to prevent bundle resume on restart [message #780605 is a reply to message #780569] Wed, 18 January 2012 18:11 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 452
Registered: July 2009
Location: Germany ✈ Vancouver
Senior Member

Am 18.01.2012 17:17, schrieb Jan Mauersberger:
> de.ikv.analyze.adapter.rhapsody.ui.AnalyzeRhapsodyAdapterUiPlugin.start(AnalyzeRhapsodyAdapterUiPlugin.java:40)

You need to change the call in AnalyzeRhapsodyAdapterUiPlugin line 40 to
"bundleToStart.start(Bundle.START_TRANSIENT)".

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: How to prevent bundle resume on restart [message #780720 is a reply to message #780605] Thu, 19 January 2012 08:05 Go to previous message
Jan Mauersberger is currently offline Jan MauersbergerFriend
Messages: 119
Registered: July 2009
Senior Member
Oh man,

I absolutely did forget that part of my own obsolete code: before trying
dynamic fragments I had added code to force certain bundle activation.
As it seems that forces a persistent restart of the bundle.

Thanks a lot for saving me lots of time and a headache!

Jan

> Am 18.01.2012 17:17, schrieb Jan Mauersberger:
>> de.ikv.analyze.adapter.rhapsody.ui.AnalyzeRhapsodyAdapterUiPlugin.start(AnalyzeRhapsodyAdapterUiPlugin.java:40)
>
> You need to change the call in AnalyzeRhapsodyAdapterUiPlugin line 40 to
> "bundleToStart.start(Bundle.START_TRANSIENT)".
>
> -Gunnar
>
Previous Topic:How to plug a different i18n mechanism
Next Topic:Problems building a p2-enabled Eclipse workbench-based product
Goto Forum:
  


Current Time: Fri Nov 28 03:28:28 GMT 2014

Powered by FUDForum. Page generated in 0.02737 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software