Developing Apama Applications > Developing Apama Applications in EPL > Getting Started with Apama EPL > Working with events > Methods on events
Methods on events
You can call the following methods on any event type. While the examples show monitors, you can also call these methods in the procedural code in a query.
*getName() retrieves the fully qualified event name. You can call this method on an event type or an event instance. For example:
event Foo {
string bar;
   integer count;
}
 
monitor m {
action onload() {
   print Foo.getName();
   }
}
The previous code prints the following:
Foo
*getFieldNames() retrieves a sequence of strings, sequence<string>, that contains the event field names. You can call this method on an event type or an event instance. For example:
event Foo {
   string bar;
   integer count;
}
 
monitor m {
   action onload() {
    print Foo.getFieldNames().toString();
    }
}
The previous code prints the following:
["bar","count"]
*getFieldTypes() retrieves a sequence of strings, sequence<string>, that contains the event field types. You can call this method on an event type or an event instance. For example:
event Foo {
   string bar;
   integer count;
}
 
monitor m {
   action onload() {
   print Foo.getFieldTypes().toString();
   }
}
The previous code prints the following:
["string","integer"]
*getFieldValues() retrieves a sequence of strings, sequence<string>, that contains the string version of the event’s field values. For string type fields, there is no quoting or escaping. You can call this method only on an event instance. For example:
event Foo {
   string bar;
   integer count;
}
 
monitor m {
   action onload() {
   Foo f:=Foo("Hello",1);
   print f.getFieldValues().toString();
  }
}
The previous code prints the following:
["Hello","1"]
*isExternal() — returns a boolean that indicates whether the event was generated by an external source. Typically, such an event came from an external event sender, triggered an event listener, and was coassigned to a monitor instance variable. A return value of true indicates an event that was generated by an external source.
When a monitor instance uses enqueue to send an event then that event is considered to be generated by an external source. When a monitor instance uses send...to or enqueue...to to send an event then that event is considered to be an internal event.
When the correlator spawns a monitor instance, it preserves the value that the isExternal() method returns. In other words, if you coassign an external event in a monitor instance, and then spawn that monitor instance, the isExternal() method returns true in the spawned monitor instance.
This method takes no parameters.
The isExternal() method returns false when a monitor instance
*Routes an event that was external
*Creates an event inside the correlator
*Clones an event
This method is useful when you need to determine whether an event came from outside or was in some way derived inside the correlator. Although this distinction is often clear from the event type, that is not always the case.
*clone() — returns a new event that is an exact copy of the event. All the event’s contents are cloned into the new event, and if they were complex types themselves, their contents are cloned as well. Takes no parameters.
*getTime() – returns a float that indicates a time expressed in seconds since the epoch, January 1st, 1970. The particular time returned is as follows:
*If the correlator created this event, the getTime() method returns the time that the correlator created the event. This is the creation time in the context in which the correlator created the event.
*Coassignment sets the timestamp of an event. A call to getTime() on a coassigned event returns the time that the correlator performed the coassignment. This is the time in the context in which the correlator performed the coassignment and it can be the time the event was received or routed (only a monitor can route events). For an enqueued event, a call to getTime() returns the receiving context’s current time when the enqueued event arrived in the context.
An event’s timestamp might not match the time when an event listener for that event fires. For example, consider the following:
on A():a and B():b {
   ...
}
Suppose that currentTime is 1 when the correlator processes A and currentTime is 2 when the correlator processes B. A call to a.getTime() returns 1, while a call to b.getTime() returns 2. Of course, the event listener fires only after processing B.
*parse()— method that returns the event object represented by the string argument. You can call this method on a parseable event type or on an instance of a parseable event type. The more typical use is to call parse() directly on the event type. You can call the string.canParse() method to determine whether a particular string can be parsed.
The parse() method takes a single string as its argument. This string must be the string form of an event object. The string must adhere to the format described in Event file format. For example:
A a := new A;
a := A.parse("A(10, \"foo\")");
You can specify the parse() method after an expression or type name. If the correlator is unable to parse the string, it is a runtime error and the monitor instance that the EPL is running in terminates.
See the description of parseable types in Type properties summary.
*toString()— returns a string representation of the event. Takes no parameters. The return value is constructed by concatenating the string representation of the referenced event's fields.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.