Package com.asakusafw.vocabulary.flow.graph

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


        }
        Set<FlowElement> saw = Sets.create();
        boolean modified = false;
        while (successors.isEmpty() == false) {
            FlowElementInput next = successors.removeFirst();
            FlowElement element = next.getOwner();
            if (saw.contains(element)) {
                continue;
            }
            saw.add(element);
            if (element.getDescription().getKind() == FlowElementKind.PSEUD) {
                for (FlowElementOutput output : element.getOutputPorts()) {
                    successors.addAll(output.getOpposites());
                }
                continue;
            }
            if (element.getDescription().getKind() == FlowElementKind.FLOW_COMPONENT) {
                FlowPartDescription desc = (FlowPartDescription) element.getDescription();
                FlowIn<?> internal = desc.getInternalInputPort(next.getDescription());
                modified |= rewriteSuccessors(source, internal);
                continue;
            }
            if (element.getDescription().getKind() == FlowElementKind.OPERATOR) {
                modified |= rewriteOperator(source, next);
                continue;
            }
        }
        return modified;
View Full Code Here


            }
        } else {
            for (FlowElement element : arrivals) {
                for (FlowElementInput input : element.getInputPorts()) {
                    for (PortConnection conn : input.getConnected()) {
                        FlowElement target = conn.getUpstream().getOwner();
                        if (passings.contains(target) || startings.contains(target)) {
                            results.add(conn);
                        }
                    }
                }
View Full Code Here

    }

    private boolean rewriteOperator(InputDescription source, FlowElementInput input) {
        assert source != null;
        assert input != null;
        FlowElement element = input.getOwner();
        assert element.getDescription().getKind() == FlowElementKind.OPERATOR;
        OperatorDescription desc = (OperatorDescription) element.getDescription();
        Class<? extends Annotation> annotationType = desc.getDeclaration().getAnnotationType();
        Class<? extends Annotation> sideDataType;
        FlowElementInput master;
        FlowElementInput tx;
        if (annotationType == MasterJoin.class) {
            sideDataType = SideDataJoin.class;
            master = getInput(element, MasterJoin.ID_INPUT_MASTER);
            tx = getInput(element, MasterJoin.ID_INPUT_TRANSACTION);
        } else if (annotationType == MasterBranch.class) {
            sideDataType = SideDataBranch.class;
            master = getInput(element, MasterBranch.ID_INPUT_MASTER);
            tx = getInput(element, MasterBranch.ID_INPUT_TRANSACTION);
        } else if (annotationType == MasterCheck.class) {
            sideDataType = SideDataCheck.class;
            master = getInput(element, MasterCheck.ID_INPUT_MASTER);
            tx = getInput(element, MasterCheck.ID_INPUT_TRANSACTION);
        } else if (annotationType == MasterJoinUpdate.class) {
            sideDataType = SideDataJoinUpdate.class;
            master = getInput(element, MasterJoinUpdate.ID_INPUT_MASTER);
            tx = getInput(element, MasterJoinUpdate.ID_INPUT_TRANSACTION);
        } else {
            return false;
        }
        if (master.equals(input) == false) {
            return false;
        }
        OperatorDescription.Builder builder = createSideDataOperator(desc, sideDataType);
        builder.addInput(
                tx.getDescription().getName(),
                tx.getDescription().getDataType());
        builder.addResource(createResource(source, master, tx));

        FlowElement rewrite = new FlowElement(builder.toDescription());
        for (FlowElementOutput upstream : tx.getOpposites()) {
            PortConnection.connect(upstream, rewrite.getInputPorts().get(0));
        }

        List<FlowElementOutput> originalOutputs = element.getOutputPorts();
        List<FlowElementOutput> rewriteOutputs = rewrite.getOutputPorts();
        assert originalOutputs.size() == rewriteOutputs.size();
        for (int i = 0, n = originalOutputs.size(); i < n; i++) {
            FlowElementOutput originalPort = originalOutputs.get(i);
            FlowElementOutput rewritePort = rewriteOutputs.get(i);
            for (FlowElementInput downstream : originalPort.getOpposites()) {
View Full Code Here

        work.add(in2.toElement());
        work.add(out.toElement());
        Graph<String> graph = Graphs.newInstance();

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

            String self = elem.getDescription().getName();
            if (saw.contains(self)) {
                continue;
            }
            saw.add(self);

            // 逆辺をキューに追加
            for (FlowElementInput input : elem.getInputPorts()) {
                for (PortConnection conn : input.getConnected()) {
                    work.add(conn.getUpstream().getOwner());
                }
            }

            // 順辺をグラフに追加
            for (FlowElementOutput output : elem.getOutputPorts()) {
                for (PortConnection conn : output.getConnected()) {
                    FlowElement opposite = conn.getDownstream().getOwner();
                    work.add(opposite);
                    String dest = opposite.getDescription().getName();
                    graph.addEdge(self, dest);
                }
            }
        }
View Full Code Here

            return null;
        }

        @Override
        protected Void visitElement(EmitContext context, VisualElement node) {
            FlowElement element = node.getElement();
            switch (element.getDescription().getKind()) {
            case INPUT:
            case OUTPUT:
                context.put("{0} [shape=invhouse, label={1}];",
                        toLiteral(node.getId().toString()),
                        toLiteral(element.getDescription().getName()));
                break;
            case OPERATOR:
                context.put("{0} [shape=box, label={1}];",
                        toLiteral(node.getId().toString()),
                        toLiteral(toOperatorName(node)));
                break;
            case FLOW_COMPONENT:
                context.put("{0} [shape=component, label={1}];",
                        toLiteral(node.getId().toString()),
                        toLiteral(element.getDescription().getName()));
                break;
            default:
                context.put("{0} [shape=point];",
                        toLiteral(node.getId().toString()));
                break;
View Full Code Here

            return super.visitLabel(context, node);
        }

        static String toOperatorName(VisualElement node) {
            assert node != null;
            FlowElement element = node.getElement();
            assert element.getDescription().getKind() == FlowElementKind.OPERATOR;
            OperatorDescription desc = (OperatorDescription) element.getDescription();
            StringBuilder buf = new StringBuilder();
            buf.append("@");
            buf.append(desc.getDeclaration().getAnnotationType().getSimpleName());
            buf.append("\n");
            buf.append(desc.getName());
View Full Code Here

        VisualAnalyzer analyzer = new VisualAnalyzer();
        Set<VisualNode> nodes = Sets.create();
        for (FlowBlock head : stage.getMapBlocks()) {
            for (FlowBlock.Input input : head.getBlockInputs()) {
                for (FlowBlock.Connection conn : input.getConnections()) {
                    FlowElement element = conn.getUpstream().getElementPort().getOwner();
                    VisualNode node = analyzer.convertElement(element);
                    if (node != null) {
                        nodes.add(node);
                    }
                }
            }
        }
        nodes.add(analyzer.convertStage(stage));
        Set<FlowBlock> tails = stage.hasReduceBlocks() ? stage.getReduceBlocks() : stage.getMapBlocks();
        for (FlowBlock tail : tails) {
            for (FlowBlock.Output output : tail.getBlockOutputs()) {
                for (FlowBlock.Connection conn : output.getConnections()) {
                    FlowElement element = conn.getDownstream().getElementPort().getOwner();
                    VisualNode node = analyzer.convertElement(element);
                    if (node != null) {
                        nodes.add(node);
                    }
                }
View Full Code Here

        getPlanner().insertIdentities(graph);

        assertThat(FlowGraphUtil.collectElements(graph),
                not(gen.getAsSet("in", "op1", "op2", "out")));

        FlowElement id = succ(gen.get("in"));
        assertThat(FlowGraphUtil.isIdentity(id), is(true));

        FlowElement op1 = succ(id);
        assertThat(op1, is(gen.get("op1")));

        FlowElement op2 = succ(op1);
        assertThat(op2, is(gen.get("op2")));

        FlowElement out = succ(op2);
        assertThat(out, is(gen.get("out")));
    }
View Full Code Here

        getPlanner().insertIdentities(graph);

        assertThat(FlowGraphUtil.collectElements(graph),
                not(gen.getAsSet("in", "op1", "op2", "out")));

        FlowElement id = succ(gen.get("in"));
        assertThat(FlowGraphUtil.isIdentity(id), is(true));

        FlowElement op1 = succ(id);
        assertThat(op1, is(gen.get("op1")));

        FlowElement op2 = succ(op1);
        assertThat(op2, is(gen.get("op2")));

        FlowElement out = succ(op2);
        assertThat(out, is(gen.get("out")));
    }
View Full Code Here

        assertThat(succ1.size(), is(2));
        assertThat(succ2.size(), is(2));

        Iterator<FlowElement> iter1 = succ1.iterator();
        FlowElement elem1 = iter1.next();
        FlowElement elem2 = iter1.next();
        Iterator<FlowElement> iter2 = succ2.iterator();
        FlowElement elem3 = iter2.next();
        FlowElement elem4 = iter2.next();

        assertThat(FlowGraphUtil.getSuccessors(elem1).size(), is(1));
        assertThat(FlowGraphUtil.getSuccessors(elem2).size(), is(1));
        assertThat(FlowGraphUtil.getSuccessors(elem3).size(), is(1));
        assertThat(FlowGraphUtil.getSuccessors(elem4).size(), is(1));
View Full Code Here

TOP

Related Classes of com.asakusafw.vocabulary.flow.graph.FlowElement

Copyright © 2018 www.massapicom. 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.