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;
}
}
}
}
Aggregations