Incremental updates from Tasks

Roman Kennke roman at kennke.org
Fri Jan 6 13:00:54 PST 2012


Hi Richard,

> 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

I was thinking about the same when you asked about how to get the state
(thread safe) into a cancelled() callback method. An API to do partial
updates would be helpful.

What about an API similar to how it's done in SwingWorker? There we
define a 2nd type parameter T and publish() partial results. This would
be called from the call() method whenever we have a partial result:

protected void publish(T chunk)

Which in turn results into a call (on the JavaFX thread) to:

protected void process(List<T> chunks...)

Which allows to process one or more chunks that have been published
before using publish().

I like that API and it solves the question how to handle atomic vs. list
types simply by introducing a new generic type. It also has the
advantage that Swing refugees feel familiar with it :-)

Anything wrong with that approach?

Regards, Roman




More information about the openjfx-dev mailing list