public class PrintPS implements PrintServiceAttributeListener { ... pservices[0].addPrintServiceAttributeListener(this); ... public void attributeUpdate(PrintServiceAttributeEvent e){ // Do something if an attribute is updated } ...The PrintServiceAttributeListener.attributeUpdate() method is called when print service attributes change. The service uses the PrintServiceAttributeListener interface to decide which events it supports.
An application can discover which print service attributes a service supports by using the same query methods it uses to discover which request attributes a service supports. For example, to discover if the service supports the QueuedJobCount attribute an application calls:
service.isAttributeCategorySupported(QueuedJobCount.class);The service determines how frequently it reports updates on attributes. If many attributes are supported, the service might batch events, which means an application isn't guaranteed to receive a particular event. The delivered event contains only attributes that have changed in value, which means that static service attributes, such as the printer model, will never be reported in an event.
One message in particular: printJobNoMoreEvents is unusual but useful. A client is often interested in knowing if a job has finished or failed. If possible, a service should deliver such "terminal" events, but sometimes the service cannot be sure if the job finished or failed, and a "completed" message is misleading in this case. For example, a job might be spooled to a network print service that has a queue that's not visible. In this case, the "no more events" message is not sufficient to say that the job has succeeded, but the client can at least infer that it is not known to have failed. The following example demonstrates adding a listener that monitors printJobNoMoreEvents messages:
public class PrintPS extends PrintJobAdapter{ ... pj.addPrintJobListener(this); ... public void printJobNoMoreEvents(PrintJobEvent e){ // Do something here } ...