Adding TaskListener When Scheduling Reports
When scheduling a report, Logi JReport Server enables you to call your Java application before or after the process.
In Logi JReport Server, a TaskListener interface has been provided in the package jet.server.api for receiving task events before or after running. You can specify one Java class to implement this interface for a task event. When the event of this task occurs, the corresponding methods in the listener will be invoked. The interface contains two methods: beforeRun and afterRun, enabling you to set your Java application call before or after the process of viewing a report or setting up a schedule. Your applications will return true or false. For true, Logi JReport Server will go on running. While for false, Logi JReport Server will stop there.
Below is an example illustrating how to add TaskListener when setting up a schedule on a report.
- Develop your Java class to implement the 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:\Logi JReport\Server\tasklistener, add the path of the class file (
C:\Logi JReport\Server\tasklistener) to the ADDCLASSPATH variable in setenv.bat.
- Start Logi JReport Server and set up a schedule on a report, check Add TaskListerner to be Invoked in the General tab of the Schedule dialog, then input the class name. In this example, input TastListener, and then submit the task.
- In this example, the class returns True.
Print out the task and schedule properties before and after running the task. You will then get task and schedule information in the command window before and after the task is run.
You can also define properties of your own and transmit them through ServerInfo. To do this, use APIConst.TAG_USERDEFINED_PROPERTY_PREFIX as the prefix for the properties.
For example, if you want to transmit the properties host_name, host_ip and hosp_protocol, you will need to insert the properties, before calling the method runTask, into the properties named prop, as follows:
You can get the value of the properties listed above through the server info object, serverInfo, in the method beforeRun or afterRun of the TaskListener class. See the example below:
Note: All properties without the prefix APIConst.TAG_USERDEFINED_PROPERTY_PREFIX will be denied and discarded by Logi JReport Server.