Force a plugin to re-start [message #329022] |
Tue, 10 June 2008 16:45 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Is it possible to force a plugin to re-start? I'm working on "entitled"
plugins that require a valid license in order to load; if the license is
not valid (or missing entirely), the activator throws an exception from
the start() method.
Now I'd like to give the user the ability to correct his license. After
doing so, I'd like to force the licensed plugins to try to start again
without having to restart the entire workbench. Is that possible?
TIA,
Eric
|
|
|
|
Re: Force a plugin to re-start [message #329029 is a reply to message #329025] |
Tue, 10 June 2008 18:56 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Wayne Beaton wrote:
> Use a bundle context to find your bundle and tell it to start.
>
> Let me know if you need some sample code.
Definitely - I'm having trouble finding the bootstraps...
Thanks,
Eric
> On Tue, 2008-06-10 at 12:45 -0400, Eric Rizzo wrote:
>> Is it possible to force a plugin to re-start? I'm working on "entitled"
>> plugins that require a valid license in order to load; if the license is
>> not valid (or missing entirely), the activator throws an exception from
>> the start() method.
>> Now I'd like to give the user the ability to correct his license. After
>> doing so, I'd like to force the licensed plugins to try to start again
>> without having to restart the entire workbench. Is that possible?
>>
>> TIA,
>> Eric
>
|
|
|
Re: Force a plugin to re-start [message #329032 is a reply to message #329029] |
Tue, 10 June 2008 19:14 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Wayne Beaton![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=wayne.beaton%40eclipse-foundation.org) Messages: 554 Registered: December 2017 |
Senior Member |
|
|
Something like this bundle activator ought to do it:
package org.eclipse.funkybundles;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends Plugin {
private static Activator plugin;
private BundleContext context;
public void start(BundleContext context) throws Exception {
this.context = context;
super.start(context);
plugin = this;
}
public void startAllMyFunkyBundles() {
Bundle[] bundles = context.getBundles();
for(int index=0;index<bundles.length;index++) {
Bundle bundle = bundles[index];
if (isThisOneOfMyFunkyBundles(bundle)) {
try {
bundle.start();
} catch (BundleException e) {
// TODO Do something smart with this
e.printStackTrace();
}
}
}
}
private boolean isThisOneOfMyFunkyBundles(Bundle bundle) {
return bundle.getSymbolicName().matches(".*\\.funky\\..*");
}
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
public static Activator getDefault() {
return plugin;
}
}
I'd write a smarter isThisOneOfMyFunkyBundles() method.
This assumes that all your bundles have been installed. I recall (but am
not 100% certain) that start() might throw an exception if the bundle is
already started. I'd probably handle this case in the exception handler
(keep in mind that multiple threads might try to start the bundle
concurrently).
On that note, you might want to either synchronize the method or add a
comment warning against multiple-thread access.
I'm not sure why I decided that your bundles would be "funky". :-)
HTH,
Wayne
On Tue, 2008-06-10 at 14:56 -0400, Eric Rizzo wrote:
> Wayne Beaton wrote:
> > Use a bundle context to find your bundle and tell it to start.
> >
> > Let me know if you need some sample code.
>
> Definitely - I'm having trouble finding the bootstraps...
>
> Thanks,
> Eric
>
>
> > On Tue, 2008-06-10 at 12:45 -0400, Eric Rizzo wrote:
> >> Is it possible to force a plugin to re-start? I'm working on "entitled"
> >> plugins that require a valid license in order to load; if the license is
> >> not valid (or missing entirely), the activator throws an exception from
> >> the start() method.
> >> Now I'd like to give the user the ability to correct his license. After
> >> doing so, I'd like to force the licensed plugins to try to start again
> >> without having to restart the entire workbench. Is that possible?
> >>
> >> TIA,
> >> Eric
> >
|
|
|
|
Powered by
FUDForum. Page generated in 0.03748 seconds