List Info

Thread: Protocol handler and Thread.sleep()




Protocol handler and Thread.sleep()
user name
2007-01-08 08:45:38
Tobias Krais schrieb:
> Hi together again,
> 
> I implemented a protocol handler for the CommandURL
.Judas:PrintTrays.
> The target of this new protocol is to print a document
on different
> printer trays (page one on tray with letter paper, the
others on the
> tray with normal paper). After sending the print
command via API I added
> a PrintJobListener:
> -----%<-----
> // Querying for the interface XPrintable on the loaded
document
> XPrintable xPrintable = (XPrintable)
>                
UnoRuntime.queryInterface(XPrintable.class,
> 			this.xComponent);
> 
> // Adding a print job listener
> XPrintJobBroadcaster selection = (XPrintJobBroadcaster)
>       
		UnoRuntime.queryInterface(XPrintJobBroadcaster.class,
> 			xPrintable);
> OOPrintJobListener ooPrintJobListener = new
OOPrintJobListener();
> ooPrintJobListener.setDebug(debug);
> selection.addPrintJobListener(ooPrintJobListener);
> 
> // Setting the property "Pages" so that only
the desired pages
> // will be printed.
> PropertyValue[] printOpts = new PropertyValue[1];
> printOpts[0] = new PropertyValue();
> printOpts[0].Name = "Pages";
> printOpts[0].Value = myPages;
> 
> try {
> 	xPrintable.print(printOpts);
> } catch (IllegalArgumentException e) {}
> 		
> // Watch print process and continue if done.
> // TODO: see OO Bug id 72240; don't print a
non-existing page, other-
> // wise here is a loop.
> while (ooPrintJobListener.getStatus() == null ||
>            ooPrintJobListener.getStatus() ==
PrintableState.JOB_STARTED)
> {
> 	try {
>     		Thread.sleep(2000);
>     	}
>     	catch (InterruptedException e) {}
> }
> -----%<-----
> 
> In the line where I wait send the Thread sleeping, I
send the whole OO
> sleeping and my protocol handler throws an exception.
Is this a bug or a
> feature?
> 
> I solved this problem by creating another thread
printing my document.
> Then it works. But this other thread won't show my
dialog if the print
> failes. How can I show the dialog if my print failes
from an other thread?

All dispatch objects (and ProtocolHandler are such dispatch
objects) 
will be called synchronous from the main thread of the
office. This is 
reasoned by the history of the code of OOo. So you are
right: your 
sleep() call blocks the whole office.

The only solution is forwarding of all dispatch requests,
which arrive 
your ProtocolHandler object to a special thread. There you
can do 
anything you like ... even calling sleep().

> 
> Greetings, Tobias
> 

Regards
Andreas

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )