JSPF questions

90 views
Skip to first unread message

Sampo Niskanen

unread,
Jan 30, 2012, 2:08:22 PM1/30/12
to js...@googlegroups.com
Hi,

I'm investigating JSPF as a potential plugin framework for use in
OpenRocket, a model rocket simulator. My goal is that developers
would be able to create plugins as jar files, which users could just
drop into a plugin directory, and the software would load the plugins
from the dir.

After reading the docs, I still have some questions:

1. The obvious one: Are plugins singletons? That is, will the
PluginManager always return the same instance, or will it always
create new instances of plugins? (I couldn't find this in the docs..)

2. Can plugins depend on classes that are part of the base
application? The documentation states that the plugins should be
self-contained. However, the application contains quite complex data
structures which the plugins need to be able to manipulate, and
abstracting all of those behind interfaces is quite unpractical. So
can a plugin depend on application classes that are not included in
the jar?

3. Is there any kind of support for multiple plugins defined by a
single class? At some point I'd like to create the possibility of
writing plugins in scripting languages. My idea was that a JSPF
plugin would scan the script directory, and instantiate plugins for
each script it finds. Is this in any way possible directly with the
JSPF framework, or do I need to create a second plugin-framework API
on top of JSPF? (For example, if a plugin instance knows what
capabilities it was queried with, that could be used to select the
correct script.)

Thanks!


Cheers,
Sampo N.

Rick Herrick

unread,
Jan 30, 2012, 5:42:06 PM1/30/12
to js...@googlegroups.com
I may have some of this wrong or not exactly correct, as I haven't been working directly with JSPF much recently, but I think I'm fairly close...


On Monday, January 30, 2012 1:08:22 PM UTC-6, Sampo N. wrote:

1.  The obvious one:  Are plugins singletons?  That is, will the
PluginManager always return the same instance, or will it always
create new instances of plugins?  (I couldn't find this in the docs..)

Plugins are not singletons, although you could make them so if you wanted to.
 

2.  Can plugins depend on classes that are part of the base

application?  The documentation states that the plugins should be
self-contained.  However, the application contains quite complex data
structures which the plugins need to be able to manipulate, and
abstracting all of those behind interfaces is quite unpractical.  So
can a plugin depend on application classes that are not included in
the jar?

To some extent this depends on how much you play around with the class loader. But generally yes, plugins can rely on classes in the base application. If you think about it, they have to rely on classes in the base implementation because the JSPF framework itself is in the base application and your plugin will use the annotations and other references from JSPF.

 3.  Is there any kind of support for multiple plugins defined by a

single class?  At some point I'd like to create the possibility of
writing plugins in scripting languages.  My idea was that a JSPF
plugin would scan the script directory, and instantiate plugins for
each script it finds.  Is this in any way possible directly with the
JSPF framework, or do I need to create a second plugin-framework API
on top of JSPF?  (For example, if a plugin instance knows what
capabilities it was queried with, that could be used to select the
correct script.)

There's no direct support for that, but you can definitely set up your plugin implementation to do what you're thinking of. You would have to do it, but I don't think that would be very difficult. My current implementation does a similar sort of thing, not with scripting but using the scope of the originating plugin to resolve resources so that, e.g., you can have CSS, JS, JSP, Velocity, or whatever other kind of resource you might need for a full extension to a web application. 

Ralf

unread,
Jan 30, 2012, 6:27:01 PM1/30/12
to jspf


On Jan 30, 2:42 pm, Rick Herrick <rherr...@gmail.com> wrote:
> > 1.  The obvious one:  Are plugins singletons?  That is, will the
> > PluginManager always return the same instance, or will it always
> > create new instances of plugins?  (I couldn't find this in the docs..)

Hi,

Just a brief amendment. The actual plugins *are* singletons. However,
there can be multiple implementations for the same plugin interface
class, of course.



> > 2.  Can plugins depend on classes that are part of the base
>
> > application?  The documentation states that the plugins should be
> > self-contained.  However, the application contains quite complex data
> > structures which the plugins need to be able to manipulate, and
> > abstracting all of those behind interfaces is quite unpractical.  So
> > can a plugin depend on application classes that are not included in
> > the jar?
>
> To some extent this depends on how much you play around with the class
> loader. But generally yes, plugins can rely on classes in the base
> application. If you think about it, they have to rely on classes in the
> base implementation because the JSPF framework itself is in the base
> application and your plugin will use the annotations and other references
> from JSPF.

Yep, correct, they can rely on plugins of the base app.


>  3.  Is there any kind of support for multiple plugins defined by a
>
> > single class?  At some point I'd like to create the possibility of
> > writing plugins in scripting languages.  My idea was that a JSPF
> > plugin would scan the script directory, and instantiate plugins for
> > each script it finds.  Is this in any way possible directly with the
> > JSPF framework, or do I need to create a second plugin-framework API
> > on top of JSPF?  (For example, if a plugin instance knows what
> > capabilities it was queried with, that could be used to select the
> > correct script.)

The last time I checked, "class X implements PluginA, PluginB" worked.
However, to dynamically define plugin interfaces at runtime you will
need to trick a bit since JSPF spawns (instantiates) your class on its
own - at the same time it checks the implemented plugin interfaces.

Cheers
Ralf
Reply all
Reply to author
Forward
0 new messages