You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Bernard Giannetti <th...@hotmail.com> on 2011/09/18 15:42:09 UTC

Interrupt/cancel/abort a render

Hi,

I'm wondering if it's possible to interrupt/cancel/abort a render once it has been started.  I'm embedding FOP into a Java desktop application in a similar way which is described here: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java?view=markup.  

I've looked at the API and nothing is immediately obvious.  I found this old forum post (http://www.mail-archive.com/fop-user@xml.apache.org/msg05146.html) which didn't help.

I am running the rendering process in a thread but not sure how I'd go about cleanly/gracefully aborting a render.

Thanks,

Bernard. 		 	   		  

Re: Fails to build publican's user guide

Posted by Vincent Hobeïka <vi...@gmail.com>.
Hi Pascal,

On Wednesday 07 December 2011 14:25:08 Pascal Sancho wrote:
> Can you try it against FOP trunk?
> 

I have tried it against FOP trunk and it passes!
Revision: 1211788

> The main thing here is to isolate a short testcase that still
> demonstrates the issue in both 0.95 and 1.0 versions.
> Even if FOP trunk passes the test, the snippet could be used for unit-test

I'll see what I can do about this. The debian user told me this file was 
generated from a docbook xml file and it seems they haven't used fop 1.0 before 
so they haven't tracked which commit broke things. If I come up with something 
I'll tell you.

Thanks
-- 
Vincent Hobeïka

Re: Fails to build publican's user guide

Posted by Pascal Sancho <pa...@takoma.fr>.
Hi Vincent,

Le 07/12/2011 10:15, Vincent Hobeïka a écrit :
> Hi Pascal,
> 
> Thank you for your kind answer.
> 
> On Tue, Dec 6, 2011 at 3:33 PM, Pascal Sancho <pa...@takoma.fr> wrote: 
>> when you ask on this list, you should provide a shrinked XSL-FO that 
>> demonstrates the problem
> 
> I am sorry about that. Thank you for pointing this. I'll do as you say
> next time.
> 
>> That said, I've found that using fo:inline within a fo:block with
>> hyphenate="true" linefeed-treatment="preserve" throws an NPE.
> 
> Thank you for the hint, I'll try to investigate more in this way.
> 
>> Fortunately, I can only reproduce it on FOP 0.95, while FOP 1.0 passes.
> 
> The debian user who reported the bug stated that it happens with FOP
> 1.0.
> 
> I was able to reproduce the bug with 1.0 and not 0.95. I did a
> comparison of the output messages and they just doesn't have much in
> common. I can produce the pdf with fop 0.95 but not with fop 1.0.

Hmm,
I've just retested the whole FO against 0.95, 1.0 and build from trunk.
result: 0.95 and 1.0 fail, while TRUNK passes.
Probably my shrinked FO was too shrinked, since the 1.0 didn't fail
yesterday.

Can you try it against FOP trunk?

> I'm giving you the output messages I have:
> 
> $ fop -version
> [warning] /usr/bin/fop: Unable to locate servlet-api in /usr/share/java FOP 
> Version 1.0
> 
> http://www.hobeika.fr/~vincent/fop/log_all1.0          	1.0 Mo
> http://www.hobeika.fr/~vincent/fop/log_cout1.0         965 Ko
> http://www.hobeika.fr/~vincent/fop/log_err1.0              20 Ko
> 
> and for fop 0.95
> 
> http://www.hobeika.fr/~vincent/fop/log_all0.95            231 o
> http://www.hobeika.fr/~vincent/fop/log_cout0.95             0 o
> http://www.hobeika.fr/~vincent/fop/log_err0.95            231 o
> 
> Is there something I can do to help more about this?
> I have search quite a lot the bug tracker but I wasn't able to find tickets 
> related to fo:inline within a fo:block and NullPointerException in 
> InlineStackingLayoutManager.java:277
> 
> Is this a new bug or can you point me to the related bug? I may add my logs in 
> it then.

The main thing here is to isolate a short testcase that still
demonstrates the issue in both 0.95 and 1.0 versions.
Even if FOP trunk passes the test, the snippet could be used for unit-test

probably related to #48806 [1], #46386 [2].

[1] https://issues.apache.org/bugzilla/show_bug.cgi?id=48806
[2] https://issues.apache.org/bugzilla/show_bug.cgi?id=46386

> Thanks again for your concern.
> 
> Best regards,

-- 
Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Fails to build publican's user guide

Posted by Vincent Hobeïka <vi...@gmail.com>.
Hi Pascal,

Thank you for your kind answer.

On Tue, Dec 6, 2011 at 3:33 PM, Pascal Sancho <pa...@takoma.fr> wrote: 
> when you ask on this list, you should provide a shrinked XSL-FO that 
> demonstrates the problem

