use of org.knime.core.node.workflow.ConnectionContainer.ConnectionType in project knime-core by knime.
the class WorkflowManager method addConnection.
/**
* Add new connection - throw Exception if the same connection already exists.
*
* @param source node id
* @param sourcePort port index at source node
* @param dest destination node id
* @param destPort port index at destination node
* @param currentlyLoadingFlow True if the flow is currently loading its content, it will then skip the
* configuration of the destination node and allow node insertion in case the dest node is currently
* (remotely!) executing.
* @return newly created Connection object
* @throws IllegalArgumentException if connection already exists
*/
private ConnectionContainer addConnection(final NodeID source, final int sourcePort, final NodeID dest, final int destPort, final boolean currentlyLoadingFlow) {
assert source != null;
assert dest != null;
assert sourcePort >= 0;
assert destPort >= 0;
ConnectionContainer newConn = null;
ConnectionType newConnType = null;
NodeContainer sourceNC;
NodeContainer destNC;
try (WorkflowLock lock = lock()) {
if (!canAddConnection(source, sourcePort, dest, destPort, true, currentlyLoadingFlow)) {
throw new IllegalArgumentException("Cannot add connection!");
}
// check for existence of a connection to the destNode/Port
Set<ConnectionContainer> scc = m_workflow.getConnectionsByDest(dest);
ConnectionContainer removeCCfirst = null;
for (ConnectionContainer cc : scc) {
if (cc.getDestPort() == destPort) {
removeCCfirst = cc;
}
}
if (removeCCfirst != null) {
removeConnection(removeCCfirst);
}
// cleaned up - now add new connection
sourceNC = m_workflow.getNode(source);
destNC = m_workflow.getNode(dest);
boolean isFlowVariablePortConnection = false;
// determine type of new connection:
if ((sourceNC == null) && (destNC == null)) {
newConnType = ConnectionType.WFMTHROUGH;
} else if (sourceNC == null) {
newConnType = ConnectionType.WFMIN;
isFlowVariablePortConnection = destNC.getInPort(destPort).getPortType().equals(FlowVariablePortObject.TYPE);
} else if (destNC == null) {
newConnType = ConnectionType.WFMOUT;
isFlowVariablePortConnection = sourceNC.getOutPort(sourcePort).getPortType().equals(FlowVariablePortObject.TYPE);
} else {
newConnType = ConnectionType.STD;
isFlowVariablePortConnection = sourceNC.getOutPort(sourcePort).getPortType().equals(FlowVariablePortObject.TYPE);
}
// create new connection
newConn = new ConnectionContainer(source, sourcePort, dest, destPort, newConnType, isFlowVariablePortConnection);
addConnection(newConn);
if (!currentlyLoadingFlow) {
// user adds connection -> configure
if (newConn.getType().isLeavingWorkflow()) {
assert !m_workflow.containsNodeKey(dest);
// if the destination was the WFM itself, only configure its
// successors one layer up!
getParent().configureNodeAndSuccessors(dest, false);
lock.queueCheckForNodeStateChangeNotification(true);
} else if (destNC instanceof WorkflowManager) {
// connection enters a metanode
// (can't have optional ins -- no reset required)
WorkflowManager destWFM = (WorkflowManager) destNC;
destWFM.configureNodesConnectedToPortInWFM(Collections.singleton(destPort));
Set<Integer> outPorts = destWFM.getWorkflow().connectedOutPorts(destPort);
configureNodeAndPortSuccessors(dest, outPorts, /* do not configure dest itself */
false, true, true);
} else {
assert m_workflow.containsNodeKey(dest);
// ...make sure the destination node is configured again (and
// all of its successors if needed)
// (reset required if optional input is connected)
resetAndConfigureNode(dest);
}
}
}
// and finally notify listeners
notifyWorkflowListeners(new WorkflowEvent(WorkflowEvent.Type.CONNECTION_ADDED, null, null, newConn));
LOGGER.debug("Added new connection from node " + source + "(" + sourcePort + ")" + " to node " + dest + "(" + destPort + ")");
return newConn;
}
use of org.knime.core.node.workflow.ConnectionContainer.ConnectionType in project knime-core by knime.
the class WorkflowManager method addConnection.
/**
* Implementation of {@link #addConnection(NodeID, int, NodeID, int, boolean)} -- assumes that all validation
* is done and there is no other old connection to replace. Does not fire events or propagates reset or anything.
* @param newConn new connection to set.
*/
private void addConnection(final ConnectionContainer newConn) {
assert isLockedByCurrentThread();
NodeID source = newConn.getSource();
NodeContainer sourceNC = m_workflow.getNode(source);
int sourcePort = newConn.getSourcePort();
NodeID dest = newConn.getDest();
NodeContainer destNC = m_workflow.getNode(dest);
int destPort = newConn.getDestPort();
ConnectionType newConnType = newConn.getType();
m_workflow.addConnection(newConn);
// crossing connections:
if ((source.equals(getID())) && (dest.equals(getID()))) {
// connection goes directly from workflow in to workflow outport
assert newConnType == ConnectionType.WFMTHROUGH;
getOutPort(destPort).setUnderlyingPort(getWorkflowIncomingPort(sourcePort));
} else if ((!dest.equals(getID())) && (destNC instanceof WorkflowManager)) {
// we are feeding data into a subworkflow
WorkflowInPort wfmIPort = ((WorkflowManager) destNC).getInPort(destPort);
NodeOutPort underlyingPort;
if (sourceNC != null) {
underlyingPort = sourceNC.getOutPort(sourcePort);
} else {
assert source.equals(getID());
underlyingPort = getWorkflowIncomingPort(sourcePort);
}
wfmIPort.setUnderlyingPort(underlyingPort);
} else if (dest.equals(getID())) {
// we are feeding data out of the subworkflow
assert newConnType == ConnectionType.WFMOUT;
if (sourceNC != null) {
getOutPort(destPort).setUnderlyingPort(sourceNC.getOutPort(sourcePort));
}
}
}
use of org.knime.core.node.workflow.ConnectionContainer.ConnectionType in project knime-core by knime.
the class WorkflowManager method addConnectionsFromTemplates.
/**
* @param connections
* @param loadResult
* @param translationMap
*/
private void addConnectionsFromTemplates(final Set<ConnectionContainerTemplate> connections, final LoadResult loadResult, final Map<Integer, NodeID> translationMap, final boolean currentlyLoadingFlow) {
for (ConnectionContainerTemplate c : connections) {
int sourceSuffix = c.getSourceSuffix();
int destSuffix = c.getDestSuffix();
assert sourceSuffix == -1 || sourceSuffix != destSuffix : "Can't insert connection, source and destination are equal";
ConnectionType type = ConnectionType.STD;
NodeID source;
NodeID dest;
if ((sourceSuffix == -1) && (destSuffix == -1)) {
source = getID();
dest = getID();
type = ConnectionType.WFMTHROUGH;
} else if (sourceSuffix == -1) {
source = getID();
dest = translationMap.get(destSuffix);
type = ConnectionType.WFMIN;
} else if (destSuffix == -1) {
dest = getID();
source = translationMap.get(sourceSuffix);
type = ConnectionType.WFMOUT;
} else {
dest = translationMap.get(destSuffix);
source = translationMap.get(sourceSuffix);
}
if (!canAddConnection(source, c.getSourcePort(), dest, c.getDestPort(), true, currentlyLoadingFlow)) {
String warn = "Unable to insert connection \"" + c + "\"";
LOGGER.warn(warn);
loadResult.addError(warn);
continue;
}
ConnectionContainer cc = addConnection(source, c.getSourcePort(), dest, c.getDestPort(), currentlyLoadingFlow);
cc.setUIInfo(c.getUiInfo());
cc.setDeletable(c.isDeletable());
assert cc.getType().equals(type);
}
}
Aggregations