Class Renderer<RESPONSE extends Response>

java.lang.Object
com.yahoo.component.AbstractComponent
com.yahoo.processing.rendering.Renderer<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 Details

    • Renderer

      public Renderer()
  • Method Details

    • 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.
    • render

      @Deprecated(forRemoval=true, since="7") public com.google.common.util.concurrent.ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response, Execution execution, Request request)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use/implement renderResponse(OutputStream, Response, Execution, Request) instead. Return type changed from ListenableFuture to CompletableFuture.
    • 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"