Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Create notification producer and consumer using tooling

Revision as of 10:54, 10 July 2007 by Unnamed Poltroon (Talk) (New page: <h1>Create notification producer and consumer using tooling</h1> <table border="0" cellpadding="2" cellspacing="2"> <tr> <td width="100">Author:</td> <td>Krishna C Shastry, Saurab...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Create notification producer and consumer using tooling

Author: Krishna C Shastry, Saurabh Dravid
email: krishna.shastry@in.ibm.com sadravid@in.ibm.com
Last updated:

Create a notification producer resource

  • We will take a file system as a notification producer resource, which will notify the consumer at some specific time interval about the file space change event.
  • Create a new Manageability Endpoint Project by the name of ProducerModel. All our Notification producer related artifacts will be stored in this project.

    Wsdl complex type new mep wizard.png

  • For this resource we create a capability which publishes the file system space change events to the consumer. Create a new capability by specifying following user inputs defined in following screenshot. Click Finish.

    Wsdl complex type new cap wizard 1.png

  • Tooling will open this newly created capability with Capability Editor. Move to the Topics tab in the editor and add a new Root Topic by providing the Topic namespace as "http://www.eclipse.org/FileSpaceChangeEvent/capability/Topics" and Root topic name as "FileSpaceChange".

    Wsdl complex type new cap wizard 1.png

  • Create a new Manageable resource type (WSDM resource type) and add the "NotificationProducer" and "FileSpaceChangeEvent" capability to it.

    Wsdl complex type new mrt wizard 1.png

    Wsdl complex type new mrt wizard 2.png

  • Right click the "FileSystem.mrt" file and select the option Generate Java Code. This will bring a new wizard to do the code generation for defined managed resource type. Provide the Output project name as "FileSystem".

    Wsdl complex type codegen wizard.png

  • After doing the code generation remove the java package "org.eclipse.tptp.wsdm.runtime.capability" from "FileSystem" web project. The classes available in this package are already available in tools.jar.

  • Open Java class in /FileSystem/JavaSource by the name of org.eclipse.www.FileSpaceChangeEvent.capability.MyCapability and put the following code in this class. This class will publish the file system space change notification messages at specific time interval.

    package org.eclipse.www.FileSpaceChangeEvent.capability;
    
    import javax.xml.namespace.QName;
    
    import org.apache.muse.core.AbstractCapability;
    import org.apache.muse.util.xml.XmlUtils;
    import org.apache.muse.ws.addressing.soap.SoapFault;
    import org.apache.muse.ws.notification.NotificationProducer;
    import org.apache.muse.ws.notification.WsnConstants;
    import org.w3c.dom.Element;
    
    public class MyCapability extends AbstractCapability
    {
        public QName TOPIC_QNAME = new QName("http://www.eclipse.org/FileSpaceChangeEvent/capability/Topics","FileSpaceChange","tns");
        private final int TIME_INTERVAL_SECONDS = 3;
    	
    	public void initialize() throws SoapFault 
        {
            //
            //The following call is necessary to property initialize the resource
            //
            super.initialize();
    
            //
            //TODO Perform any needed initialization for this empty capability
            //
        }
        
        public void initializeCompleted() throws SoapFault
        {
        	super.initializeCompleted();
        	
        	
        	
        	Thread thread = new Thread(){
        		
        		public void run()
        		{
        			String message = "File space changed";
    				QName messageName = new QName("http://org.eclipse/FileSystem",
    						"FileSpaceChangeMessage", "tns");
    				Element payload = XmlUtils.createElement(messageName,
    						message);
    				NotificationProducer producer = (NotificationProducer) getResource()
    						.getCapability(WsnConstants.PRODUCER_URI);
        			while (true) {
        				try {
    						Thread.currentThread().sleep(TIME_INTERVAL_SECONDS * 1000);
    					} catch (InterruptedException e1) {
    						e1.printStackTrace();
    					}
    					try {
    						producer.publish(TOPIC_QNAME, payload);
    					} catch (SoapFault e) {
    						e.printStackTrace();
    					}
    				}
        		}
        	};
        	
        	thread.start();
        }
    
    }


Comments

Copyright © Eclipse Foundation, Inc. All Rights Reserved.