Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Report max generation time (How to specify a report max generation time?)
Report max generation time [message #870935] Thu, 10 May 2012 09:54 Go to next message
donino donino is currently offline donino doninoFriend
Messages: 183
Registered: July 2011
Senior Member
Hi,

I wonder if it is possible, using the Report Engine API, to specify a report max generation time? May be a value to set to the report engine, or for each IRunTask?

Thanks!
Re: Report max generation time [message #871076 is a reply to message #870935] Thu, 10 May 2012 17:34 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You could always spawn a thread to cancel the report after a certain
amount of time. Look at this example, (While it is not exactly what you
want it should get you close).


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.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
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;


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();
}
}
}


}

Jason


On 5/10/2012 5:54 AM, donino donino wrote:
> Hi,
> I wonder if it is possible, using the Report Engine API, to specify a
> report max generation time? May be a value to set to the report engine,
> or for each IRunTask?
> Thanks!
Re: Report max generation time [message #871170 is a reply to message #871076] Fri, 11 May 2012 09:10 Go to previous messageGo to next message
donino donino is currently offline donino doninoFriend
Messages: 183
Registered: July 2011
Senior Member
Thank you Jason,

This is very helpful i think i will be able to manage this max generation time with something close to your example. However could you please clarify why the rtask.cancel() is wrapped in a loop? Invoke it one time may not be sufficient?

thanks





Re: Report max generation time [message #871260 is a reply to message #871170] Fri, 11 May 2012 16:39 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Just a typo, you should only have to cancel it once.

Jason

On 5/11/2012 5:10 AM, donino donino wrote:
> Thank you Jason,
> This is very helpful i think i will be able to manage this max
> generation time with something close to your example. However could you
> please clarify why the rtask.cancel() is wrapped in a loop? Invoke it
> one time may not be sufficient?
>
> thanks
>
>
>
>
>
>
Previous Topic:Adding comments to the graph generated by BIRT.
Next Topic:Dynamic coloring a result
Goto Forum:
  


Current Time: Thu Apr 25 13:05:51 GMT 2024

Powered by FUDForum. Page generated in 0.02775 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top