@Override public void setDestination(final Connectable newDestination) { final Connectable previousDestination = destination.get(); if (previousDestination.equals(newDestination)) { return; } if (previousDestination.isRunning() && !(previousDestination instanceof Funnel || previousDestination instanceof LocalPort)) { throw new IllegalStateException("Cannot change destination of Connection because the current destination is running"); } if (getFlowFileQueue().isUnacknowledgedFlowFile()) { throw new IllegalStateException("Cannot change destination of Connection because FlowFiles from this Connection are currently held by " + previousDestination); } if (newDestination instanceof Funnel && newDestination.equals(source)) { throw new IllegalStateException("Funnels do not support self-looping connections."); } try { previousDestination.removeConnection(this); this.destination.set(newDestination); getSource().updateConnection(this); newDestination.addConnection(this); scheduler.registerEvent(newDestination); } catch (final RuntimeException e) { this.destination.set(previousDestination); throw e; } }
source.addConnection(connection); if (source != destination) { // don't call addConnection twice if it's a self-looping connection. destination.addConnection(connection);