Plugin System
NeuroKernel has a very flexible plugin system. Every application can be used as a plugin inside another application if the application itself allows it. There is no need to install any plugin to your server, locale or remote. Plugin system is one of the most striking features of NeuroKernel operating system.
1. Plugin Branch
A plugin branch is a plugin reques tmade by an already running plugin application. Plugin applications running as a branch wont have any visuals, they can interact with their parent in terms of data input and output. NeuroKernel task processor wont allow recursive calling of plugin branches. Plugin branches are a good choice for connecting other servers for information needed. It may be used as distributed data searches, pattern recognition and more. Plugin branches are forced to run in a worker by kernel.
2. Plugin Component
Plugin component, or NPlugin
, is the UI control that embeds a plugin application for its parent. It can request a plugin component from various sources including peer-to-peer networks. IPluginSystem
interface object is created for both the plugin component and the plugin application to make the development consistent. The messaging is made via events between parent and plugin.
import com.neurokernel.client.*; import com.neurokernel.adapter.NActionListener; public class PluginExample extends NApplication { private NPlugin pluginApp; private IPluginSystem pluginSystem; @Override public void main(int argc, String[] argv) { final NFrame mainFrame=getMainFrame(); NButton button=new NButton(mainFrame,"Hello"); button.addActionListener(new NActionListener() { @Override public void onAction(NEvent e) { pluginSystem.sendEvent(500, "Hello"); } }); pluginApp=new NPlugin(mainFrame, "HelloPlugin"); pluginSystem = pluginApp.getEmbeddedSystem(); pluginSystem.addListener(new IEventListener { @Override public void onEvent(NEvent e) { if(e.getEventType()==500) { NMessageDialog.showInfo(mainFrame, e.getString()); } } }); mainFrame.setTitle("Plugin Example"); mainFrame.setBounds(20,20,200,200); mainFrame.setVisible(true); } }
3. Devices
An application can define itself as a device by using Device annotation. The advance of defining a device is to give a standardized plugin interface to the applications so that same device type can be loaded from different sources implemented differently.
import com.neurokernel.client.system.ICallback; import com.neurokernel.client.device.*; import com.neurokernel.client.NApplication; import com.neurokernel.client.constants.DataType; import com.neurokernel.client.annotation.Device; import com.neurokernel.client.annotation.Method; import java.util.Date; @Device( value="NDayTime", type="DayTimeDevice", methods={ @Method(value="getTime",returnType=DataType.LONG), @Method(value="getDate",returnType=DataType.DATE) } ) public class NDayTimeDevice extends NApplication { Date currentDate=new Date(); NMethod getTime; @Override public void main(int argc, String[] argv) { NDevice deviceInfo=getSystem().getDevice(); if(deviceInfo!=null) { getTime=deviceInfo.getDeviceMethod("getTime").setCallProcessor(new IMethodCall() { @Override public Object process(IAsyncResponse response,Object... args) { return currentDate.getTime(); } }); deviceInfo.getDeviceMethod("getDate").setCallProcessor(new IMethodCall() { @Override public Object process(IAsyncResponse response,Object... args) { return currentDate; } }); } } }
import com.neurokernel.client.constants.DataType; import com.neurokernel.client.annotation.* import com.neurokernel.client.system.*; import com.neurokernel.client.device.*; import java.util.Date; @Device( value="NDayTime", type="DayTimeDevice", methods={ @Method(value="getTime",returnType=DataType.LONG), @Method(value="getDate",returnType=DataType.DATE) } ) public class NMyDevice extends NDeviceDriver { IConsole console; public NMyDevice(ISystem system) { super("DayTimeDevice",system); console=system.getConsole(); } @Override protected void onDeviceSuccess(NDevice device) { device.getDeviceMethod("getTime"). setResponseProcessor(new IMethodResponse<Long>() { @Override public void process(NMethod method, Long result) { console.print(new Date(result)); } }).call(); device.getDeviceMethod("getDate"). setResponseProcessor(new IMethodResponse<Date>() { @Override public void process(NMethod method, Date result) { console.print(result); } }).call(); } @Override protected void onDeviceFailure() { } }
4. Associating Canvas
Parent application can associate a canvas with the plugin application by giving reference information to it. This gives opportunity to the plugin to draw a parent canvas on protocol level. This association can also be done with direct canvas access if the offline canvas feature is supported by the browser used, or the plugin application is from the same domain as the parent application.
import com.neurokernel.client.*; import com.neurokernel.client.system.IPluginSystem; public class MyApplication extends NApplication { @Override public void main(int argc, String[] argv) { NFrame mainFrame=getMainFrame(); NCanvas canvas=new NCanvas(mainFrame); NPlugin plugin=new NPlugin(mainFrame, "teapot", null); IPluginSystem pluginSystem=plugin.getPluginSystem(); pluginSystem.associateCanvas("MyCanvas", canvas.getGraphics()); mainFrame.setTitle("Plugin Application"); mainFrame.setBounds(20,20,200,200); mainFrame.setVisible(true); } }