Class ProgressiveRendering
- Direct Known Subclasses:
RunListProgressiveRendering
- Write a
<script>
section definingfunction display(data)
. (Callts_refresh($('someid'))
if using asortable
table.) - Use
<l:progressiveRendering handler="${it.something()}" callback="display"/>
from your Jelly page to display a progress bar and initialize JavaScript infrastructure. (The callback attribute can take arbitrary JavaScript expression to be evaluated in the browser so long as it produces a function object.) - Implement
something()
to create an instance of your subclass ofProgressiveRendering
. - Perform your work in
compute()
. - Periodically check
canceled()
. - As results become available, call
progress(double)
. - Make
data()
produce whatever JSON you want to send to the page to be displayed.
design-library
demonstrates all this.- Since:
- 1.484
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final boolean
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.protected ExecutorService
May be overridden to provide an alternate executor service.final net.sf.json.JSONObject
news()
For internal use.protected final void
progress
(double completedFraction) Indicate what portion of the work has been done.final void
start()
For internal use.protected long
timeout()
May be overridden to control the inactivity timeout.
-
Constructor Details
-
ProgressiveRendering
protected ProgressiveRendering()Constructor for subclasses.
-
-
Method Details
-
start
@JavaScriptMethod public final void start()For internal use. -
compute
Actually do the work.The security context will be that in effect when the web request was made.
Stapler.getCurrentRequest2()
will also be similar to that in effect when the web request was made; at least,Ancestor
s and basic request properties (URI, locale, and so on) will be available.- Throws:
Exception
- whenever you like; the progress bar will indicate that an error occurred but details go to the log only
-
data
@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
{}
or[]
), 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 incompute()
which modifies these fields should also temporarily be synchronized on the same monitor such asthis
.- Returns:
- any JSON data you like
-
progress
protected final void progress(double completedFraction) Indicate what portion of the work has been done. (Oncecompute()
returns, the work is assumed to be complete regardless of this method.)- Parameters:
completedFraction
- estimated portion of work now done, from 0 (~ 0%) to 1 (~ 100%)
-
canceled
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. Thereforecompute()
should periodically say:if (canceled()) return;
- Returns:
- true if user seems to have abandoned us, false if we should still run
-
news
@JavaScriptMethod public final net.sf.json.JSONObject news()For internal use. -
executorService
May be overridden to provide an alternate executor service.- Returns:
- by default,
Timer.get()
-
timeout
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 tocanceled()
will be true.- Returns:
- timeout in milliseconds; by default, 15000 (~ 15 seconds)
-