319 |
*/ |
*/ |
320 |
protected abstract boolean handleEvents(boolean waitForEvent); |
protected abstract boolean handleEvents(boolean waitForEvent); |
321 |
|
|
322 |
|
private PriorityQueue queue = new PriorityQueue(); |
323 |
|
|
324 |
|
/** Run a given task in the main thread at some point |
325 |
|
* in the future. |
326 |
|
* @see gzz.util.Background#addTask |
327 |
|
*/ |
328 |
|
public void doWhenIdle(Runnable r, int priority) { |
329 |
|
synchronized(queue) { |
330 |
|
queue.add(r, priority); |
331 |
|
queue.notifyAll(); |
332 |
|
} |
333 |
|
} |
334 |
|
|
335 |
/** Do the background tasks that need to be done in |
/** Do the background tasks that need to be done in |
336 |
* the main thread. |
* the main thread. |
337 |
* Implementations overriding this method should also delegate! |
* Implementations overriding this method should also delegate! |
338 |
* @return true if something was done. |
* @return true if something was done. |
339 |
*/ |
*/ |
340 |
protected boolean doIdle() { |
protected boolean doIdle() { |
341 |
|
synchronized(queue) { |
342 |
|
Runnable r = (Runnable)queue.getAndRemoveLowest(); |
343 |
|
if(r != null) { |
344 |
|
if(dbg) pa("Updmanager idle: run "+r); |
345 |
|
r.run(); |
346 |
|
if(dbg) pa("Updmanager idle: finished run "+r); |
347 |
|
return true; |
348 |
|
} |
349 |
|
} |
350 |
return false; |
return false; |
351 |
} |
} |
352 |
|
|