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
  • Field Summary

    Fields inherited from class com.yahoo.component.AbstractComponent

    isDeconstructable
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Used to create a separate instance for each result to render.
    abstract String
    Name of the output encoding, if applicable.
    abstract String
    The MIME type of the rendered content sent to the client.
    void
    Initializes the mutable state, see the contract in the class documentation.
    renderResponse(OutputStream stream, RESPONSE response, Execution execution, Request request)
    Render a response to a stream.

    Methods inherited from class com.yahoo.component.AbstractComponent

    compareTo, deconstruct, getClassName, getId, getIdString, hasInitializedId, initId, isDeconstructable, setIsDeconstructable, toString

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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.
    • renderResponse

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