@Override public IterationStrategy doEdit() throws EditException { if (applied) { throw new EditException("Edit has already been applied"); } if (!(iterationStrategy instanceof IterationStrategyImpl)) { throw new EditException( "Object being edited must be instance of IterationStrategyImpl"); } ((IterationStrategyImpl) iterationStrategy).addInput(namedInputPortNode); applied = true; return iterationStrategy; }
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")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); addInput((NamedInputPortNode) node); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
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")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); addInput((NamedInputPortNode) node); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
/** * @param args */ public static void main(String[] args) { IterationStrategyImpl iterationStrategyImpl = new IterationStrategyImpl(); NamedInputPortNode fishPort = new NamedInputPortNode("fish", 2); NamedInputPortNode otherPort = new NamedInputPortNode("other", 0); NamedInputPortNode soupPort = new NamedInputPortNode("soup", 1); iterationStrategyImpl.addInput(fishPort); iterationStrategyImpl.addInput(soupPort); iterationStrategyImpl.addInput(otherPort); iterationStrategyImpl.connectDefault(otherPort); iterationStrategyImpl.connectDefault(fishPort); iterationStrategyImpl.connectDefault(soupPort); IterationStrategyEditorControl editorControl = new IterationStrategyEditorControl(iterationStrategyImpl); JFrame frame = new JFrame("Iteration strategy editor"); frame.add(editorControl); frame.setSize(500,400); frame.setVisible(true); }
/** * @param args */ public static void main(String[] args) { IterationStrategyImpl iterationStrategyImpl = new IterationStrategyImpl(); NamedInputPortNode fishPort = new NamedInputPortNode("fish", 2); NamedInputPortNode otherPort = new NamedInputPortNode("other", 0); NamedInputPortNode soupPort = new NamedInputPortNode("soup", 1); iterationStrategyImpl.addInput(fishPort); iterationStrategyImpl.addInput(soupPort); iterationStrategyImpl.addInput(otherPort); iterationStrategyImpl.connectDefault(otherPort); iterationStrategyImpl.connectDefault(fishPort); iterationStrategyImpl.connectDefault(soupPort); IterationStrategyEditorControl editorControl = new IterationStrategyEditorControl(iterationStrategyImpl); JFrame frame = new JFrame("List handling editor"); frame.add(editorControl); frame.setSize(500,400); frame.setVisible(true); }
@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(newPortName) != null) { throw new EditException( "Attempt to create duplicate input port with name '" + newPortName + "'"); } previousIterationStrategyState = processor.iterationStack.asXML(); processor.inputPorts.add(new ProcessorInputPortImpl(processor, newPortName, newPortDepth)); for (IterationStrategyImpl is : processor.iterationStack.getStrategies()) { NamedInputPortNode nipn = new NamedInputPortNode(newPortName, newPortDepth); is.addInput(nipn); is.connectDefault(nipn); } }
private void addIterationNode(MutableTreeNode node, IterationStrategyImpl t2IterationStrategy, IterationStrategyNode parent, Processor t2Processor) { if (node instanceof LeafNode) { String nodeName = (String) ((LeafNode) node).getUserObject(); for (InputPort ip : t2Processor.getInputPorts()) { if (ip.getName().equals(nodeName)) { NamedInputPortNode inputPortNode = new NamedInputPortNode( nodeName, ip.getDepth()); inputPortNode.setParent(parent); t2IterationStrategy.addInput(inputPortNode); break; } } } else { AbstractIterationStrategyNode strategyNode = null; if (node instanceof DotNode) { strategyNode = new DotProduct(); } else { strategyNode = new CrossProduct(); } strategyNode.setParent(parent); for (Enumeration<?> en = node.children(); en.hasMoreElements();) { addIterationNode((MutableTreeNode) en.nextElement(), t2IterationStrategy, strategyNode, t2Processor); } } }
private void addIterationNode(MutableTreeNode node, IterationStrategyImpl t2IterationStrategy, AbstractIterationStrategyNode parent, Processor t2Processor) { if (node instanceof LeafNode) { String nodeName = (String) ((LeafNode) node).getUserObject(); for (InputPort ip : t2Processor.getInputPorts()) { if (ip.getName().equals(nodeName)) { NamedInputPortNode inputPortNode = new NamedInputPortNode( nodeName, ip.getDepth()); inputPortNode.setParent(parent); t2IterationStrategy.addInput(inputPortNode); break; } } } else { AbstractIterationStrategyNode strategyNode = null; if (node instanceof DotNode) { strategyNode = new DotProduct(); } else { strategyNode = new CrossProduct(); } strategyNode.setParent(parent); for (Enumeration<?> en = node.children(); en.hasMoreElements();) { addIterationNode((MutableTreeNode) en.nextElement(), t2IterationStrategy, strategyNode, t2Processor); } } }
@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() + "'"); } previousIterationStrategyState = processor.iterationStack.asXML(); processor.inputPorts.add(port); for (IterationStrategyImpl is : processor.iterationStack.getStrategies()) { NamedInputPortNode nipn = new NamedInputPortNode(port.getName(), port.getDepth()); is.addInput(nipn); is.connectDefault(nipn); } }
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.getTerminal()); return is1; }
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.getTerminal()); return is1; }
@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() + "'"); } previousIterationStrategyState = processor.iterationStack.asXML(); processor.inputPorts.add(port); for (IterationStrategyImpl is : processor.iterationStack.getStrategies()) { NamedInputPortNode nipn = new NamedInputPortNode(port.getName(), port.getDepth()); is.addInput(nipn); is.connectDefault(nipn); } }
NamedInputPortNode nipn1 = new NamedInputPortNode("a", 1); NamedInputPortNode nipn2 = new NamedInputPortNode("b", 1); is1.addInput(nipn1); is1.addInput(nipn2); DotProduct dp = new DotProduct(); nipn1.setParent(dp); NamedInputPortNode nipn3 = new NamedInputPortNode("a", 0); NamedInputPortNode nipn4 = new NamedInputPortNode("b", 0); is2.addInput(nipn3); is2.addInput(nipn4); CrossProduct cp = new CrossProduct(); nipn3.setParent(cp);
public void testMutipleData() throws MalformedIdentifierException { NamedInputPortNode nipn1 = new NamedInputPortNode("a", 0); NamedInputPortNode nipn2 = new NamedInputPortNode("b", 0); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); dp.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn1); is.addInput(nipn2); String owningProcess = "Process1"; for (int i = 0; i < 4; i++) { EntityListIdentifier dataReference = new EntityListIdentifier("urn:t2data:list://foo.bar/alist"+i+"/1"); is.receiveData("a", owningProcess, new int[]{i}, dataReference, context); } is.receiveCompletion("a", owningProcess, new int[]{}, context); for (int i = 0; i < 4; i++) { EntityListIdentifier dataReference = new EntityListIdentifier("urn:t2data:list://foo.bar/blist"+i+"/1"); is.receiveData("b", owningProcess, new int[]{i}, dataReference, context); } is.receiveCompletion("b", owningProcess, new int[]{}, context); assertTrue(disn.jobsReceived("Process1")==4); System.out.println(disn); }
public void testBasic() { NamedInputPortNode nipn = new NamedInputPortNode("Input", 0); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); nipn.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn); try { is.receiveData("Input", "Process1", new int[]{}, nextID(), context); } catch (WorkflowStructureException e) { fail("Should be able to find input named 'Input' in this test case"); } assertTrue(disn.jobsReceived("Process1") == 1); }
public void testBasic() { NamedInputPortNode nipn1 = new NamedInputPortNode("Input1", 0); NamedInputPortNode nipn2 = new NamedInputPortNode("Input2", 0); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); dp.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn1); is.addInput(nipn2); try { is.receiveData("Input1", "Process1", new int[] {0}, nextID(), context); is.receiveCompletion("Input1", "Process1", new int[]{}, context); assertTrue(disn.jobsReceived("Process1") == 0); is.receiveData("Input2", "Process1", new int[] {0}, nextID(), context); is.receiveCompletion("Input2", "Process1", new int[]{}, context); assertTrue(disn.jobsReceived("Process1") == 1); System.out.println(disn); } catch (WorkflowStructureException e) { fail("Unknown structure exception"); } }
public void testMultipleProcess() { NamedInputPortNode nipn1 = new NamedInputPortNode("Input1", 0); NamedInputPortNode nipn2 = new NamedInputPortNode("Input2", 0); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); dp.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn1); is.addInput(nipn2); try { is.receiveData("Input1", "Process1", new int[] {}, nextID(), context); assertTrue(disn.jobsReceived("Process1") == 0); is.receiveCompletion("Input1", "Process1", new int[]{}, context); is.receiveData("Input2", "Process2", new int[] {}, nextID(), context); assertTrue(disn.jobsReceived("Process1") == 0); is.receiveData("Input2", "Process1", new int[] {}, nextID(), context); assertTrue(disn.jobsReceived("Process1") == 1); is.receiveCompletion("Input2", "Process1", new int[]{}, context); System.out.println(disn); } catch (WorkflowStructureException e) { fail("Unknown structure exception"); } }
public void testMultipleProcesses() { NamedInputPortNode nipn = new NamedInputPortNode("Input", 0); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); nipn.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn); try { is.receiveData("Input", "Process1", new int[]{0}, nextID(), context); is.receiveData("Input", "Process1", new int[]{1}, nextID(), context); is.receiveData("Input", "Process2", new int[]{}, nextID(), context); } catch (WorkflowStructureException e) { fail("Should be able to find input named 'Input' in this test case"); } assertTrue(disn.jobsReceived("Process1") == 2); assertTrue(disn.jobsReceived("Process2") == 1); }