Examples of FlowElement


Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        Map<FlowElementInput, FlowElementInput> unifiedInputs = Maps.create();
        Map<FlowElementOutput, FlowElementOutput> unifiedOutputs = Maps.create();

        // find originals
        for (Map.Entry<FlowElement, FlowElement> entry : elementMapping.entrySet()) {
            FlowElement orig = entry.getKey();
            FlowElement dest = entry.getValue();
            assert orig.getIdentity().equals(orig.getIdentity());
            FlowElement unified;
            if (unifier.containsKey(orig.getIdentity()) == false) {
                unified = dest;
                unifier.put(orig.getIdentity(), unified);
            else {
                unified = unifier.get(orig.getIdentity());
                LOG.debug("Unify {} -> {}", dest, unified);
            }
            unifiedElements.put(dest, unified);
            List<FlowElementInput> srcInput = orig.getInputPorts();
            List<FlowElementInput> dstInput = dest.getInputPorts();
            List<FlowElementInput> uniInput = unified.getInputPorts();
            assert srcInput.size() == uniInput.size();
            for (int i = 0, n = srcInput.size(); i < n; i++) {
                if (inputMapping.containsKey(srcInput.get(i))) {
                    inputMapping.put(srcInput.get(i), uniInput.get(i));
                    unifiedInputs.put(dstInput.get(i), uniInput.get(i));
                }
            }
            List<FlowElementOutput> srcOutput = orig.getOutputPorts();
            List<FlowElementOutput> dstOutput = dest.getOutputPorts();
            List<FlowElementOutput> uniOutput = unified.getOutputPorts();
            assert srcOutput.size() == uniOutput.size();
            for (int i = 0, n = srcOutput.size(); i < n; i++) {
                if (outputMapping.containsKey(srcOutput.get(i))) {
                    outputMapping.put(srcOutput.get(i), uniOutput.get(i));
                    unifiedOutputs.put(dstOutput.get(i), uniOutput.get(i));
                }
            }
        }

        // reconnect inputs
        for (Map.Entry<FlowElement, FlowElement> entry : elementMapping.entrySet()) {
            FlowElement elem = entry.getValue();
            FlowElement unified = unifiedElements.get(elem);
            assert unified != null;
            if (elem != unified) {
                List<FlowElementInput> srcInput = elem.getInputPorts();
                List<FlowElementInput> uniInput = unified.getInputPorts();
                assert srcInput.size() == uniInput.size();
                for (int i = 0, n = srcInput.size(); i < n; i++) {
                    FlowElementInput srcPort = srcInput.get(i);
                    FlowElementInput uniPort = uniInput.get(i);
                    for (PortConnection conn : srcPort.getConnected()) {
                        FlowElementOutput opposite = unifiedOutputs.get(conn.getUpstream());
                        assert opposite != null;
                        PortConnection.connect(opposite, uniPort);
                    }
                    srcPort.disconnectAll();
                }
            }
        }

        // reconnect outputs
        for (FlowElement elem : elementMapping.values()) {
            FlowElement unified = unifiedElements.get(elem);
            assert unified != null;
            if (elem != unified) {
                List<FlowElementOutput> srcOutput = elem.getOutputPorts();
                List<FlowElementOutput> uniOutput = unified.getOutputPorts();
                assert srcOutput.size() == uniOutput.size();
                for (int i = 0, n = srcOutput.size(); i < n; i++) {
                    FlowElementOutput srcPort = srcOutput.get(i);
                    FlowElementOutput uniPort = uniOutput.get(i);
                    for (PortConnection conn : srcPort.getConnected()) {
                        FlowElementInput opposite = unifiedInputs.get(conn.getDownstream());
                        assert opposite != null;
                        PortConnection.connect(uniPort, opposite);
                    }
                    srcPort.disconnectAll();
                }
            }
        }

        // delete unified
        for (Map.Entry<FlowElement, FlowElement> entry : elementMapping.entrySet()) {
            FlowElement elem = entry.getValue();
            FlowElement unified = unifiedElements.get(elem);
            assert unified != null;
            entry.setValue(unified);
        }

        this.elements = Sets.from(elementMapping.values());
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        Set<FlowElement> removed = Sets.create();
        LinkedList<FlowElement> work = new LinkedList<FlowElement>();
        work.addAll(elements);

        while (work.isEmpty() == false) {
            FlowElement element = work.removeFirst();

            // このセッションで削除済みのものについては処理対象としない
            if (removed.contains(element)) {
                continue;
            }
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        // 利用しない入力は削除
        Iterator<FlowBlock.Input> inputs = blockInputs.iterator();
        while (inputs.hasNext()) {
            FlowBlock.Input port = inputs.next();
            FlowElement element = port.getElementPort().getOwner();
            if (FlowGraphUtil.hasSuccessors(element) == false
                    && FlowGraphUtil.hasMandatorySideEffect(element) == false
                    && outputElements.contains(element) == false) {
                LOG.debug("Deleting unnecessary input: {} on {}", port, this);
                port.disconnect();
                inputs.remove();
                changed = true;
            } else {
                inputElements.add(element);
            }
        }

        // 利用しない出力は削除
        Iterator<FlowBlock.Output> outputs = blockOutputs.iterator();
        while (outputs.hasNext()) {
            FlowBlock.Output port = outputs.next();
            FlowElement element = port.getElementPort().getOwner();
            if (FlowGraphUtil.hasPredecessors(element) == false
                    && inputElements.contains(element) == false) {
                LOG.debug("Deleting unnecessary output: {} on {}", port, this);
                port.disconnect();
                outputs.remove();
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

    private Statement setupRendezvous(FragmentNode node, StageModel.Fragment value) {
        assert node != null;
        assert value != null;
        assert value.getInputPorts().isEmpty() == false;
        FlowElement element = value.getInputPorts().get(0).getOwner();
        Type type = importer.resolve(factory.newNamedType(value.getCompiled().getQualifiedName()));
        List<Expression> arguments = resolveArguments(node, value);
        assert rendezvous.containsKey(element);
        return new ExpressionBuilder(factory, factory.newThis())
            .field(node.getName())
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        block.detach();
        assertThat(block.getElements().size(), is(1));
        assertThat(block.getBlockInputs().size(), is(1));
        assertThat(block.getBlockOutputs().size(), is(1));

        FlowElement op = block.getElements().iterator().next();
        FlowBlock.Input input = block.getBlockInputs().get(0);
        FlowBlock.Output output = block.getBlockOutputs().get(0);

        assertThat(op, not(sameInstance(gen.get("op"))));
        assertThat(input.getElementPort(), not(sameInstance(gen.input("op"))));
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        FlowBlock.Output output = block.getBlockOutputs().get(0);

        assertThat(input.getElementPort(), not(sameInstance(gen.input("op1"))));
        assertThat(output.getElementPort(), not(sameInstance(gen.output("op2"))));

        FlowElement op1 = input.getElementPort().getOwner();
        FlowElement op2 = output.getElementPort().getOwner();

        assertThat(op1.getInputPorts().get(0).getConnected().size(), is(0));
        assertThat(op1.getOutputPorts().get(0).getConnected().size(), is(1));
        assertThat(op2.getInputPorts().get(0).getConnected().size(), is(1));
        assertThat(op2.getOutputPorts().get(0).getConnected().size(), is(0));

        assertThat(op1.getOutputPorts().get(0).getConnected(),
                is(op2.getInputPorts().get(0).getConnected()));
    }
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        FlowGraph copy = FlowGraphUtil.deepCopy(graph);

        Set<FlowElement> allComponents = FlowGraphUtil.collectFlowParts(copy);
        assertThat(allComponents.size(), is(1));
        FlowElement compElem = allComponents.iterator().next();

        FlowPartDescription copyComponent = (FlowPartDescription) compElem.getDescription();

        assertThat(
                toDescription(FlowGraphUtil.toElementGraph(copyComponent.getFlowGraph())),
                is(toDescription(FlowGraphUtil.toElementGraph(component))));
        assertThat(
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        FlowGraphUtil.insertCheckpoint(gen.output("in"));

        Set<FlowElement> succ = FlowGraphUtil.getSuccessors(gen.get("in"));
        assertThat(succ.size(), is(1));
        FlowElement elem = succ.iterator().next();
        assertThat(FlowGraphUtil.isStagePadding(elem), is(true));
        assertThat(FlowGraphUtil.getSuccessors(elem),
            is(gen.getAsSet("out")));
    }
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        FlowGraphUtil.insertCheckpoint(gen.output("in"));

        Set<FlowElement> succ = FlowGraphUtil.getSuccessors(gen.get("in"));
        assertThat(succ.size(), is(1));
        FlowElement elem = succ.iterator().next();
        assertThat(FlowGraphUtil.isStagePadding(elem), is(true));
        assertThat(FlowGraphUtil.getSuccessors(elem),
            is(gen.getAsSet("out1", "out2", "out3")));
    }
View Full Code Here

Examples of com.asakusafw.vocabulary.flow.graph.FlowElement

        FlowGraphUtil.insertIdentity(gen.output("in"));

        Set<FlowElement> succ = FlowGraphUtil.getSuccessors(gen.get("in"));
        assertThat(succ.size(), is(1));
        FlowElement elem = succ.iterator().next();
        assertThat(FlowGraphUtil.isIdentity(elem), is(true));
        assertThat(FlowGraphUtil.getSuccessors(elem),
            is(gen.getAsSet("out")));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.