Re: plugins, api and classloaders

From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 01/31/05


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



Relevant Pages

  • Re: reiser4 plugins
    ... "Plugins" is a bad word. ... We now have a standard disk format plugin, ... I see no problems with providing at least as consistent an EA interface ... Only, zip files aren't just compression, so ...
    (Linux-Kernel)
  • Re: Email clients
    ... presumably this isn't a bug in Mail after all. ... but filters not that good (why don't they just license dspam or some ... totally sufficient, and the interface to them is very, very good). ... plugins are basically hacks against a "private" ...
    (uk.comp.sys.mac)
  • Driver Model 2 Proposal - Linux Kernel Performance v Usability
    ... This is not an attempt to have a Microkernel, or any move away from GNU/OSS ... It is worth remembering that for every Kernel hacker there must ... Implement binary kernel 'plugin' interface ... even FS 'plugins' could be created although IPL would be ...
    (Linux-Kernel)
  • Re: modular application
    ... >> Do your plugins inherit from IPlugin or do the implement it? ... > Sometimes the plugins implement a plugin-specific interface, e.g., ... isn't the Type of MyPlugin actually MyPlugin? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Cross-appdomain communication
    ... reference to that assembly in order to get the interface type, ... that object to talk to the other appdomain? ... I have an app that searches for plugins at ... >> while I want to create a list of plugins, I don't want those assemblies to ...
    (microsoft.public.dotnet.framework.remoting)