Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Asynchronous invocation of reports(Is IRunTask Synchronous??)
Asynchronous invocation of reports [message #768156] Mon, 19 December 2011 12:08 Go to next message
Tony M is currently offline Tony M
Messages: 7
Registered: December 2011
Location: Lodon
Junior Member
Hey there,

I have implemented 2 separate methods for run and render tasks using BIRT.
I am using the concept where i can fire the run task and return the status of the task to use it in a grid (View). In a situation where the task takes a long while to finish(big rptdocument) i can't seem to satisfy the condition where

task.getStatus() == IRunTask.STATUS_RUNNING

please help me - if that's possible - with an example on how to use the task.getStatus() in order to run the tasks in the background. i have tried many things yet it seems that the task has to finish running before it proceeds processing which is totally synchronous Sad

thanks for the help

Tony
Re: Asynchronous invocation of reports [message #768324 is a reply to message #768156] Mon, 19 December 2011 17:57 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

I modified the example.


package REAPI;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;

import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;

import org.eclipse.birt.report.engine.api.IParameterDefnBase;


public class RunAndRenderTaskCancel {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;

try{
config = new EngineConfig( );

config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");

config.setLogConfig("c:/temp/test", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");



//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);


HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/resample/TopNPercent.html");
options.setOutputFormat("html");
task.setRenderOption(options);



CancelReport cancelThread = new CancelReport( "cancelReport",
task);
cancelThread.start();
long beginTime = System.currentTimeMillis();
task.run();
long endTime = System.currentTimeMillis();
long timeSpan = endTime - beginTime;
System.out.println("Report Runtime: " + timeSpan);
int teststatus = task.getStatus();
if( teststatus == 4){
System.out.println("Report was cancelled");
}
task.close();




engine.destroy();
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunAndRenderTaskCancel ex = new RunAndRenderTaskCancel( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}
private class CancelReport extends Thread
{
private IRunAndRenderTask rTask;
private int msecs=0;
public CancelReport( String threadName, IRunAndRenderTask task){
super(threadName);
rTask = task;

}
public void run()
{
try{
while( msecs < 50 ){
Thread.currentThread().sleep( 200 );
//rTask.cancel();

System.out.println(rTask.getStatus());
msecs++;
}

}
catch(Exception e)
{
e.printStackTrace();
}
}
}


}


On 12/19/2011 12:08 PM, Tony wrote:
> Hey there,
>
> I have implemented 2 separate methods for run and render tasks using BIRT.
> I am using the concept where i can fire the run task and return the
> status of the task to use it in a grid (View). In a situation where the
> task takes a long while to finish(big rptdocument) i can't seem to
> satisfy the condition where
> task.getStatus() == IRunTask.STATUS_RUNNING
>
> please help me - if that's possible - with an example on how to use the
> task.getStatus() in order to run the tasks in the background. i have
> tried many things yet it seems that the task has to finish running
> before it proceeds processing which is totally synchronous :(
>
> thanks for the help
>
> Tony
Re: Asynchronous invocation of reports [message #768489 is a reply to message #768324] Tue, 20 December 2011 03:45 Go to previous message
Tony M is currently offline Tony M
Messages: 7
Registered: December 2011
Location: Lodon
Junior Member
Thanks a lot Jason, that was of a great help. Exactly what i wanted
Tony
Previous Topic:Hiding grid for excel
Next Topic:Asynchronous invocation of reports
Goto Forum:
  


Current Time: Thu Jul 24 11:24:18 EDT 2014

Powered by FUDForum. Page generated in 0.10984 seconds