Options

right way to add outputports to multiply operator

simon_knollsimon_knoll Member Posts: 40 Contributor II
edited November 2018 in Help
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
Tagged:

Answers

  • Options
    timurtimur Member Posts: 4 Contributor I
    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.
  • Options
    simon_knollsimon_knoll Member Posts: 40 Contributor II
    thanks, i'll give a try!

    regards simon
  • Options
    fischerfischer Member Posts: 439 Maven
    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
Sign In or Register to comment.