Asynchronous invocation of reports [message #360813] |
Mon, 25 February 2008 00:41  |
Eclipse User |
|
|
|
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 #360871 is a reply to message #360850] |
Tue, 26 February 2008 11:11   |
Eclipse User |
|
|
|
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
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25522 seconds