- Write a
function display(data). (Call
ts_refresh($('someid'))if using a
something()to create an instance of your subclass of
- Perform your work in
- Periodically check
- As results become available, call
data()produce whatever JSON you want to send to the page to be displayed.
ui-samples-plugindemonstrates all this.
- Write a
Constructors Modifier Constructor Description
ProgressiveRendering()Constructor for subclasses.
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description
canceled()Checks whether the task has been canceled.
protected abstract void
compute()Actually do the work.
protected abstract net.sf.json.JSON
data()Provide current data to the web page for display.
executorService()May be overridden to provide an alternate executor service.
news()For internal use.
progress(double completedFraction)Indicate what portion of the work has been done.
start()For internal use.
timeout()May be overridden to control the inactivity timeout.
protected abstract void compute() throws ExceptionActually do the work.
The security context will be that in effect when the web request was made.
Stapler.getCurrentRequest()will also be similar to that in effect when the web request was made; at least,
Ancestors and basic request properties (URI, locale, and so on) will be available.
Exception- whenever you like; the progress bar will indicate that an error occurred but details go to the log only
@NonNull protected abstract net.sf.json.JSON data()Provide current data to the web page for display.
While this could be an aggregate of everything that has been computed so far, more likely you want to supply only that data that is new since the last call (maybe just
), so that the page can incrementally update bits of HTML rather than refreshing everything.
You may want to make your implementation
synchronized, so that it can track what was sent on a previous call, in which case any code running in
compute()which modifies these fields should also temporarily be synchronized on the same monitor such as
- any JSON data you like
protected final void progress(double completedFraction)Indicate what portion of the work has been done. (Once
compute()returns, the work is assumed to be complete regardless of this method.)
completedFraction- estimated portion of work now done, from 0 (~ 0%) to 1 (~ 100%)
protected final boolean canceled()Checks whether the task has been canceled. If the rendering page fails to send a heartbeat within a certain amount of time, the user is assumed to have moved on. Therefore
compute()should periodically say:
if (canceled()) return;
- true if user seems to have abandoned us, false if we should still run
protected ExecutorService executorService()May be overridden to provide an alternate executor service.
- by default,
protected long timeout()May be overridden to control the inactivity timeout. If no request from the browser is received within this time, the next call to
canceled()will be true.
- timeout in milliseconds; by default, 15000 (~ 15 seconds)