[Engine-devel] Update on UI Plugins: PoC patch revision 4

Vojtech Szocs vszocs at redhat.com
Thu Aug 30 15:12:12 UTC 2012


Hello everyone, 

as a follow-up to my last email on improving plugin API, here comes the latest revision of UI Plugins proof-of-concept patch (please find it attached). 

This patch is focused on improving JavaScript plugin API, along with important changes and improvements made to plugin infrastructure ( PluginManager ). Let's walk through the changes step by step. 



Improved plugin API, taking some inspiration from jQuery 

Following is a sample plugin code that uses new plugin API: 

var myPlugin = pluginApi('myPlugin'); // Obtain plugin API instance for 'myPlugin' 
var myPluginConfig = myPlugin.configObject(); // Obtain plugin-specific configuration 

// Register event handler functions to be invoked by WebAdmin 
// Note: all functions are optional, the plugin only defines functions for events it wants to handle 
myPlugin.register({ 
UiInit: function() { 
var testUrl = 'http://www.example.com/' + myPluginConfig.foo; // Assume plugin configuration has 'foo' attribute 
myPlugin.ui.addMainTab('Custom Tab', 'custom-tab', testUrl); // Invoke some operation using plugin API 
} 
}); 

myPlugin.ready(); // Event handler functions are registered, we are now ready to get initialized (UiInit) 



UI plugin life-cycle, enforced by plugin infrastructure 

The PluginState enumeration lists possible states of a plugin during its runtime: 

    * DEFINED : This is the initial state for all plugins. Plugin meta-data has been read by PluginManager and the corresponding iframe element has been created for the plugin. Note that at this point, the iframe element is not attached to DOM yet. 
    * LOADING : The iframe element for the plugin has been attached to DOM, which causes plugin host page (previously known as plugin source page) to be fetched asynchronously in the background. We are now waiting for plugin to report in as ready. In practice, due to JavaScript runtime being single-threaded, WebAdmin startup logic will continue to execute until the JavaScript runtime is "idle" (browser event loop returns), and at this point JavaScript plugin code gets invoked through the plugin host page. 
    * READY : The plugin has indicated that it is ready for use. We assume the plugin has already registered its event handler object (object containing various event handler functions to be called by WebAdmin) at this point. We can now proceed with plugin initialization. 
    * INITIALIZED : The plugin has been initialized by calling UiInit function on its event handler object. We can now call other event handler functions, the plugin is now initialized and in use. 


Note on plugin initialization: the UiInit function will be called just once during the lifetime of the plugin, after the plugin reports in as ready AND WebAdmin enters the state that allows plugins to be invoked (entering main section for logged-in users), and before other event handler functions are invoked by the plugin infrastructure. 




Plugin meta-data is now passed to client using different format 


Previously, plugin meta-data was embedded into WebAdmin host page as a simple JavaScript object, like so: 


var pluginDefinitions = { myPlugin: "<URL>", anotherPlugin: "<URL>" } 



Now, plugin meta-data is embedded into WebAdmin host page as a JavaScript array, like so: 



var pluginDefinitions = [ 
{ name: "myPlugin", url: "<URL>", config: { "foo": 1, "bar": "whatever" } }, 
{ name: "anotherPlugin", url: "<URL>" } 

]; 


As you can see, pluginDefinitions is now an array of JavaScript objects, with each object representing plugin meta-data . The "name" and "url" attributes are mandatory (we need to check them when loading plugin descriptors). "config" is the plugin configuration (JSON) object, obtained by merging default plugin configuration (defined in plugin descriptor) with custom plugin configuration (defined in external plugin configuration file) . Note that the "config" attribute is optional. 



In terms of Java classes, pluginDefinitions is mapped to PluginDefinitions overlay type, and each meta-data object within the array is mapped to PluginMetaData overlay type. 





Note on using assert statements in client code : you might notice that I'm using a lot of assert statements in Plugin class. This is to ensure consistency and guard against corrupted state during development. In GWT, assert statements work in a different way than in standard Java VM. When debugging GWT application using Development Mode, assert statements are checked and throw assertion errors during runtime (they are displayed in Development Mode console). However, when compiling GWT application to JavaScript (Production Mode), assert statements are removed by GWT compiler, so they don't affect the application running in Production Mode. 



Let me know what you think guys. 



Cheers, 
Vojtech 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/engine-devel/attachments/20120830/22d07f18/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WIP-UI-Plugins-PoC-revision-4.patch
Type: text/x-patch
Size: 49169 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/engine-devel/attachments/20120830/22d07f18/attachment.bin>


More information about the Engine-devel mailing list