Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to force a call to plugin's start() method
How to force a call to plugin's start() method [message #466188] Sun, 15 April 2007 21:25 Go to next message
Eclipse UserFriend
Originally posted by: mash_909.yahoo.co.uk

I have an application which has a 'master' plugin (containing most of
the core views, actions etc).
I have designed my app such that other plugins can be added and make use
of the Master's components, but the master does not know about these
guest plugins. I imagine this is a fairly common design pattern.

So the question is, from the master plugin, what is the best way to
force a guest plugin to start and register itself with Master components?

I know the guest would start automatically if the Master plugin
referenced a guest's class, but the design means the Master does not
know about the guest.

The best I have so far is to try to grab a reference to the guest bundle
(based on a namespace string pattern) and explicitly call start() on
it's Activator. ie from the Master plugin's Activator.start():

IExtensionRegistry extRegistry = Platform.getExtensionRegistry();
String[] namespaces = extRegistry.getNamespaces();
for (int i = 0; i < namespaces.length; i++) {
if (namespaces[i].indexOf("guest.plugin") != -1) {
Bundle b = Platform.getBundle(namespaces[i]);
try {
b.start();
} catch (BundleException e) {
LOG.error(e);
}
}
}

This seems to work but throws a BundleException:

org.osgi.framework.BundleException: State change in progress for bundle
"initial@reference:file:../../...myplugin/" by thread "Start Level Event
Dispatcher".

Is there a better way to start a "guest" plugin from a "master" plugin?
Re: How to force a call to plugin's start() method [message #466192 is a reply to message #466188] Mon, 16 April 2007 00:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Matt Hegarty wrote:
> I have an application which has a 'master' plugin (containing most of
> the core views, actions etc).
> I have designed my app such that other plugins can be added and make use
> of the Master's components, but the master does not know about these
> guest plugins. I imagine this is a fairly common design pattern.
>
> So the question is, from the master plugin, what is the best way to
> force a guest plugin to start and register itself with Master components?
>
> I know the guest would start automatically if the Master plugin
> referenced a guest's class, but the design means the Master does not
> know about the guest.
>
> The best I have so far is to try to grab a reference to the guest bundle
> (based on a namespace string pattern) and explicitly call start() on
> it's Activator. ie from the Master plugin's Activator.start():
>
> IExtensionRegistry extRegistry = Platform.getExtensionRegistry();
> String[] namespaces = extRegistry.getNamespaces();
> for (int i = 0; i < namespaces.length; i++) {
> if (namespaces[i].indexOf("guest.plugin") != -1) {
> Bundle b = Platform.getBundle(namespaces[i]);
> try {
> b.start();
> } catch (BundleException e) {
> LOG.error(e);
> }
> }
> }
>
> This seems to work but throws a BundleException:
>
> org.osgi.framework.BundleException: State change in progress for bundle
> "initial@reference:file:../../...myplugin/" by thread "Start Level Event
> Dispatcher".
>
> Is there a better way to start a "guest" plugin from a "master" plugin?
Have you tried defining an extension point in the master plugin that the
guest plugins then implement? The master plugin can then use the
extension registry to activate the quest plugins.
Re: How to force a call to plugin's start() method [message #466196 is a reply to message #466188] Mon, 16 April 2007 07:27 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
You shouldn't start() it -- the start/stop level of a bundle is managed by the OSGi framework, not you. What you're seeing is an error when the bundle in question is either started or starting.

What you should do is just access the class(es) that you want; if you have Eclipse-LazyStart: true then it will bring your bundle up on first access.

Alex.
Re: How to force a call to plugin's start() method [message #466230 is a reply to message #466196] Mon, 16 April 2007 20:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mash_909.yahoo.co.uk

Thanks for the responses.

Alex - The reason I can't follow your suggestion is because of the way I
have designed my app - namely the Master plugin doesn't know about the
classes in the guest plugins. It would be ideal if the guest plugins
would just start after the Master plugin.

David - I'll look into your suggestion.

To be more specific, within my Master plugin's Activator I have a simple
List, the contents of which are displayed in a TreeViewer. I would like
guest plugins to be able to get a reference to the List and add objects
which are then rendered in the Tree.

Matt

Alex Blewitt wrote:
> You shouldn't start() it -- the start/stop level of a bundle is managed by the OSGi framework, not you. What you're seeing is an error when the bundle in question is either started or starting.
>
> What you should do is just access the class(es) that you want; if you have Eclipse-LazyStart: true then it will bring your bundle up on first access.
>
> Alex.
Re: How to force a call to plugin's start() method [message #466232 is a reply to message #466230] Mon, 16 April 2007 20:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mash_909.yahoo.co.uk

Hmm - well I removed the call to bundle.start() and it still worked ok.
So I guess calling:

Platform.getBundle(namespaces[i]);

Is enough to cause the guest plugin's Activator to start.