I am sorry about that. Thank you for pointing this. I'll do as you say
next time.

> That said, I've found that using fo:inline within a fo:block with
> hyphenate="true" linefeed-treatment="preserve" throws an NPE.

Thank you for the hint, I'll try to investigate more in this way.

> Fortunately, I can only reproduce it on FOP 0.95, while FOP 1.0 passes.

The debian user who reported the bug stated that it happens with FOP
1.0.

I was able to reproduce the bug with 1.0 and not 0.95. I did a
comparison of the output messages and they just doesn't have much in
common. I can produce the pdf with fop 0.95 but not with fop 1.0.

I'm giving you the output messages I have:

$ fop -version
[warning] /usr/bin/fop: Unable to locate servlet-api in /usr/share/java FOP 
Version 1.0

http://www.hobeika.fr/~vincent/fop/log_all1.0          	1.0 Mo
http://www.hobeika.fr/~vincent/fop/log_cout1.0         965 Ko
http://www.hobeika.fr/~vincent/fop/log_err1.0              20 Ko

and for fop 0.95

http://www.hobeika.fr/~vincent/fop/log_all0.95            231 o
http://www.hobeika.fr/~vincent/fop/log_cout0.95             0 o
http://www.hobeika.fr/~vincent/fop/log_err0.95            231 o

Is there something I can do to help more about this?
I have search quite a lot the bug tracker but I wasn't able to find tickets 
related to fo:inline within a fo:block and NullPointerException in 
InlineStackingLayoutManager.java:277

Is this a new bug or can you point me to the related bug? I may add my logs in 
it then.

Thanks again for your concern.

Best regards,
-- 
Vincent Hobeïka

Re: Fails to build publican's user guide

Posted by Pascal Sancho <pa...@takoma.fr>.
Hi Vincent,

when you ask on this list, you should provide a shrinked XSL-FO that
demonstrates the problem (the one on Debian buglist is about 2MB, witch
is quite big).

That said, I've found that using fo:inline within a fo:block with
hyphenate="true" linefeed-treatment="preserve" throws an NPE.

Fortunately, I can only reproduce it on FOP 0.95, while FOP 1.0 passes.

So, you have 2 options:
 - either use FOP 1.0
 - or replace such fo:inline with fo:wrapper, since from what I've seen
they are used as properties carriers, not as related area properties
(i.e. padding, border, background, etc.).

Le 06/12/2011 11:46, Vincent Hobeïka a écrit :
> Sorry, I realise my report was quite imprecise.
> 
> fop encounters a NullPointerException in
> InlineStackingLayoutManager.java:277
> 
> I have found several reports regarding this kind of error in fop bug
> tracker:
> 
> https://issues.apache.org/bugzilla/show_bug.cgi?id=46386
> 
> https://issues.apache.org/bugzilla/show_bug.cgi?id=48765
> 
> So far I'm not sure if they are related.
> 
> Best regards,
> 
> -- 
> 
> Vincent Hobeïka
> 

-- 
Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Fails to build publican's user guide

Posted by Vincent Hobeïka <vi...@gmail.com>.
Sorry, I realise my report was quite imprecise.

fop encounters a NullPointerException in InlineStackingLayoutManager.java:277

I have found several reports regarding this kind of error in fop bug tracker:

https://issues.apache.org/bugzilla/show_bug.cgi?id=46386
https://issues.apache.org/bugzilla/show_bug.cgi?id=48765

So far I'm not sure if they are related.

Best regards,

-- 
Vincent Hobeïka

Fails to build publican's user guide

Posted by Vincent Hobeïka <vi...@gmail.com>.
Dear fop users,

I come to you to forward a bug from the debian bug tracker [1].

fop crashes when building publican's user guide. You can find a sample 
attachment [2] to reproduce the problem.

Best regards,

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=649476
[2] http://bugs.debian.org/cgi-
bin/bugreport.cgi?msg=10;filename=Users_Guide.fo.gz;att=1;bug=649476
-- 
Vincent Hobeïka

RE: Interrupt/cancel/abort a render

Posted by Theresa Jayne Forster <th...@inbrand.co.uk>.
Craig, I agree with you, that is exactly how we process stuff here, drop a
file in a folder and then the "fopengine" picks it up - processes and then
drops the output into another folder for the original process to pick up (or
time out)


Kindest regards


Theresa Forster
Senior Software Developer

-----Original Message-----
From: Craig Ringer [mailto:craig@postnewspapers.com.au] 
Sent: 06 December 2011 03:10
To: fop-users@xmlgraphics.apache.org
Cc: Alexios Giotis
Subject: Re: Interrupt/cancel/abort a render

