public class FoldFlowProcessor extends RendezvousProcessor {
@Override
public void emitRendezvous(Context context) {
ModelFactory f = context.getModelFactory();
OperatorDescription desc = context.getOperatorDescription();
FlowElementPortDescription input = context.getInputPort(Fold.ID_INPUT);
FlowElementPortDescription output = context.getOutputPort(Fold.ID_OUTPUT);
Expression init = context.createField(boolean.class, "initialized");
context.addBegin(new ExpressionBuilder(f, init)
.assignFrom(Models.toLiteral(f, false))
.toStatement());
DataObjectMirror cache = context.createModelCache(output.getDataType());
Expression impl = context.createImplementation();
Expression proc = context.getProcessInput(input);
List<Expression> arguments = Lists.create();
arguments.add(cache.get());
arguments.add(proc);
for (OperatorDescription.Parameter param : desc.getParameters()) {
arguments.add(Models.toLiteral(f, param.getValue()));
}
context.addProcess(input, f.newIfStatement(
init,
f.newBlock(new ExpressionBuilder(f, impl)
.method(desc.getDeclaration().getName(), arguments)
.toStatement()),
f.newBlock(
cache.createSet(proc),
new ExpressionBuilder(f, init)
.assignFrom(Models.toLiteral(f, true))