public abstract class AsynchronousSectionedRenderer<RESPONSE extends com.yahoo.processing.Response> extends AsynchronousRenderer<RESPONSE>
This API assumes all data should be rendered. Choosing which data should be rendered is the responsibility of the processing chains.
Modifier and Type | Class and Description |
---|---|
private class |
AsynchronousSectionedRenderer.DataListener
A data listener is invoked every time new data is available in an incoming list, such that this data
can be rendered before completion of the entire list (streaming).
|
private class |
AsynchronousSectionedRenderer.DataListListener
A listener to async completion of a data list.
|
private static class |
AsynchronousSectionedRenderer.ParentOfTopLevel
This must be pushed on the stack first to get things started off, given that the stack is expected to
contain the parent of each element (including the topmost)
|
private class |
AsynchronousSectionedRenderer.RendererListener |
Modifier and Type | Field and Description |
---|---|
private boolean |
beforeHandoverMode |
private com.yahoo.jdisc.handler.ContentChannel |
channel |
private boolean |
clientClosed |
private com.yahoo.jdisc.handler.CompletionHandler |
completionHandler |
private Deque<AsynchronousSectionedRenderer.DataListListener> |
dataListListenerStack
The stack of listeners to ancestor datalist completions above the current one
|
private com.yahoo.processing.execution.Execution |
execution |
private boolean |
isInitialized |
private static Logger |
logger |
private boolean |
networkIsInitialized |
private Executor |
renderingExecutor |
private boolean |
renderingExecutorIsOwned |
private RESPONSE |
response |
private Object |
singleThreaded |
private OutputStream |
stream |
private com.google.common.util.concurrent.SettableFuture<Boolean> |
success |
Constructor and Description |
---|
AsynchronousSectionedRenderer()
Create an renderer instance not yet associated with any request
processing or network for easy subclassing.
|
AsynchronousSectionedRenderer(Executor executor)
Create an renderer using the specified executor instead of the default one which should be used for production.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
beginList(com.yahoo.processing.response.DataList<?> list)
Invoked at the beginning of each data list, including the implicit,
outermost one in the response.
|
abstract void |
beginResponse(OutputStream stream)
Invoked once at the beginning of rendering a response.
|
protected boolean |
clientClosed()
Returns whether the client this is rendering to has closed the connection
|
private static ThreadPoolExecutor |
createExecutor() |
abstract void |
data(com.yahoo.processing.response.Data data)
Invoked for each leaf node in the data tree
|
void |
deconstruct() |
abstract void |
endList(com.yahoo.processing.response.DataList<?> list)
Invoked at the end of each data list, including the implicit, outermost
one in the response.
|
abstract void |
endResponse()
Invoked once at the end of rendering a response.
|
com.yahoo.processing.execution.Execution |
getExecution()
The outermost execution which was run to create the response to render.
|
(package private) Executor |
getExecutor()
Returns the executor in which to execute a listener.
|
int |
getRecursionLevel()
How deep into the tree of nested data lists the callback currently is.
|
(package private) Executor |
getRenderingExecutor()
For inspection only; use getExecutor() for execution
|
com.yahoo.processing.Response |
getResponse()
The response render callbacks are generated from.
|
void |
init()
Do per instance initialization.
|
protected void |
onClientClosed()
This hook is called once when the renderer detects that the client has closed the connection
|
com.google.common.util.concurrent.ListenableFuture<Boolean> |
render(OutputStream stream,
RESPONSE response,
com.yahoo.processing.execution.Execution execution,
com.yahoo.processing.Request request)
Render this response using the renderer's own threads and return a future indicating whether the rendering
was successful.
|
com.google.common.util.concurrent.ListenableFuture<Boolean> |
renderBeforeHandover(OutputStream stream,
RESPONSE response,
com.yahoo.processing.execution.Execution execution,
com.yahoo.processing.Request request)
Initiate rendering before handover to rendering threads.
|
void |
setNetworkWiring(com.yahoo.jdisc.handler.ContentChannel channel,
com.yahoo.jdisc.handler.CompletionHandler completionHandler)
For internal use: Expose JDisc wiring to ensure asynchronous cleanup.
|
private void |
shutdown(ThreadPoolExecutor executor) |
private com.google.common.util.concurrent.ListenableFuture<Boolean> |
startRender(OutputStream stream,
RESPONSE response,
com.yahoo.processing.execution.Execution execution,
com.yahoo.processing.Request request) |
clone, getEncoding, getMimeType
private static final Logger logger
private Deque<AsynchronousSectionedRenderer.DataListListener> dataListListenerStack
private boolean beforeHandoverMode
private OutputStream stream
private RESPONSE extends com.yahoo.processing.Response response
private com.yahoo.processing.execution.Execution execution
private boolean clientClosed
private Object singleThreaded
private final Executor renderingExecutor
private final boolean renderingExecutorIsOwned
private com.google.common.util.concurrent.SettableFuture<Boolean> success
private com.yahoo.jdisc.handler.ContentChannel channel
private com.yahoo.jdisc.handler.CompletionHandler completionHandler
private boolean networkIsInitialized
private boolean isInitialized
public AsynchronousSectionedRenderer()
public AsynchronousSectionedRenderer(Executor executor)
executor
- the executor to use or null to use the default executor suitable for productionpublic abstract void beginResponse(OutputStream stream) throws IOException
stream
- the stream to render to in this and all subsequent calls.IOException
- passed on from the streampublic abstract void beginList(com.yahoo.processing.response.DataList<?> list) throws IOException
list
- the data list which now will be renderedIOException
- passed on from the streampublic abstract void data(com.yahoo.processing.response.Data data) throws IOException
data
- the leaf node to renderIOException
- passed on from the streampublic abstract void endList(com.yahoo.processing.response.DataList<?> list) throws IOException
list
- the data list which now has no more data items to renderIOException
- passed on from the streampublic abstract void endResponse() throws IOException
IOException
- passed on from the streamprivate static ThreadPoolExecutor createExecutor()
public final com.google.common.util.concurrent.ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response, com.yahoo.processing.execution.Execution execution, com.yahoo.processing.Request request)
Render this response using the renderer's own threads and return a future indicating whether the rendering was successful. The data list tree will be traversed asynchronously, and the pertinent methods will be called as data becomes available.
If rendering fails, the exception causing this will be wrapped in an ExecutionException and thrown from blocked calls to Future.get()
render
in class Renderer<RESPONSE extends com.yahoo.processing.Response>
stream
- a stream API bridge to JDiscresponse
- the response to renderexecution
- the execution which created this responserequest
- the request matching the responsepublic void deconstruct()
deconstruct
in class com.yahoo.component.AbstractComponent
private void shutdown(ThreadPoolExecutor executor)
public final com.google.common.util.concurrent.ListenableFuture<Boolean> renderBeforeHandover(OutputStream stream, RESPONSE response, com.yahoo.processing.execution.Execution execution, com.yahoo.processing.Request request)
private com.google.common.util.concurrent.ListenableFuture<Boolean> startRender(OutputStream stream, RESPONSE response, com.yahoo.processing.execution.Execution execution, com.yahoo.processing.Request request)
Executor getExecutor()
Executor getRenderingExecutor()
public com.yahoo.processing.execution.Execution getExecution()
public com.yahoo.processing.Response getResponse()
protected boolean clientClosed()
protected void onClientClosed()
public int getRecursionLevel()
public final void setNetworkWiring(com.yahoo.jdisc.handler.ContentChannel channel, com.yahoo.jdisc.handler.CompletionHandler completionHandler)
setNetworkWiring
in class AsynchronousRenderer<RESPONSE extends com.yahoo.processing.Response>
channel
- the channel to the client receiving the responsecompletionHandler
- the JDisc completion handler which will be invoked at the end
of the renderingIllegalStateException
- if attempted invoked more than onceCopyright © 2017. All rights reserved.