Overview
The "Plugins" mechanism is designed to provide the management of and access to external (outside of the OpenPTK Framework) processing capabilities. The initial requirement of this plugin is to access a mime-type detection "plugin", related to the Mime-Type document management project.
Difference between Services and Plugins
Plugins are different from "Services" in the OpenPTK since "Services" are focused on performing CRUD operations for Subjects. The only thing they have in common is that they provide a consistent abstraction to "something else" and that the configuration processes can manage their life-cycle.
Specific Difference
- Services/Subjects use Input / Output objects ... Plugins use generic Structures
- Services/Subjects have the concept of finite Operations ... Plugins have no concept of "operations"
- Service/Subjects have many automatic features: Definitions/Functions/Relationships/etc. ... Plugins have non of these constraints as it is designed to be a way to access any external API.
They solve two different problems. The Service concept is "focused" on the specific task of performing CRUD operations, for a Subject, to a Repository that implements the Operations Interface. The Plugin mechanism is intended to provide access to many kinds of "external / third party" processing through a consistent / generic interface.
Architecture
The "plugins" mechanism is similar to the "Service" architecture.
- The Plugins and each Plugin will be defined in the openptk.xml file
- If configured, the OpenPTK start-up mechanism can start the Plugin
- An interface is defined to provide run-time access to the Plugin
- The config object will maintain a Collection of "active" Plugins
- The Plugins will be generally available through out the Framework (via the config)
- Example access points:
- Function within an Attribute
- Action within a Context
- Service
- Engine
- Representation
- Relationship
The following diagram demonstrates a email plugin which can be used for many different things within the Server architecture. The Email plugin will allow a consistent way to access mail APIs (and related configuration information for smtp host, port, etc.) for sending emails for any purpose.
Framework Packaging
Similar to the Service architecture, the Plugin architecture will have the interface and abstract classes packed within the Framework Project (jar). Each implementation of a Plugin will have it's own Project containing related source code and supporting files.
Project |
OpenPTK-Framework |
Distribution |
openptk-framework.jar |
SVN Path |
project/OpenPTK/Framework/src/java/org/openptk/plugin |
Namespace |
org.openptk.plugin |
Interface |
org.openptk.plugin.PluginIF |
Class(es) |
org.openptk.plugin.Plugin (abstract base class) |
Example Plugin Packaging
This examples uses the Mime-Util Project
Project |
OpenPTK-Plugin-MimeUtil |
Distribution |
openptk-plugin-mimeutil.jar |
SVN Path |
ext/Plugin/MimeUtil/src/java/org/openptk/plugin/mimeutil |
Namespace |
org.openptk.plugin.mimeutil |
Class(es) |
org.openptk.plugin.mimeutil.MimeUtilPlugin |
|
|
Project |
OpenPTK-Plugin-Thumbnail |
Distribution |
openptk-plugin-thumbnail.jar |
SVN Path |
ext/Plugin/Tumbnail/src/java/org/openptk/plugin/thumbnail |
Namespace |
org.openptk.plugin.thumbnail |
Class(es) |
org.openptk.plugin.thumbnail.ThumbnailPlugin |
|
|
Project |
OpenPTK-Plugin-SendEmail |
Distribution |
openptk-plugin-sendemail.jar |
SVN Path |
ext/Plugin/SendEmail/src/java/org/openptk/plugin/sendemail |
Namespace |
org.openptk.plugin.sendemail |
Class(es) |
org.openptk.plugin.sendemail.SendEmailPlugin extends Plugin |
Configuration
The xml-based (and xsd) configuration file will be updated to support Plugins.
<Plugins>
<Plugin id="mimeutil" enabled="true" classname="org.openptk.plugin.mimeutil.MimeUtilPlugin"/>
<Properties>
<Property name="detector" value="MagicMimeMimeDetector"/>
<Property name="attribute.document" value="document"/>
<Property name="attribute.mime" value="mime"/>
</Properties>
</Plugin>
<Plugin id="thumbnail" enabled="false" classname="org.openptk.plugin.thumbnail.ThumbnailPlugin"/>
<Properties>
<Property name="size.height" value="100"/>
<Property name="size.weight" value="100"/>
</Properties>
</Plugin>
<Plugin id="email" enabled="true" classname="org.openptk.plugin.sendemail.SendEmailPlugin"/>
<Properties>
<Property name="mail.host" value="localhost"/>
<Property name="mail.debug" value="false"/>
<Property name="mail.from" value="donotreply@example.com"/>
</Properties>
</Plugin>
</Plugins>
Implementation
org.openptk.exception
PluginException.java
package org.openptk.exception;
public class PluginException extends Exception
{
public PluginException(String message)
{
...
}
public PluginException(Throwable ex)
{
...
}
...
}
org.openptk.config
This are new methods:
ConfigIF.java
public interface ConfigIF extends ComponentIF
{
...
public Map<String, PluginIF> getPlugins();
public PluginIF getPlugin(String name);
...
}
org.openptk.plugin
PluginIF.java
package org.openptk.plugin;
public interface PluginIF extends ComponentIF
{
public void startup();
public void shutdown();
public StructureIF execute(StructureIF structure) throws PluginException;
}
Plugin.java
package org.openptk.plugin;
public abstract class Plugin extends Component implements PluginIF
{
public Plugin()
{
super();
return;
}
public void startup()
{
return;
}
public void shutdown()
{
return;
}
public abstract StructureIF execute(StructureIF structure) throws PluginException;
}
org.openptk.plugin.mimeutil
MimeUtilPlugin.java
package org.openptk.plugin.mimeutil;
public class MimeUtilPlugin extends Plugin
{
public void startup()
{
...
return;
}
public void shutdown()
{
...
return;
}
public StructureIF execute(StructureIF structIn) throws PluginException
{
StructureIF structOut = null;
...
return structOut;
}
}
Usage Example
MimeUtilExample.java
...
PluginIF mimeUtil = null;
StructureIF structIn = null;
StructureIF structOut = null;
...
mimeUtil = config.getPlugin("mimeutil");
structIn = new BasicStructure("document", byteArray);
structOut = mimeUtil.execute(structIn);
System.out.println("Mime-Type=" + structOut.getValueAsString();
|