@Override public String toString() { return getClass().getSimpleName() + " " + getPortName() + "(" + getCardinality() + ")"; } }
/** * Completion events are passed straight through the same as jobs */ @Override public void receiveCompletion(int inputIndex, Completion completion) { pushCompletion(completion); }
/** * If this node receives a job it will always be pushed without modification * up to the parent */ @Override public void receiveJob(int inputIndex, Job newJob) { pushJob(newJob); }
public void removeInputByName(String name) { synchronized (inputs) { NamedInputPortNode removeMe = null; for (NamedInputPortNode nipn : inputs) if (nipn.getPortName().equals(name)) removeMe = nipn; if (removeMe != null) { inputs.remove(removeMe); removeMe.removeFromParent(); } } }
private IterationStrategyImpl getISDot(int depthA, int depthB) { IterationStrategyImpl is1 = new IterationStrategyImpl(); NamedInputPortNode nipn1 = new NamedInputPortNode("a", depthA); NamedInputPortNode nipn2 = new NamedInputPortNode("b", depthB); is1.addInput(nipn1); is1.addInput(nipn2); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); dp.setParent(is1.getTerminalNode()); return is1; }
private AbstractIterationStrategyNode nodeForElement(Element e) { AbstractIterationStrategyNode node = null; String eName = e.getName(); if (eName.equals("dot")) node = new DotProduct(); else if (eName.equals("cross")) node = new CrossProduct(); else if (eName.equals("prefix")) node = new PrefixDotProduct(); else if (eName.equals("port")) { NamedInputPortNode nipn = new NamedInputPortNode( e.getAttributeValue("name"), Integer.parseInt(e .getAttributeValue("depth"))); node = nipn; addInput(nipn); } for (Object child : e.getChildren()) nodeForElement((Element) child).setParent(node); return node; }
private NamedInputPortNode nodeForName(String portName) throws WorkflowStructureException { for (NamedInputPortNode node : inputs) if (node.getPortName().equals(portName)) return node; throw new WorkflowStructureException("No port found with name '" + portName + "'"); }
/** * Connect up a new named input port node to the first child of the terminal * node. If the terminal node doesn't have any children then create a new * cross product node, connect it to the terminal and connect the new input * port node to the cross product (saneish default behaviour) * * @param nipn */ public synchronized void connectDefault(NamedInputPortNode nipn) { if (terminal.getChildCount() == 0) { CrossProduct cp = new CrossProduct(); cp.setParent(terminal); nipn.setParent(cp); } else nipn.setParent((AbstractIterationStrategyNode) terminal .getChildAt(0)); }
ReferenceService rs = e.getContext().getReferenceService(); NamedInputPortNode ipn = nodeForName(portName); int desiredDepth = ipn.getCardinality(); Iterator<ContextualizedT2Reference> ids = rs.traverseFrom( dataRef, desiredDepth);
public void receiveCompletion(String inputPortName, String owningProcess, int[] completionArray, InvocationContext context) throws WorkflowStructureException { nodeForName(inputPortName).receiveCompletion(0, new Completion(owningProcess, completionArray, context)); }
@Test(expected = IllegalStateException.class) public void cantAddToNamedInput() throws Exception { input1.insert(dotProduct1); }
@Test public void addSingleChildToTerminal() throws Exception { assertNull(input1.getParent()); assertEquals(0, root.getChildCount()); root.insert(input1); assertEquals(root, input1.getParent()); assertEquals(1, root.getChildCount()); assertEquals(input1, root.getChildAt(0)); assertEquals(Arrays.asList(input1), root.getChildren()); root.insert(input1); assertEquals(1, root.getChildCount()); root.insert(input1, 0); assertEquals(1, root.getChildCount()); }
private IterationStrategyImpl getISCross(int depthA, int depthB) { IterationStrategyImpl is1 = new IterationStrategyImpl(); NamedInputPortNode nipn1 = new NamedInputPortNode("a", depthA); NamedInputPortNode nipn2 = new NamedInputPortNode("b", depthB); is1.addInput(nipn1); is1.addInput(nipn2); CrossProduct cp = new CrossProduct(); nipn1.setParent(cp); nipn2.setParent(cp); cp.setParent(is1.getTerminalNode()); return is1; }
@Before public void makeNodes() throws Exception { root = new DummyTerminalNode(); input1 = new NamedInputPortNode("input1", 1); input2 = new NamedInputPortNode("input2", 2); crossProduct1 = new CrossProduct(); crossProduct2 = new CrossProduct(); dotProduct1 = new DotProduct(); dotProduct2 = new DotProduct(); }
@Override public Map<String, Integer> getDesiredCardinalities() { Map<String, Integer> result = new HashMap<>(); for (NamedInputPortNode nipn : inputs) result.put(nipn.getPortName(), nipn.getCardinality()); return result; }
@Override protected void doEditAction(ProcessorImpl processor) throws EditException { /* * Add a new InputPort object to the processor and also create * an appropriate NamedInputPortNode in any iteration * strategies. By default set the desired drill depth on each * iteration strategy node to the same as the input port, so * this won't automatically trigger iteration staging unless the * depth is altered on the iteration strategy itself.) */ if (processor.getInputPortWithName(port.getName()) != null) throw new EditException( "Attempt to create duplicate input port with name '" + port.getName() + "'"); processor.inputPorts.add((ProcessorInputPortImpl) port); for (IterationStrategyImpl is : processor.iterationStack .getStrategies()) { NamedInputPortNode nipn = new NamedInputPortNode( port.getName(), port.getDepth()); is.addInput(nipn); is.connectDefault(nipn); } } };