Incremental updates from Tasks
Richard Bair
richard.bair at oracle.com
Fri Jan 6 12:51:01 PST 2012
Hi,
OK, here is the next issue I ran into while documenting the Task for the last issue. We don't really have a good way for the Task to do incremental updates to the Task value. Instead, it is only set at the conclusion of the call method, and only when the Task isn't cancelled. This is fairly limiting. Instead, it would be nice to allow Task subclasses to set the value whenever they like -- before execution (such as in the constructor), multiple times during execution, or even after it has been cancelled.
This is the issue: http://javafx-jira.kenai.com/browse/RT-18820
There are two parts to this solution. The first is solving incremental updates when the value is an atomic value (String, int, Customer, etc). The second is solving incremental updates for collections. I will tackle these separately (I think the best answer is to have a simple updateValue for everything and a special ObservableListTask which handles Tasks that return an ObservableList with all the fancy bells and whistles for dealing with incremental updates to an ObservableList).
Here is my proposed new API to add to Task:
/**
* Updates the <code>value</code> property with the supplied value. This
* can be done at any time. A final <code>updateValue</code> is called
* automatically by Task at the completion of the <code>call</code>
* method. This method allows Task implementations to provide partial
* results.
*
* <p>For example, you may have a Task which computes prime numbers. Each
* prime number computed could become the new <code>value</code> of the
* Task. Simply invoke updateValue passing the most recently computed
* prime number.</p>
*
* <p>As with the other update methods, Calls to updateValue
* are coalesced and run later on the FX application thread, so calls
* to updateValue, even from the FX Application thread, may not
* necessarily result in immediate updates to this property, and
* intermediate values may be coalesced to save on event
* notifications.
* <p>
* <em>This method is safe to be called from any thread.</em>
* </p>
*
* @param value The new value for the <code>value</code> property of Task.
*/
protected void updateValue(V value) { ... }
I'm formulating the fix for the ObservableListTask (I figure that is what I will call it, although it isn't all that nice a name to be honest, but it is right to the point).
Richard
More information about the openjfx-dev
mailing list