Matt Hegarty wrote:
> Thanks for the responses.
>
> Alex - The reason I can't follow your suggestion is because of the way I
> have designed my app - namely the Master plugin doesn't know about the
> classes in the guest plugins. It would be ideal if the guest plugins
> would just start after the Master plugin.
>
> David - I'll look into your suggestion.
>
> To be more specific, within my Master plugin's Activator I have a simple
> List, the contents of which are displayed in a TreeViewer. I would like
> guest plugins to be able to get a reference to the List and add objects
> which are then rendered in the Tree.
>
> Matt
>
> Alex Blewitt wrote:
>> You shouldn't start() it -- the start/stop level of a bundle is
>> managed by the OSGi framework, not you. What you're seeing is an error
>> when the bundle in question is either started or starting.
>>
>> What you should do is just access the class(es) that you want; if you
>> have Eclipse-LazyStart: true then it will bring your bundle up on
>> first access.
>>
>> Alex.
Re: How to force a call to plugin's start() method [message #466262 is a reply to message #466230] Tue, 17 April 2007 11:11 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
This should definitly be an extension point. Provide an interface that
enables the "slave" plugins to access the functionality and provide a
extension point to access it. Then make each slave implement the
corresponding extension. The master plugin simply checks the registry
and by exectuing the extension activates the slaves.

BTW it sounds like you over engineered your master. Maybe you need to
split the functionality of your master into separate plugins.

Regards
Stefan

Matt Hegarty schrieb:
> Thanks for the responses.
>
> Alex - The reason I can't follow your suggestion is because of the way I
> have designed my app - namely the Master plugin doesn't know about the
> classes in the guest plugins. It would be ideal if the guest plugins
> would just start after the Master plugin.
>
> David - I'll look into your suggestion.
>
> To be more specific, within my Master plugin's Activator I have a simple
> List, the contents of which are displayed in a TreeViewer. I would like
> guest plugins to be able to get a reference to the List and add objects
> which are then rendered in the Tree.
>
> Matt
>
> Alex Blewitt wrote:
>> You shouldn't start() it -- the start/stop level of a bundle is
>> managed by the OSGi framework, not you. What you're seeing is an error
>> when the bundle in question is either started or starting.
>>
>> What you should do is just access the class(es) that you want; if you
>> have Eclipse-LazyStart: true then it will bring your bundle up on
>> first access.
>>
>> Alex.
Re: How to force a call to plugin's start() method [message #466306 is a reply to message #466188] Tue, 17 April 2007 14:09 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Matt Hegarty wrote:
> IExtensionRegistry extRegistry = Platform.getExtensionRegistry();
> String[] namespaces = extRegistry.getNamespaces();
>

The others have given you a couple of choices for how to solve your usecase.

The common pattern in eclipse is to let other plugins contribute to
extensions, and have the master plugin use the IExtensionRegistry to
find the contributed plugins, and "normally" just have eclipse
auto-start plugins when using
IConfigurationElement#createExecutableExtension(*).

It also depends on how "dynamic" the set of contributed plugins are.
Just using the IExtensionRegistry works well if new plugins come in as
features through the update manager or are dropped in an extension
location and eclipse is restarted with -clean.

If your list of contributed plugins was more dynamic, you would probably
still use the IExtensionRegistry approach to extract information, but
you would also have to programmatically tell OSGi when the bundles
become available (more work, but doable).

While you can use Bundle#start() to start a plugin, OSGi considers it a
manual activation and it will be restarted eagerly the next time OSGi
restarts (i.e. you loose the advantages of lazy loading, and your plugin
would have to be able to correctly initialize itself potentially without
the workbench or workbench window being available).

OSGi is always exciting ;-)

Later,
PW


Re: How to force a call to plugin's start() method [message #466431 is a reply to message #466306] Wed, 18 April 2007 20:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mash_909.yahoo.co.uk

Thanks for the responses. I'll read up on extension points from here on.

Paul Webster wrote:
> Matt Hegarty wrote:
>> IExtensionRegistry extRegistry = Platform.getExtensionRegistry();
>> String[] namespaces = extRegistry.getNamespaces();
>>
>
> The others have given you a couple of choices for how to solve your
> usecase.
>
> The common pattern in eclipse is to let other plugins contribute to
> extensions, and have the master plugin use the IExtensionRegistry to
> find the contributed plugins, and "normally" just have eclipse
> auto-start plugins when using
> IConfigurationElement#createExecutableExtension(*).
>
> It also depends on how "dynamic" the set of contributed plugins are.
> Just using the IExtensionRegistry works well if new plugins come in as
> features through the update manager or are dropped in an extension
> location and eclipse is restarted with -clean.
>
> If your list of contributed plugins was more dynamic, you would probably
> still use the IExtensionRegistry approach to extract information, but
> you would also have to programmatically tell OSGi when the bundles
> become available (more work, but doable).
>
> While you can use Bundle#start() to start a plugin, OSGi considers it a
> manual activation and it will be restarted eagerly the next time OSGi
> restarts (i.e. you loose the advantages of lazy loading, and your plugin
> would have to be able to correctly initialize itself potentially without
> the workbench or workbench window being available).
>
> OSGi is always exciting ;-)
>
> Later,
> PW
>
Re: How to force a call to plugin's start() method [message #466466 is a reply to message #466232] Thu, 19 April 2007 13:10 Go to previous message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Mon, 16 Apr 2007 21:30:22 +0100, Matt Hegarty wrote:

> Hmm - well I removed the call to bundle.start() and it still worked ok.
> So I guess calling:
>
> Platform.getBundle(namespaces[i]);
>
> Is enough to cause the guest plugin's Activator to start.
>

If you set auto-start in the manifest, then the plugin will be started
whenever any of its classes are requested.

An extension point is the proper way to do what you want to do. You may
have to change things a bit, but I suggest you do so.


CL
Previous Topic:migration of rcp development and problem
Next Topic:How to restrict contributions or provide a list of 'granted' plugins.
Goto Forum:
  


Current Time: Wed Apr 24 16:28:02 GMT 2024

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

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

Back to the top