Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining What Happens When Matching Events Are Found | Defining static actions
 
Defining static actions
In contrast to the regular actions that are described in Defining actions, static actions do not apply to specific instances of an event. They are not as powerful as regular actions, but they are helpful in situations where it makes more sense to use an action that is related to the event type, and where the action is not called on an instance of that event.
Static actions can only be declared inside an event type. They are defined in just the same way as regular actions (see Format for defining actions). The only differences are that they start with static, cannot reference self, and cannot reference members of the event. For example:
static action staticActionName() {
// do something
}
The following example contrasts a regular action with a static action.
event MyEventType {
integer i;

action someAction() {
print i.toString(); // Valid
}

static action someStaticAction() {
print i.toString(); // Not valid
someAction(); // Not valid
}
}

MyEventType e := new MyEventType;
e.someAction();

MyEventType.someStaticAction();
A static action can be used, for example, if you have a factory action which constructs a new instance of a particular event type and initializes its members to values that make sense for that type. Although it is possible to have such code in any place, in terms of program readability, it is more helpful to "associate" the static action with the event type that it is creating. For example:
event MyEventType {
string s;
integer i;

static action initialise() returns MyEventType {
MyEventType ret := new MyEventType;
ret.s := "Default";
ret.i := 100;
return ret;
}

...
}

MyEventType e := MyEventType.initialise();
With the above definition, the static action can then be called using a single line of code anywhere in your program.