Plugin SDK

Top  Previous  Next

AggreGate Platform has a rich set of build in data processing tools, such as alerts, event filters, widgets, or trackers. AggreGate Plugin SDK is designed for creating customized instances of existing tools (e.g. building widgets on-the-fly based on current state of the system) and creating completely new tools (e.g. Access Policies for the physical access control industry). These tools are added to the AggreGate Server core in the form of plugins.

note_tip-wt

Use scripts instead of new AggreGate Server plugins to solve simple data processing tasks.

Technically speaking, AggreGate Server plugin can:

Add new contexts to the AggreGate Server context tree.
Add new variables, functions, events and actions to existing contexts. The functionality of these objects may be implemented by custom code.
Start any asynchronous code (listening server sockets, threads, etc.) that interacts with existing or custom contexts by changing values of their variables, executing their functions, or generating events in them.

Some examples of AggreGate Server plugins:

Asset Management plugin that creates a number of common tables containing asset-specific information and associates them with the hardware devices
Syslog Server plugin that receives messages from the servers via network and converts them to AggreGate events for storage and future processing
Industrial I/O plugin that generates widgets for monitoring status of programmable controllers

note_example-wt

Device Server SDK bundle includes an open-source example of AggreGate Server Plugin implementation called Demo Plugin. It is located in examples.plugin package and comprises three files:

DemoServerPlugin.java - source code of the plugin
plugin.xml - plugin descriptor
build.xml - Ant build file with a single task building plugin's JAR archive

To try the plugin:

Run build.xml using Ant to build demo.jar
Copy demo.jar to %AggreGate Server Installation Folder/plugins/context when AggreGate Server is not running
Start AggreGate Server

Structure of AggreGate Server Plugin

AggreGate Server plugin has two mandatory components:

Plugin Java class that implements ContextPlugin interface. Most implementations extend AbstractContextPlugin class to avoid implementing irrelevant methods and preserve their default functionality.
Plugin descriptor that defines plugin properties and its place in AggreGate Server's plugin hierarchy.

These components must be packed in the Java Archive (JAR). Plugin descriptor (plugin.xml) must be located in the root folder of the archive.

Creating New AggreGate Server Plugin

To create new AggreGate Server plugin from scratch, create new Java class inherited from AbstractContextPlugin. You will need to override at least some of the methods to provide plugin functionality.

note_further-wt

To suppress permission checking and ensure full access to all server contexts, pass an instance of UncheckedCallerController to all calls that accept arguments of CallerController type.

Global Configuration

Certain plugins may have global configuration settings.

To add global implement globalInit() method. Its implementations should call createGlobalConfigContext() and provide VariableDefinition's of global settings. These settings will be exposed to system administrators, their values get persisted in the database.

To access setting values from any method of the plugin, retrieve global config context using getGlobalConfigContext(), then call Context.getVariable() to fetch instances of DataTable representing setting values.

Hooking Up to the Server Context Tree

ContextPlugin interface provides several groups of methods to attach some new elements to the AggreGate Server context tree. Every group has two methods: one "startup" method called at server startup or context creation and one "shutdown" method called at server shutdown or context destruction.

1. Plugin initialization/deininialization

When a new context plugin is created, server calls its initialize() method that may contain some generic initialization code.

When the plugin going to be destroyed, server calls its deinitialize() method.

2. Context-based setup

Every time when new context is created or re-created on server startup, server calls install(Context context) method of the plugin. Its implementation may:

Add some variable/function/event/action definitions to the context and optionally provide their "custom code" (variable getters/setters, function implementations)
Add event listeners to the context

note_further-wt

Please avoid accessing other server contexts from the install(Context context) method. Since server context tree creation is concurrent, certain server contexts may be available at the time of debugging and become unavailable in production environment, causing unpredictable behaviour.

To access the whole context tree, add your code to install(ContextManager contextManager) or launch() methods.

3. Context tree-based setup

The install(ContextManager contextManager) method is called once right after server context tree finishes loading and all contexts were created. Its implementation may retrieve certain server contexts using ContextManager.get() method and add variable/function/event/action definitions and/or event listeners to them.

4. Plugin launch

launch() method of the plugin is called in the very end of server startup, when all server contexts and facilities are up and running. It should be implemented only if some code fails to work properly from any of the methods described above.

Modifying Plugin Descriptor

To create a plugin descriptor for your plugin, make a copy of demo plugin's plugin.xml file and edit the following in it:

Change the last word in id attribute of the <plugin> tag to the ID of new plugin. The ID should contain only lowecase letters, digits and underscores. For example, if your desired plugin ID is xyz, set ID attribute to com.tibbo.linkserver.plugin.context.xyz.
Change class attribute of <plugin> tag to full name of plugin's java class.
Enter plugin description in the body <doc-text> tag.
Change id attribute of the <extension> tag to the new plugin ID.

Building and Deploying Plugin Archive

Make a copy of demo plugin's Ant build file (build.xml)
Change project name and name of destination file (plugin archive)
Run built.xml using Ant (http://ant.apache.org/) to build plugin Java archive
Copy the JAR file to %AggreGate Server Installation Folder/plugins/context when AggreGate Server is not running
Start AggreGate Server