WebSphere brand IBM WebSphere Premises Server, Version 6.1.x

Creating the task agent MDB

All task agent MDBs must extend from IBMSEAbstractTaskAgent class.

About this task
Follow these steps to create a task agent MDB.
Procedure
  1. In Rational® Application Developer for WebSphere® Software, select TemperatureEvent_EJB.
  2. Select File > New > Other > EJB > Enterprise Bean and click Next.
  3. Complete the following tasks in the Enterprise Bean window.
    • Select Message-drive bean.
    • For the EJB project, select TemperatureEvent_EJB.
    • For the bean name, enter TemperatureEventTaskAgent.
    • For the source folder, enter ejbModule.
    • For the default package, enter com.temperature.event.mdb.
  4. Click Next.
  5. In the Message-Driven Bean Type window, select JMS type and click Next.
  6. In the Create a JMS Message-Driven Bean window, accept all the defaults and click Next.
  7. In the EJB Java Class Details window, enter com.ibm.sensorevent.engine.baseagent.IBMSEAbstractTaskAgent for the bean superclass.
  8. Click Next.
  9. If the Confirm Enablement window appears, select Always enable activities and don't ask me againand click OK.
  10. Close the class diagram editor (default.dnx) when it opens. It will not be used.
  11. In the Project Explorer view, expand TemperatureEvent_EJB > ejbModule > com.temperature.event.mdb.
  12. Double-click TemperatureEventTaskAgentBean.java to open the source editor There are errors in the generated code which will be corrected in the next step.
  13. Change the source to be the following:
    /**********************************************************************************
     * Licensed Materials - Property of IBM
     * 5724-L17 WebSphere Premises Server
     * (c) Copyright IBM Corp. 2008  All rights reserved.
     *
     * US Government Users Restricted Rights - Use, duplication or disclosure 
     * restricted by GSA ADP Schedule Contract with IBM Corp.
     *
     * DISCLAIMER OF WARRANTIES.  The following code is sample code created by 
     * IBM Corporation.  This sample code is part of the WebSphere Premises Server 
     * and is warranted to perform its intended function only if used un-modified.  
     * If you modify this code then it is considered provided "AS IS", without 
     * warranty of any kind.  Notwithstanding the foregoing, IBM shall not be liable 
     * for any damages arising out of your use of the sample code, even if they have
     * been advised of the possibility of such damages.
     ***********************************************************************************/
    
    package com.temperature.event.mdb;
    
    import com.ibm.sensorevent.model.IPayloadMetaData;
    import com.ibm.sensorevent.model.ISensorEvent;
    import com.temperature.event.payload.TemperatureEventPayload;
    
    public class TemperatureEventTaskAgentBean 
    	extends com.ibm.sensorevent.engine.baseagent.IBMSEAbstractTaskAgent
    	implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener {
    
    	private static final long serialVersionUID = 1L;
    	private javax.ejb.MessageDrivenContext fMessageDrivenCtx;
    
    	// Method 1
    	protected void onIBMSensorEvent(ISensorEvent event) {
    		try {
    			// display the event data
    			TemperatureEventPayload payload = (TemperatureEventPayload) event.getPayload();
    			int temperature = payload.getTemperature();
    			long time = payload.getTime();
    			System.out.println("task agent: temperature = " + temperature);
    			System.out.println("task agent: time = " + time);
    			
    			// add sample data to event metadata
    			IPayloadMetaData metadata = event.getPayloadMetaData();
    			metadata.addBooleanAttribute("processed", true);
    			
    			// forward event to output channels
    			this.publishOutbound(event);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	// Method 2
    	public void onMessage(javax.jms.Message msg) {
    		super.onMessage(msg);
    	}
    	
    	public javax.ejb.MessageDrivenContext getMessageDrivenContext() {
    		return fMessageDrivenCtx;
    	}
    
    	public void setMessageDrivenContext(javax.ejb.MessageDrivenContext ctx) {
    		fMessageDrivenCtx = ctx;
    	}
    
    	public void ejbCreate() {
    	}
    
    	public void ejbRemove() {
    	}
    }
  14. Select File > Save All.
  15. Select File > Close All.
Example

In this task agent example:

Every task agent MDB must contain the following:

What to do next
Modify the EJB deployment descriptor.

Library | Support | Terms of use

(c) Copyright IBM Corporation 2004, 2008. All rights reserved.
U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.