Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining if a printer can handle a print job without look-up

I have been battling the PrintServiceLookup; the lookupPrintServices(DocFlavor flavor, AttributeSet attributes) method is excessively slow to detect printers in our application with the initial run-in. Clients with more than 100 network printers have reported that behaviour that executes this code is poorly performing the first time it is run.

After seeing that the look-up results are being cached, I have initially deployed a dummy look-up within a separate thread (executed at start-up). However, for a particular client this solution is not working.

I do not currently have their environment and cannot see what is causing the exact performance problem.

I am trying to see if a PrintService supports a given MediaSizeName without performing a look-up of DocFlavor and AttributeSet. So I pull all available PrintServices and the default PrintService:

private static final PrintService[] PRINTSERVICES =     PrintServiceLookup.lookupPrintServices(null, null);  private static final PrintService DEFAULTSERVICE =     PrintServiceLookup.lookupDefaultPrintService(); 

And then, obtain the PrintService and the MediaSizeName from the client request. Finally, I ask the PrintService if the MediaSizeName is supported by:

private void checkPrintServiceForMediaSize(PrintService pservice) throws MediaSizeNotSupportedException{      if(!pservice.isAttributeValueSupported(_mediaSizeName,null,null))             throw new MediaSizeNotSupportedException("This media size is not supported by the selected printer.");      } 

The API declares that when isAttributeValueSupported(Attribute attrval,DocFlavor flavor,AttributeSet attributes) is called with null DocFlavor and AttributeSet

this method tells whether this Print Service supports the given printing attribute value for some possible combination of doc flavor and set of attributes

and has behaved correctly up until now. However, I am not entirely sure if this is the way to perform if a printer supports a selected page size.

I would appreciate your feedback and experience on this issue.


Update

Around the time I implemented my approach, my workstation decided to have serious network issues, which took me awhile to figure out. Finally, my implementation has been tested with the networking tool SoftPerfect Connection Emulator (to simulate network load) and the results have not improved significantly.

I will continue testing and update this question. Hopefully I can find a solution and share it with people here. I am guessing that the initial lookup:

private static final PrintService[] PRINTSERVICES =     PrintServiceLookup.lookupPrintServices(null, null); 

is still causing issues.


Update 2

The beta build is finally tested on the client environment and performance of the printing dialog is about 5 times improved (the initial pull of printer now takes about 1 minute under the same environment compared to about 5 minutes). Still the initial wait time is not an acceptable amount of time, however, is the best I could do for now. We have also heard from the client that a print server is being used and following the suggestions in the comments (@Wardy), I will be moving on in this direction. Hopefully, we can leverage the advantages of the print server.

like image 608
arin Avatar asked Apr 04 '12 13:04

arin


People also ask

How do I find the print queue?

Double clicking on the printer icon will open the Print Queue on your computer. (You can also open the Print Queue by clicking on Devices and Printers in the Start Menu, then double clicking on the printer you are trying to print to.) The Print Queue will show you how many jobs are waiting to be sent to the printer.

How do I find the print queue on a Mac?

View information about completed print jobs On your Mac, choose Apple menu > System Preferences, then click Printers & Scanners . Select the printer you used in the list at the left, then click Open Print Queue.

How do I clear the printer cache?

Click "See What's Printing." Open the "Printer" menu, pick "Cancel All Documents" and choose "Yes." The list should clear within a few seconds. If one or more print jobs remain on the list, reboot your computer to clear out the memory.


1 Answers

More aggressive caching. Have the client perform the look-up once and persist the cache between restarts. Better yet, save the cache to a central data store which is accessible by all clients.

I'm assuming that network printers and their capabilities don't change that often but you have to update the cache eventually, but the "who" and "when" is dependent on your environment.

Updates to the cache can be made by a client that runs your current discovery in the background and if changes are detected updates the cache. If you have a central component that runs continuously anyway, that would be a good place where you can check in fixed intervals.

If you have some kind of directory service you can compare its list of printers with you cache before contacting each printer to get its capabilities to lessen network and cpu load.

like image 130
Darcara Avatar answered Oct 02 '22 03:10

Darcara