Class ThrottledTemplateProcessor
- java.lang.Object
-
- org.thymeleaf.engine.ThrottledTemplateProcessor
-
- All Implemented Interfaces:
IThrottledTemplateProcessor
public final class ThrottledTemplateProcessor extends java.lang.Object implements IThrottledTemplateProcessor
Standard implementation of
IThrottledTemplateProcessor.This class is for internal use only. There is usually no reason why user's code should directly reference it.
- Since:
- 3.0.0
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallProcessingFinishedprivate IEngineContextcontextprivate booleaneventProcessingFinishedprivate TemplateFlowControllerflowControllerprivate java.lang.Stringidentifierprivate static java.util.concurrent.atomic.AtomicLongidentifierGeneratorprivate static org.slf4j.Loggerloggerprivate static intNANOS_IN_SECONDprivate intoffsetprivate static java.lang.StringOUTPUT_TYPE_BYTESprivate static java.lang.StringOUTPUT_TYPE_CHARSprivate ProcessorTemplateHandlerprocessorTemplateHandlerprivate ITemplateHandlertemplateHandlerprivate TemplateModeltemplateModelprivate TemplateSpectemplateSpecprivate static org.slf4j.LoggertimerLoggerprivate ThrottledTemplateWriterwriter
-
Constructor Summary
Constructors Constructor Description ThrottledTemplateProcessor(TemplateSpec templateSpec, IEngineContext context, TemplateModel templateModel, ITemplateHandler templateHandler, ProcessorTemplateHandler processorTemplateHandler, TemplateFlowController flowController, ThrottledTemplateWriter writer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancomputeFinish()java.lang.StringgetProcessorIdentifier()Returns an identifier for this processor that should enable the tracing of its executions.TemplateSpecgetTemplateSpec()Return theTemplateSpecthis throttled template processor object is acting on.IThrottledTemplateWriterControlgetThrottledTemplateWriterControl()booleanisFinished()Checks whether the processing of the template has already finished.intprocess(int maxOutputInBytes, java.io.OutputStream outputStream, java.nio.charset.Charset charset)Process the template until at most the specified amount of bytes has been written to output, then return control.intprocess(int maxOutputInChars, java.io.Writer writer)Process the template until at most the specified amount of chars has been written to output, then return control.private intprocess(int maxOutput, java.lang.String outputType)intprocessAll(java.io.OutputStream outputStream, java.nio.charset.Charset charset)Process the whole template (all parts remaining), with no limit in the amount of bytes written to output.intprocessAll(java.io.Writer writer)Process the whole template (all parts remaining), with no limit in the amount of chars written to output.private voidreportFinish(java.lang.String outputType)
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
timerLogger
private static final org.slf4j.Logger timerLogger
-
NANOS_IN_SECOND
private static final int NANOS_IN_SECOND
- See Also:
- Constant Field Values
-
OUTPUT_TYPE_CHARS
private static final java.lang.String OUTPUT_TYPE_CHARS
- See Also:
- Constant Field Values
-
OUTPUT_TYPE_BYTES
private static final java.lang.String OUTPUT_TYPE_BYTES
- See Also:
- Constant Field Values
-
identifierGenerator
private static final java.util.concurrent.atomic.AtomicLong identifierGenerator
-
identifier
private final java.lang.String identifier
-
templateSpec
private final TemplateSpec templateSpec
-
context
private final IEngineContext context
-
templateModel
private final TemplateModel templateModel
-
templateHandler
private final ITemplateHandler templateHandler
-
processorTemplateHandler
private final ProcessorTemplateHandler processorTemplateHandler
-
flowController
private final TemplateFlowController flowController
-
writer
private final ThrottledTemplateWriter writer
-
offset
private int offset
-
eventProcessingFinished
private boolean eventProcessingFinished
-
allProcessingFinished
private volatile boolean allProcessingFinished
-
-
Constructor Detail
-
ThrottledTemplateProcessor
ThrottledTemplateProcessor(TemplateSpec templateSpec, IEngineContext context, TemplateModel templateModel, ITemplateHandler templateHandler, ProcessorTemplateHandler processorTemplateHandler, TemplateFlowController flowController, ThrottledTemplateWriter writer)
-
-
Method Detail
-
getThrottledTemplateWriterControl
public IThrottledTemplateWriterControl getThrottledTemplateWriterControl()
-
isFinished
public boolean isFinished()
Description copied from interface:IThrottledTemplateProcessorChecks whether the processing of the template has already finished.
NOTE Implementations of this method must be thread-safe as, even if executions of the throttled processor (calls to
process(...)methods) should never happen concurrently, determining whether a throttled processor has finished or not can happen concurrently from different threads as a way of short-cutting the execution of the processor (and avoid excessive consumption of upstream data, for example).- Specified by:
isFinishedin interfaceIThrottledTemplateProcessor- Returns:
- true if the template has already been fully processed, false if not.
-
computeFinish
private boolean computeFinish() throws java.io.IOException- Throws:
java.io.IOException
-
reportFinish
private void reportFinish(java.lang.String outputType)
-
getProcessorIdentifier
public java.lang.String getProcessorIdentifier()
Description copied from interface:IThrottledTemplateProcessorReturns an identifier for this processor that should enable the tracing of its executions.
Given throttled processors are often used in reactive environments, in which different executions of a throttled processor might be performed by different threads (in a non-interleaved manner), this identifier should help identifying at the log trace the specific processor being executed independently of the thread ID.
Though it is not completely required that the identifier returned by this method is unique by construction, it should be unique enough to be of practical use as an identifier.
- Specified by:
getProcessorIdentifierin interfaceIThrottledTemplateProcessor- Returns:
- the identifier for this processor object.
-
getTemplateSpec
public TemplateSpec getTemplateSpec()
Description copied from interface:IThrottledTemplateProcessorReturn the
TemplateSpecthis throttled template processor object is acting on.- Specified by:
getTemplateSpecin interfaceIThrottledTemplateProcessor- Returns:
- the template spec.
-
processAll
public int processAll(java.io.Writer writer)
Description copied from interface:IThrottledTemplateProcessorProcess the whole template (all parts remaining), with no limit in the amount of chars written to output.
- Specified by:
processAllin interfaceIThrottledTemplateProcessor- Parameters:
writer- the writer output should be written to.- Returns:
- the amount of bytes written to output.
-
processAll
public int processAll(java.io.OutputStream outputStream, java.nio.charset.Charset charset)Description copied from interface:IThrottledTemplateProcessorProcess the whole template (all parts remaining), with no limit in the amount of bytes written to output.
- Specified by:
processAllin interfaceIThrottledTemplateProcessor- Parameters:
outputStream- the output stream output should be written to.charset- the charset to be used for encoding the written output into bytes.- Returns:
- the amount of bytes written to output.
-
process
public int process(int maxOutputInChars, java.io.Writer writer)Description copied from interface:IThrottledTemplateProcessorProcess the template until at most the specified amount of chars has been written to output, then return control.
- Specified by:
processin interfaceIThrottledTemplateProcessor- Parameters:
maxOutputInChars- the maximum amount of chars that the engine is allowed to output. A number < 0 orInteger.MAX_VALUEwill mean "no limit".writer- the writer output should be written to.- Returns:
- the amount of bytes written to output.
-
process
public int process(int maxOutputInBytes, java.io.OutputStream outputStream, java.nio.charset.Charset charset)Description copied from interface:IThrottledTemplateProcessorProcess the template until at most the specified amount of bytes has been written to output, then return control.
- Specified by:
processin interfaceIThrottledTemplateProcessor- Parameters:
maxOutputInBytes- the maximum amount of bytes that the engine is allowed to output. A number < 0 orInteger.MAX_VALUEwill mean "no limit".outputStream- the output stream output should be written to.charset- the charset to be used for encoding the written output into bytes.- Returns:
- the amount of bytes written to output.
-
process
private int process(int maxOutput, java.lang.String outputType)
-
-