Class StreamingTranslator.StreamOutput<O>
- java.lang.Object
-
- ai.djl.inference.streaming.StreamingTranslator.StreamOutput<O>
-
- Type Parameters:
O- the output type
- Enclosing interface:
- StreamingTranslator<I,O>
public abstract static class StreamingTranslator.StreamOutput<O> extends java.lang.ObjectAStreamingTranslator.StreamOutputrepresents a streamable output type (either iterative or asynchronous).There are two modes for the
StreamingTranslator.StreamOutput. When using it, you must choose one of the modes and can only access it once. Any other usage including trying both modes or trying one mode twice will result in anIllegalStateException.The first mode is the iterative mode which can be used by calling
getIterativeOutput(), it returns a result that has an internal iterate method. When calling the iterating method, it will compute an additional part of the output.The second mode is asynchronous mode. Here, you can produce a mutable output object by calling
getAsyncOutput(). Then, callingcomputeAsyncOutput()will synchronously compute the results and deposit them into the prepared output. This method works best with manual threading where the worker can return the template result to another thread and then continue to compute it.
-
-
Constructor Summary
Constructors Constructor Description StreamOutput()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ObuildAsyncOutput()Performs the internal implementation ofgetAsyncOutput().voidcomputeAsyncOutput()Computes the actual value and stores it in the object returned earlier bygetAsyncOutput().protected abstract voidcomputeAsyncOutputInternal(O output)Performs the internal implementation ofcomputeAsyncOutput().OgetAsyncOutput()Returns a template object to be used with the async output.OgetIterativeOutput()Returns an iterative streamable output.abstract OgetIterativeOutputInternal()Performs the internal implementation ofgetIterativeOutput().
-
-
-
Method Detail
-
getAsyncOutput
public final O getAsyncOutput()
Returns a template object to be used with the async output.This should only be an empty data structure until
computeAsyncOutput()is called.- Returns:
- a template object to be used with the async output
-
buildAsyncOutput
protected abstract O buildAsyncOutput()
Performs the internal implementation ofgetAsyncOutput().- Returns:
- the output for
getAsyncOutput().
-
computeAsyncOutput
public final void computeAsyncOutput()
Computes the actual value and stores it in the object returned earlier bygetAsyncOutput().
-
computeAsyncOutputInternal
protected abstract void computeAsyncOutputInternal(O output)
Performs the internal implementation ofcomputeAsyncOutput().- Parameters:
output- the output object returned by the earlier call togetAsyncOutput().
-
getIterativeOutput
public final O getIterativeOutput()
Returns an iterative streamable output.- Returns:
- an iterative streamable output
-
getIterativeOutputInternal
public abstract O getIterativeOutputInternal()
Performs the internal implementation ofgetIterativeOutput().- Returns:
- the output for
getIterativeOutput()
-
-