When running a report in Advanced mode or scheduling a task such as report task, data cache task and in-memory cube task, Logi JReport Server enables you to call your Java application before or after the report or task runs so as to get the information about the task.
The TaskListener interface is provided in the jet.server.api package in the Server API for receiving task events before or after the task running. The interface contains two methods: beforeRun() and afterRun(), which enable you to set your Java application call before or after the process of viewing a report or scheduling a task. You can specify one Java class to implement this interface for a task event, then when the event of this task occurs, the corresponding method in the listener will be invoked. Your application will return True or False. When True is returned, Logi JReport Server will go on running; if False, Logi JReport Server will stop there.
Below example shows how to add TaskListener when creating a schedule task on a report.
- Develop your Java class to implement the TaskListener interface. Here TestTaskListener.java is used, which is available in
- Compile TestTaskListener.java to generate the class file.
- Edit the batch file setenv.bat in
<install_root>\bin. Assuming that TestTaskListener has been saved in
C:\JReport\Server\tasklistener, add the path of the class file (
C:\JReport\Server\tasklistener) to the ADDCLASSPATH variable in setenv.bat.
- In the Logi JReport Server console, create the schedule task on a report. In the General tab of the Schedule dialog, check Add TaskListerner to be Invoked and input the class name. In this example, input TastListener and submit the task.
In the example, the class returns True. The task and schedule properties will be output to the command window before and after the task runs. You can get the task information in the command window.
You can also define properties of your own and transmit them through the serverInfo object by using APIConst.TAG_USERDEFINED_PROPERTY_PREFIX as the prefix of the properties. Note that all properties without this prefix will be denied and discarded by Logi JReport Server.
For example, if you want to transmit the properties host_name, host_ip and hosp_protocol, you can insert them into the properties named prop before calling the method runTask() as follows:
prop.put(APIConst. TAG_USERDEFINED_PROPERTY_PREFIX+"host_name", "host");
prop.put(APIConst. TAG_USERDEFINED_PROPERTY_PREFIX+"host_ip", "127.0.0.1");
prop.put(APIConst. TAG_USERDEFINED_PROPERTY_PREFIX+"host_protocol"+ "TCP/IP");
You can get the value of the properties listed above through the serverInfo object, in the method beforeRun() or afterRun() of the TaskListener interface. See the example below: