Search in sources :

Example 1 with PrintServiceAttributeEvent

use of javax.print.event.PrintServiceAttributeEvent in project jdk8u_jdk by JetBrains.

the class ServiceNotifier method run.

/* A heuristic is used to calculate sleep time.
     * 10 times the time taken to loop through all the listeners, with
     * a minimum of 15 seconds. Ensures this won't take more than 10%
     * of available time.
     */
public void run() {
    long minSleepTime = 15000;
    long sleepTime = 2000;
    HashPrintServiceAttributeSet attrs;
    PrintServiceAttributeEvent attrEvent;
    PrintServiceAttributeListener listener;
    PrintServiceAttributeSet psa;
    while (!stop) {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
        }
        synchronized (this) {
            if (listeners == null) {
                continue;
            }
            long startTime = System.currentTimeMillis();
            if (listeners != null) {
                if (service instanceof AttributeUpdater) {
                    psa = ((AttributeUpdater) service).getUpdatedAttributes();
                } else {
                    psa = service.getAttributes();
                }
                if (psa != null && !psa.isEmpty()) {
                    for (int i = 0; i < listeners.size(); i++) {
                        listener = (PrintServiceAttributeListener) listeners.elementAt(i);
                        attrs = new HashPrintServiceAttributeSet(psa);
                        attrEvent = new PrintServiceAttributeEvent(service, attrs);
                        listener.attributeUpdate(attrEvent);
                    }
                }
            }
            sleepTime = (System.currentTimeMillis() - startTime) * 10;
            if (sleepTime < minSleepTime) {
                sleepTime = minSleepTime;
            }
        }
    }
}
Also used : PrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener) PrintServiceAttributeEvent(javax.print.event.PrintServiceAttributeEvent) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet)

Aggregations

HashPrintServiceAttributeSet (javax.print.attribute.HashPrintServiceAttributeSet)1 PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)1 PrintServiceAttributeEvent (javax.print.event.PrintServiceAttributeEvent)1 PrintServiceAttributeListener (javax.print.event.PrintServiceAttributeListener)1