Apama 10.7.2 | Developing Apama Applications | Developing Apama Applications in Java | Overview of Apama JMon Applications | About event types | Simple example of an event type
 
Simple example of an event type
An event type is defined as a Java class as per the following example,
/*
* Tick.java
*
* Class to abstract an Apama stock tick event. A stock tick event
* describes the trading of a stock, as described by the symbol
* of the stock being traded, and the price at which the stock was
* traded
*/
 
import com.apama.jmon.Event;
 
public class Tick extends Event {
   /** The stock tick symbol */
   public String name;
 
   /** The traded price of the stock tick */
   public double price;
 
   /**
   * No argument constructor
   */
   public Tick() {
     this("", 0);
   }
 
   /**
   * Construct a tick object and set the name and price
   * instance variables
   *
   * @param name The stock symbol of the traded stock
   * @param price The price at which the stock was traded
   */
   public Tick(String name, double price){
     this.name = name;
     this.price = price;
   }
}
By Java programming conventions, the previous definition would need to be provided on its own in a stand-alone file, for example, Tick.java.
The definition must import the definition of the Event class. This is provided as part of the com.apama.jmon package provided with your Apama distribution. See Developing and Deploying JMon Applications on installation and deployment for details of where to locate this package.
Event is the abstract superclass of all user classes implementing desired event types. Then we must define our new event class as a subclass of the Event type.
The user-defined event class must have three primary elements:
*A set of public variables that define the event's parameters
*A no argument constructor, whose purpose is to construct an instance of the event with the parameters set to default values
*A constructor whose parameter list corresponds (in type and order) to the event's parameters. This constructor allows creation of an instance of the event with specific parameter values.
In the above example the event is called Tick, and it has two parameters, name, of type String, and price, of type double. The previous definition may be considered a simple template for how to write all event definitions.
Note:
Non-public (like private and protected) variables are not considered to be part of the event schema.