Class Renderer<RESPONSE extends Response>

  • All Implemented Interfaces:
    com.yahoo.component.Component, com.yahoo.component.Deconstructable, Cloneable, Comparable<com.yahoo.component.Component>
    Direct Known Subclasses:
    AsynchronousRenderer

    public abstract class Renderer<RESPONSE extends Response>
    extends com.yahoo.component.AbstractComponent
    implements Cloneable
    Renders a response to a stream. The renderers are cloned just before rendering, and must therefore obey the following contract:
    1. At construction time, only final members shall be initialized, and these must refer to immutable data only.
    2. State mutated during rendering shall be initialized in the init method.
    Author:
    Tony Vaagenes, Steinar Knutsen
    • Constructor Detail

      • Renderer

        public Renderer()
    • Method Detail

      • clone

        public Renderer<RESPONSE> clone()
        Used to create a separate instance for each result to render.
        Overrides:
        clone in class com.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.
      • renderResponse

        public CompletableFuture<Boolean> renderResponse​(OutputStream stream,
                                                         RESPONSE response,
                                                         Execution execution,
                                                         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 JDisc
        response - the response to render
        execution - the execution which created this response
        request - the request matching the response
        Returns:
        a CompletableFuture containing a boolean where true indicates a successful rendering
      • getEncoding

        public abstract String getEncoding()
        Name of the output encoding, if applicable.
        Returns:
        the encoding of the output if applicable, e.g. "utf-8"
      • getMimeType

        public abstract 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"