IMO the best way to make it cancelable is to run fop out-of-process in a 
separate VM instance that you can kill using the standard OS methods.

That's what I think I'll end up doing when I need to support 
cancellation. It's a bit of a pain and has some performance cost because 
you can't re-use the fop factory for multiple runs or benefit from some 
of fop's other caching. Perhaps more importantly it means you can't run 
under a standard SecurityManager since you need to be able to spawn new 
JVM instances. OTOH, it eliminates potential memory leaks / unwanted 
threadlocals / caches.

--
Craig Ringer




---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Interrupt/cancel/abort a render

Posted by Craig Ringer <cr...@postnewspapers.com.au>.
On 09/21/2011 12:43 AM, Alexios Giotis wrote:
> Hi Bernard,
>
> As far as I know there is no build-in support in FOP to cancel the rendering. In Java, the only way to achieve it (except the deprecated stop()), is to get the thread that is executing it and call the interrupt() method. The problem is that there is no guarantee that the thread will interrupt it's execution and the behavior really depends on the code it is running. Typically if the thread is making calculations (and is not blocking on I/O requests or is not executing a method that throws InterruptedException, ....), then it will not respond to your interrupt. In this case, the only way to interrupt is if you execute code like
> if(Thread.interrupted()) // clears the interrupted status
>    throw SomeException();

IMO the best way to make it cancelable is to run fop out-of-process in a 
separate VM instance that you can kill using the standard OS methods.

That's what I think I'll end up doing when I need to support 
cancellation. It's a bit of a pain and has some performance cost because 
you can't re-use the fop factory for multiple runs or benefit from some 
of fop's other caching. Perhaps more importantly it means you can't run 
under a standard SecurityManager since you need to be able to spawn new 
JVM instances. OTOH, it eliminates potential memory leaks / unwanted 
threadlocals / caches.

--
Craig Ringer

POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088     Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Interrupt/cancel/abort a render

Posted by Alexios Giotis <al...@gmail.com>.
Hi Bernard,

As far as I know there is no build-in support in FOP to cancel the rendering. In Java, the only way to achieve it (except the deprecated stop()), is to get the thread that is executing it and call the interrupt() method. The problem is that there is no guarantee that the thread will interrupt it's execution and the behavior really depends on the code it is running. Typically if the thread is making calculations (and is not blocking on I/O requests or is not executing a method that throws InterruptedException, ....), then it will not respond to your interrupt. In this case, the only way to interrupt is if you execute code like 
if(Thread.interrupted()) // clears the interrupted status
  throw SomeException();

A good reading on cancellation and shutdown is Chapter 7 of "Java Concurrency in Practice" by  Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea.

In practice, you typically can't change code in existing libraries. *IF* you find that FOP is not responding to the interrupt methods, then a workaround is to pass your own classes that will (1) check for the interrupted status or (2) check for your own flag and throw an exception, for example (2nd case):

public class InterruptAwareOutputStream extends BufferedOutputStream {
private boolean volatile shouldStop = false;
public void interruptProcessing() {
   shouldStop = true;
}

public void write(.....) {
    if(shouldStop)
       throw MyException();
   else
    super.write(....);
}
// other methods that need to be overwritten
}

For the XML to PDF example you pointed, you will also need to subclass like this the ContentHandler given to the "new SAXResult".

If the thread does not respond to the interrupt, it's always helpful to know what this is executing. I typically print the stacktrace with code like:

executingThread.interrupt();
		
StackTraceElement ste[] = executingThread.getStackTrace();
StringBuilder sb = new StringBuilder(LINE_SEP);
for (StackTraceElement s : ste) {
  String stacktrace = s.toString();
  sb.append(LINE_SEP).append("\t\t").append(stacktrace);
}

String stackTrace = sb.toString();		
logger.info("Interrupted ["+info.task.getId()+"]" + " executed by thread ["
				+ executingThread.getName() + "] with stacktrace:" + stackTrace);



Hope this helps,
Alexios Giotis


On Sep 18, 2011, at 4:42 PM, Bernard Giannetti wrote:

> Hi,
> 
> I'm wondering if it's possible to interrupt/cancel/abort a render once it has been started.  I'm embedding FOP into a Java desktop application in a similar way which is described here: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java?view=markup.  
> 
> I've looked at the API and nothing is immediately obvious.  I found this old forum post (http://www.mail-archive.com/fop-user@xml.apache.org/msg05146.html) which didn't help.
> 
> I am running the rendering process in a thread but not sure how I'd go about cleanly/gracefully aborting a render.
> 
> 
> Thanks,
> 
> Bernard.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org