Re: plugins, api and classloaders
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 01/31/05
- Next message: Ahmed Moustafa: "Re: Open source license"
- Previous message: nathaniel_auvil_at_yahoo.com: "JNDI Connection Pool issue"
- Next in thread: ittay.dror_at_gmail.com: "Re: plugins, api and classloaders"
- Reply: ittay.dror_at_gmail.com: "Re: plugins, api and classloaders"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 Jan 2005 10:36:48 -0500
ittay.dror@gmail.com wrote:
> Assume I have an application that can load plugins.
>
> I want a plugin to be able to use an API I provide, and nothing more.
> How do I do that?
>
> More detailed, I have an interface MyApi, implemented by MyApiImpl, and
> a class MyPlugin loaded into my application. How can I make it
> recognize MyApi, but not MyApiImpl? It has to work with MyApi
> interface, but the object it links with is MyApiImpl. I want to acheive
> this with class loaders, not public/private/package protection.
Plugins are required to implement something like this interface:
public interface Plugin {
void init(PluginConfig config);
<choose return type> doSomething(<choose argument type> arg);
}
Your application provides this interface (or perhaps just uses MyApi in
its place):
public interface PluginConfig {
MyApi getHostApi();
// perhaps other methods
}
and uses instances of it to initialize plugins. You make MyApiImpl
package-private, so that the plugin couldn't downcast even if it knew
the name of the implementation class.
None of this requires explicit reference to ClassLoaders, and I'm having
trouble seeing just how a ClassLoader could be used to achieve the kind
of protection you're talking about. ClassLoaders do have other uses
relative to plugins, however; in particular, careful use of a
ClassLoader to load a plugin can make it feasible to dynamically unload
/ replace it during program execution. By means of ClassLoaders you may
also be able to protect plugins from interference by other plugins
(somewhat).
John Bollinger
jobollin@indiana.edu
- Next message: Ahmed Moustafa: "Re: Open source license"
- Previous message: nathaniel_auvil_at_yahoo.com: "JNDI Connection Pool issue"
- Next in thread: ittay.dror_at_gmail.com: "Re: plugins, api and classloaders"
- Reply: ittay.dror_at_gmail.com: "Re: plugins, api and classloaders"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|