WebSphere brand IBM WebSphere Premises Server, Version 6.1.x

Creating the custom payload in the Java™ utility project

All custom payload types must extend from the IBMSensorEventPayload class.

About this task
Follow these steps to create the custom payload.
Procedure
  1. In Rational® Application Developer for WebSphere® Software select File > New > Other > Java > Class and click Next.
  2. Complete the following tasks in the Java Class window.
    • For the source folder, enter TemperatureEvent_Java/src.
    • For the package, enter com.temperature.event.payload.
    • For the name, enter TemperatureEventPayload.
    • For the modifiers, select Public.
    • For the superclass, enter com.ibm.sensorevent.model.payload.IBMSensorEventPayload.
  3. Click Finish. The source editor for TemperatureEventPayload.java file opens.
  4. 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.payload;
    
    import com.ibm.sensorevent.model.IPayload;
    import com.ibm.sensorevent.model.generic.IGenericGroup;
    import com.ibm.sensorevent.model.generic.SensorEventException;
    import com.ibm.sensorevent.model.payload.IBMSensorEventPayload;
    
    public class TemperatureEventPayload extends IBMSensorEventPayload {
    	private static final long serialVersionUID = 1L;
    
    	// Constructor 1
    	protected TemperatureEventPayload() throws SensorEventException {
    	}
    
    	// Constructor 2
    	protected TemperatureEventPayload(String eventType) throws SensorEventException {
    		super(eventType);
    	}
    
    	// Factory method 1
    	public static IGenericGroup getInstance() throws SensorEventException {
    		return new TemperatureEventPayload();
    	}
    	
    	// Factory method 2
    	public static IGenericGroup getInstance(String eventType) throws SensorEventException {
    		return new TemperatureEventPayload(eventType);
    	}
    	
    	// Factory method 3
    	public static IGenericGroup getInstance(IPayload sourcePayload) throws SensorEventException {
    		TemperatureEventPayload payload = (TemperatureEventPayload) getInstance();
    		payload.copyFields(sourcePayload);		
    		copyGroup(sourcePayload, payload);
    		return payload;
    	}
    	
    	// Method 1
    	public int getTemperature() throws SensorEventException {
    		return this.eventGroup.getIntAttributeValue("temperature");
    	}
    	
    	// Method 2
    	public void setTemperature(int t) throws SensorEventException {
    		this.eventGroup.addIntAttribute("temperature", t);
    	}
    	
    	// Method 3
    	public long getTime() throws SensorEventException {
    		return this.eventGroup.getDateAttributeValueAsLong("time");
    	}
    	
    	// Method 4
    	public void setTime(long t) throws SensorEventException {
    		this.eventGroup.addDateAttributeAsLong("time", t);
    	}	
    }
  5. Select File > Save All.
  6. Select File > Close All.
Example

In this custom payload example:

Every custom payload must contain the following:


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.