/** * Set up a consumer {@link ExecutionTask} for this instance. * * @param consumer the new consumer * @param inputIndex the input index for this instance into the consumer */ public void addConsumer(ExecutionTask consumer, int inputIndex) { if (!this.consumers.contains(consumer)) { assert this.isReusable() || this.consumers.isEmpty() : String.format("Cannot add %s as consumer of non-reusable %s, there is already %s.", consumer, this, this.consumers); this.consumers.add(consumer); consumer.setInputChannel(inputIndex, this); } }
/** * Exchanges input {@link Channel}. Will also update the {@link Channel}'s consumers appropriately. */ public void exchangeInputChannel(Channel currentChannel, Channel newChannel) { for (int inputIndex = 0; inputIndex < this.getNumInputChannels(); inputIndex++) { if (this.getInputChannel(inputIndex) == currentChannel) { currentChannel.getConsumers().remove(this); this.setInputChannel(inputIndex, null); newChannel.addConsumer(this, inputIndex); return; } } throw new IllegalArgumentException(String.format("%s is not an input of %s.", currentChannel, this)); }