Class Renderer<RESPONSE extends com.yahoo.processing.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:
    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
      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.
      • 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 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.
      • 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 JDisc
        response - the response to render
        execution - the execution which created this response
        request - 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"