right way to add outputports to multiply operator

simon_knoll
simon_knoll New Altair Community Member
edited November 5 in Community Q&A
Hello there,
im using the multiply operator in my java application.
to add a output port i wrote a small helper method

private static void addport(String input, String output, Operator operator)
throws OperatorException {
InputPort inputPort = operator.getInputPorts().getPortByName(input);
OutputPort outputPort = operator.getOutputPorts().createPort(output);
outputPort.deliver(inputPort.getData());

}
now im asking me if im using it the right way, because i think that ive done just a workaround.

greetings
simon

Answers

  • timur
    timur New Altair Community Member
    Look into PortExtender interface and its implementing classes. For example, in your operator class you can declare port as follows

    private final OutputPortExtender outPort = new OutputPortExtender("port name", getOutputPorts());

    Every time you connect this output port, a new port would be created automatically.

    be aware though that every created port would have name of the form "port name #" where # is an index of port in order of creation.
  • simon_knoll
    simon_knoll New Altair Community Member
    thanks, i'll give a try!

    regards simon
  • fischer
    fischer New Altair Community Member
    Hi,

    In addition to what timur explained perfectly, let me say that if you use the regular multiply operator, you will not need to create a PortExtender yourself since the multiply operator already uses one. Just connect your ports one after another to getPortByIndex(numOfPorts - 1) and you will always have a new port created automatically for you.

    Cheers,
    Simon