mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
parent
dbf241285e
commit
e0a125f3b9
3 changed files with 25 additions and 4 deletions
|
@ -0,0 +1,21 @@
|
|||
package org.logstash.config.ir.compiler;
|
||||
|
||||
/**
|
||||
* Provides common behavior for Dataset classes generated by Java execution.
|
||||
*/
|
||||
public abstract class BaseDataset implements Dataset {
|
||||
private boolean done;
|
||||
|
||||
protected void setDone() {
|
||||
done = true;
|
||||
}
|
||||
|
||||
protected void clearDone() {
|
||||
done = false;
|
||||
}
|
||||
|
||||
protected boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
}
|
|
@ -107,7 +107,7 @@ public final class ComputeStepSyntaxElement<T extends Dataset> {
|
|||
try {
|
||||
return REDUNDANT_SEMICOLON.matcher(new Formatter().formatSource(
|
||||
String.format(
|
||||
"package org.logstash.generated;\npublic final class %s implements %s { %s }",
|
||||
"package org.logstash.generated;\npublic final class %s extends org.logstash.config.ir.compiler.BaseDataset implements %s { %s }",
|
||||
name,
|
||||
type.getName(),
|
||||
SyntaxFactory.join(
|
||||
|
|
|
@ -258,18 +258,18 @@ public final class DatasetCompiler {
|
|||
*/
|
||||
private static DatasetCompiler.ComputeAndClear withOutputBuffering(final Closure compute,
|
||||
final Closure clear, final ValueSyntaxElement outputBuffer, final ClassFields fields) {
|
||||
final ValueSyntaxElement done = fields.add(boolean.class);
|
||||
final SyntaxFactory.MethodCallReturnValue done = new SyntaxFactory.MethodCallReturnValue(SyntaxFactory.value("this"), "isDone");
|
||||
return computeAndClear(
|
||||
Closure.wrap(
|
||||
SyntaxFactory.ifCondition(done, Closure.wrap(SyntaxFactory.ret(outputBuffer)))
|
||||
).add(compute)
|
||||
.add(SyntaxFactory.assignment(done, SyntaxFactory.identifier("true")))
|
||||
.add(new SyntaxFactory.MethodCallReturnValue(SyntaxFactory.value("this"), "setDone"))
|
||||
.add(SyntaxFactory.ret(outputBuffer)),
|
||||
Closure.wrap(
|
||||
SyntaxFactory.ifCondition(
|
||||
done, Closure.wrap(
|
||||
clear.add(clear(outputBuffer)),
|
||||
SyntaxFactory.assignment(done, SyntaxFactory.identifier("false"))
|
||||
new SyntaxFactory.MethodCallReturnValue(SyntaxFactory.value("this"), "clearDone")
|
||||
)
|
||||
)
|
||||
), fields
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue