Package com.yahoo.processing.rendering
Class Renderer<RESPONSE extends com.yahoo.processing.Response>
- java.lang.Object
-
- com.yahoo.component.AbstractComponent
-
- com.yahoo.processing.rendering.Renderer<RESPONSE>
-
- All Implemented Interfaces:
com.yahoo.component.Component
,java.lang.Cloneable
,java.lang.Comparable<com.yahoo.component.Component>
- Direct Known Subclasses:
AsynchronousRenderer
public abstract class Renderer<RESPONSE extends com.yahoo.processing.Response> extends com.yahoo.component.AbstractComponent implements java.lang.Cloneable
Renders a response to a stream. The renderers are cloned just before rendering, and must therefore obey the following contract:- At construction time, only final members shall be initialized, and these must refer to immutable data only.
- State mutated during rendering shall be initialized in the init method.
- Author:
- Tony Vaagenes, Steinar Knutsen
-
-
Constructor Summary
Constructors Constructor Description Renderer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Renderer<RESPONSE>
clone()
Used to create a separate instance for each result to render.abstract java.lang.String
getEncoding()
Name of the output encoding, if applicable.abstract java.lang.String
getMimeType()
The MIME type of the rendered content sent to the client.void
init()
Initializes the mutable state, see the contract in the class documentation.abstract com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>
render(java.io.OutputStream stream, RESPONSE response, com.yahoo.processing.execution.Execution execution, com.yahoo.processing.Request request)
Render a response to a stream.
-
-
-
Method Detail
-
clone
public Renderer<RESPONSE> clone()
Used to create a separate instance for each result to render.- Overrides:
clone
in classcom.yahoo.component.AbstractComponent
-
init
public void init()
Initializes the mutable state, see the contract in the class documentation. Called on the clone just before rendering.
-
render
public abstract com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean> render(java.io.OutputStream stream, RESPONSE response, com.yahoo.processing.execution.Execution execution, com.yahoo.processing.Request request)
Render a response to a stream. The stream also exposes a ByteBuffer API for efficient transactions to JDisc. The returned future will throw the exception causing failure wrapped in an ExecutionException if rendering was not successful.- Parameters:
stream
- a stream API bridge to JDiscresponse
- the response to renderexecution
- the execution which created this responserequest
- the request matching the response- Returns:
- a ListenableFuture containing a boolean where true indicates a successful rendering
-
getEncoding
public abstract java.lang.String getEncoding()
Name of the output encoding, if applicable.TODO: ensure null is OK
- Returns:
- The encoding of the output if applicable, e.g. "utf-8"
-
getMimeType
public abstract java.lang.String getMimeType()
The MIME type of the rendered content sent to the client.- Returns:
- The mime type of the data written to the writer, e.g. "text/plain"
-
-