Out-/In-Ports

Hey Guys,

is it possible to configure the number of ports of a node while executing the node? 

e.g.: I want to choose only one channel, so i must get only one outport. If i choose two channels, i must get two outports without creating a new node.

I believe you'd have to specify the number of ports as the maximum you want but mark them as optional. 

1 Like

Hey Eduard

The number of ports has to be specified in the constructor, so I don't belive there is a possibility to change it during the execution. The number of output-ports shouldn't matter as you don't need to use them in the following workflow. And regarding the number of input ports: As swebb pointed out you can make input-ports optional and during runtime the node can check whether these ports are used and decide on what to do.

Best,
Ferry

Hi, ferry,

I want to make sure if the situation for a fixed output port number changes. Is it possible now to set the number according to some configuration steps??

Regards
Kefang

Hi @KFDing,
you need to set the number of output ports during the construction of the node, so you can not change their number during via configuration. However you can deactivate unused ports during in the configure method, the following example snippet deactivates all output ports:

  protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {

        final PortObjectSpec[] result = new PortObjectSpec[getNrOutPorts()];
        Arrays.fill(result, InactiveBranchPortObjectSpec.INSTANCE); // deactivates port

        return result;
    }

best,
Gabriel

3 Likes