public class CoGroupFlowProcessor extends RendezvousProcessor {
@Override
public void emitRendezvous(Context context) {
ModelFactory f = context.getModelFactory();
OperatorDescription desc = context.getOperatorDescription();
InputBuffer bufferKind = desc.getAttribute(InputBuffer.class);
assert bufferKind != null;
List<Expression> arguments = Lists.create();
List<ListBufferMirror> buffers = Lists.create();
for (FlowElementPortDescription input : desc.getInputPorts()) {
ListBufferMirror list = context.createListBuffer(input.getDataType(), bufferKind);
buffers.add(list);
context.addBegin(list.createBegin());
Expression proc = context.getProcessInput(input);
context.addProcess(input, list.createAdvance(proc));
context.addEnd(list.createEnd());
arguments.add(list.get());
}
for (FlowElementPortDescription output : desc.getOutputPorts()) {
arguments.add(context.getOutput(output).get());
}
for (OperatorDescription.Parameter param : desc.getParameters()) {
arguments.add(Models.toLiteral(f, param.getValue()));
}
Expression impl = context.createImplementation();
context.addEnd(new ExpressionBuilder(f, impl)
.method(desc.getDeclaration().getName(), arguments)
.toStatement());
for (ListBufferMirror list : buffers) {
context.addEnd(list.createShrink());
}