Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Asynchronous invocation of reports
Asynchronous invocation of reports [message #360813] Mon, 25 February 2008 05:41 Go to next message
Eclipse UserFriend
Originally posted by: mikey.gmail.com

Does BIRT support asynchronous invocation of reports?

I am looking for a run method that gives me a job id of some kind and i
can query BIRT using the job id and get the status of the report execution?
Re: Asynchronous invocation of reports [message #360837 is a reply to message #360813] Mon, 25 February 2008 15:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Mikey,

If you spawn a thread to run a task, in that thread you can check the
status of the task by calling task.getStatus(), which will return one of
the following as defined in the IEngineTask

STATUS_NOT_STARTED
STATUS_RUNNING
STATUS_SUCCEEDED
STATUS_FAILED
STATUS_CANCELLED

Jason

Mikey wrote:
> Does BIRT support asynchronous invocation of reports?
>
> I am looking for a run method that gives me a job id of some kind and i
> can query BIRT using the job id and get the status of the report execution?
>
Re: Asynchronous invocation of reports [message #360850 is a reply to message #360837] Mon, 25 February 2008 22:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pari.gandhi.gmail.com

Jason,

Thanks for that. Have you got an example of this?

Thanks once again
Re: Asynchronous invocation of reports [message #360871 is a reply to message #360850] Tue, 26 February 2008 16:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Here is an example of canceling a task. It only spawns a thread to
cancel the currently running report.

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.IGetParameterDefinitionTa sk;
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 RunAndRenderTask {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;

try{
//System.setProperty("java.io.tmpdir", "c:/temp/test/testsampledb");
config = new EngineConfig( );

config.setBIRTHome(" C:\\birt\\birt-runtime-2_2_1\\birt-runtime-2_2_1\\ReportEngi ne ");
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/parmdisp.rptdesign");


IGetParameterDefinitionTask ptask =
engine.createGetParameterDefinitionTask( design );

String myDefaultValue = (String)ptask.getDefaultValue("para1");
Collection selectionList = ptask.getSelectionList("para1");
String myDisplayLabel = "";
if ( selectionList != null )
{
for ( Iterator sliter = selectionList.iterator( ); sliter.hasNext( ); )
{
IParameterSelectionChoice selectionItem =
(IParameterSelectionChoice) sliter.next( );

String value = (String)selectionItem.getValue( );
if( value.compareTo(myDefaultValue) == 0 ){
myDisplayLabel = selectionItem.getLabel();
break;
}

}

}


ptask.close();


//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
String tst = task.getParameterDisplayText("para1");
task.setParameterDisplayText("para1", myDisplayLabel);
task.setParameterValue("para1", myDefaultValue);




// task.setParameterValue("Top Count", (new Integer(5)));
// task.validateParameters();

HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/resample/Parmdisp.html");
options.setOutputFormat("html");
options.setHtmlRtLFlag(false);
options.setEmbeddable(false);

//
options.setImageDirectory("C:\\apps\\apache-tomcat-5.5.20\\webapps\\2.2\\images ");
// options.setBaseImageURL("http://localhost:8080/2.2/images/");

//ImageHandlerTest
// options.setImageHandler(new MyImageHandler());
//options.setImageHandler(new HTMLServerImageHandler());
//options.setImageHandler(new HTMLCompleteImageHandler());
//options.setBaseImageURL("http://localhost/imageGetter?");
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();


//Create task to run and render the report,
//task = engine.createRunAndRenderTask(design);
//task.setParameterValue("Top Percentage", (new Integer(3)));
//task.setParameterValue("Top Count", (new Integer(5)));
//task.validateParameters();
//task.setRenderOption(options);


//beginTime = System.currentTimeMillis();
//task.run();
//endTime = System.currentTimeMillis();
//timeSpan = endTime - beginTime;
//System.out.println("Report Runtime: " + timeSpan);
//teststatus = task.getStatus();
//if( teststatus == 2){
// System.out.println("Report Completed");
//}

//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
{

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

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

}
public void run()
{
try{
Thread.currentThread().sleep( 100 );
rTask.cancel();
System.out.println("######Report Cancelled#######");

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


}

Jason

Dunce wrote:
> Jason,
>
> Thanks for that. Have you got an example of this?
>
> Thanks once again
>
Re: Asynchronous invocation of reports [message #768150 is a reply to message #360871] Mon, 19 December 2011 16:58 Go to previous messageGo to next message
Tony M is currently offline Tony MFriend
Messages: 7
Registered: December 2011
Location: Lodon
Junior Member
Could you please clarify this thread.
after i run a task, BIRT engine waits until this task is finished for it to continue processing making it impossible to satisfy the condition where

task.getStatus() == IRunTask.STATUS_RUNNING

Please clarify as i need to return the task status in case the document generation takes some while for big reports. With my very limited knowledge of BIRT i think it is synchronous report generation. since a task has to wait until the run is finished in order to continue processing, right?

thanks a lot for the help

Tony

Re: Asynchronous invocation of reports [message #768322 is a reply to message #768150] Mon, 19 December 2011 22:50 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Tony,

In that example a separate thread is launched that just cancels the
current threads task. You get the task number as soon as you create it.
You could spawn another thread to monitor the task. I put the code
back in this response and if you look at the line :

Thread.currentThread().sleep( 100 );
rTask.cancel();
System.out.println("######Report Cancelled#######");
The thread sleeps for 100 millis and then cancels the task. You could
have put a while loop that checked the status every couple of seconds
and when it ran to long cancel it.

Here are the status values:

* the task is not running yet
*/
static final int STATUS_NOT_STARTED = 0;
/**
* the task is running
*/
static final int STATUS_RUNNING = 1;
/**
* the task is finished with sucessful
*/
static final int STATUS_SUCCEEDED = 2;
/**
* the task is finished with errors
*/
static final int STATUS_FAILED = 3;
/**
* the task is finished by cancled
*/
static final int STATUS_CANCELLED = 4;


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;
public CancelReport( String threadName, IRunAndRenderTask task){
super(threadName);
rTask = task;

}
public void run()
{
try{
Thread.currentThread().sleep( 100 );
rTask.cancel();
System.out.println("######Report Cancelled#######");

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


}


You can also implement a progress monitor that is notified of different
events as they occur.
Take a look at this page:

http://www.eclipse.org/birt/phoenix/project/notable2.5.php#jump_19

Jason


On 12/19/2011 11:59 AM, Tony wrote:
> Could you please clarify this thread.
> after i run a task, BIRT engine waits until this task is finished for it
> to continue processing making it impossible to satisfy the condition where
>
> task.getStatus() == IRunTask.STATUS_RUNNING
>
> Please clarify as i need to return the task status in case the document
> generation takes some while for big reports. With my very limited
> knowledge of BIRT i think it is synchronous report generation. since a
> task has to wait until the run is finished in order to continue
> processing, right?
>
> thanks a lot for the help
>
> Tony
>
>
Re: Asynchronous invocation of reports [message #768490 is a reply to message #768322] Tue, 20 December 2011 08:46 Go to previous message
Tony M is currently offline Tony MFriend
Messages: 7
Registered: December 2011
Location: Lodon
Junior Member
Cheers Jason, that's exactly what i wanted.
Tony
Previous Topic:Asynchronous invocation of reports
Next Topic:Disable drill through actions in PDF format
Goto Forum:
  


Current Time: Mon Dec 22 15:00:46 GMT 2014

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

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