The custom listener passes the results of complex event processing to a user-developed Java class. This section provides an overview of the user-developed Java classes and the considerations required when designing it.
Implement the following interface for a user-developed Java class:
com.fujitsu.cspf.cep.CustomListener
The following two methods must be implemented using this interface:
Type of the return value | Method name | Argument | Explanation |
---|---|---|---|
void | setArgs | String[] args | The args parameter specified using the @CustomListener annotation is passed. |
String statementName | The name (specified using @Name) of the complex event processing statement to which the @CustomListener annotation was attached is passed. | ||
void | update | Map[] newEvents | The processing result (output event) of the complex event processing statement to which the @CustomListener annotation was attached is passed as an array of the java.util.Map object. The output event passed as a java.util.Map object contains a property name and value pair. If the rules output events periodically, the update method may be called even if there is no output event. |
The following processes are performed for the user-developed Java class each time there is an output from a complex event processing statement:
An instance of the user-developed Java class is generated.
The setArgs method is called.
The update method is called.
In addition, an instance of a user-developed Java class is generated when the CEP engine is started.
If an exception occurs during custom listener processing, the CEP engine catches the exception and outputs it to the engine log and the system log. Processing of other events continues.
Note
A user-developed Java class runs on the same Java VM as the CEP engine. Take the following points into account when designing a user-developed Java class.
Design a user-developed Java class so there is no bottleneck in processing time
Design a user-developed Java class so that it takes only a short time to generate an instance of the user-developed Java class and to call the setArgs and update methods. If these processes take time, events awaiting processing may accumulate in the CEP engine and adversely affect the processing performance of the entire CEP engine. Particularly if a large volume of events is to be output, the impact will be greater.
Create a thread-safe design
Processing of a user-developed Java class is called from multiple threads, so create a thread-safe design. For example, if using class variables, you must consider the fact that the user-developed Java class will be called from multiple threads.
However, an instance of a user-developed Java class is generated each time an output event occurs, and one instance runs on only one thread. Therefore, if processing involves merely operating the instance variables, there is no need to consider multiple threads.
Throw errors that must be monitored as exceptions
To monitor errors that occur in a user-developed Java class, throw details of the error as an exception outside the user-developed Java class. An exception that is thrown is caught by the CEP engine and output to the engine log and the system log.
Example
Sample source code of a user-developed Java class is stored in the following directory:
/opt/FJSVcep/sample/CustomListener