Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Force a plugin to re-start
Force a plugin to re-start [message #329022] Tue, 10 June 2008 16:45 Go to next message
Eclipse UserFriend
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 #329025 is a reply to message #329022] Tue, 10 June 2008 16:57 Go to previous messageGo to next message
Wayne Beaton is currently offline Wayne BeatonFriend
Messages: 554
Registered: December 2017
Senior Member
Use a bundle context to find your bundle and tell it to start.

Let me know if you need some sample code.

HTH,

Wayne

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 #329029 is a reply to message #329025] Tue, 10 June 2008 18:56 Go to previous messageGo to next message
Eclipse UserFriend
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 messageGo to next message
Wayne Beaton is currently offline Wayne BeatonFriend
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
> >
Re: Force a plugin to re-start [message #329141 is a reply to message #329032] Fri, 13 June 2008 17:05 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I would also use bundle.start(Bundle.START_TRANSIENT); if it available
to you ... that allows the bundle to remain in the lazy state for the
next restart.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Retarget Action and Handler
Next Topic:Where is the list of the now-exist PropertyTesters?
Goto Forum:
  


Current Time: Sat Jul 27 12:54:20 GMT 2024

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

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

Back to the top