org.apache.edgent.graph.Vertex类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中org.apache.edgent.graph.Vertex类的一些代码示例,展示了Vertex类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex类的具体详情如下:
包路径:org.apache.edgent.graph.Vertex
类名称:Vertex

Vertex介绍

[英]A Vertex in a graph.

A Vertex has an Oplet instance that will be executed at runtime and zero or more input ports and zero or more output ports. Each output port is represented by a Connector instance.
[中]

代码示例

代码示例来源:origin: org.apache.edgent/edgent-spi-graph

  1. @Override
  2. public <N extends Source<P>, P> Connector<P> source(N oplet) {
  3. return insert(oplet, 0, 1).getConnectors().get(0);
  4. }

代码示例来源:origin: apache/incubator-edgent

  1. assertSame(op, v.getInstance());
  2. v.getConnectors().get(0).connect(v2, 0);

代码示例来源:origin: org.apache.edgent/edgent-runtime-etiao

  1. @SuppressWarnings({ "rawtypes", "unchecked" })
  2. public VertexType(Vertex<? extends Oplet<?, ?>, ?, ?> value, IdMapper<String> ids) {
  3. this.id = (value instanceof ExecutableVertex) ?
  4. ids.add(value, ((ExecutableVertex) value).getInvocationId()) :
  5. // Can't get an id from the vertex, generate unique value
  6. ids.add(value);
  7. this.invocation = new InvocationType(value.getInstance());
  8. }

代码示例来源:origin: apache/incubator-edgent

  1. @SuppressWarnings({ "rawtypes", "unchecked" })
  2. public VertexType(Vertex<? extends Oplet<?, ?>, ?, ?> value, IdMapper<String> ids) {
  3. this.id = (value instanceof ExecutableVertex) ?
  4. ids.add(value, ((ExecutableVertex) value).getInvocationId()) :
  5. // Can't get an id from the vertex, generate unique value
  6. ids.add(value);
  7. this.invocation = new InvocationType(value.getInstance());
  8. }

代码示例来源:origin: apache/incubator-edgent

  1. @Override
  2. public <N extends Source<P>, P> Connector<P> source(N oplet) {
  3. return insert(oplet, 0, 1).getConnectors().get(0);
  4. }

代码示例来源:origin: apache/incubator-edgent

  1. /**
  2. * Add counter metrics to all the topology's streams.
  3. * <p>
  4. * {@link CounterOp} oplets are inserted between every two graph
  5. * vertices with the following exceptions:
  6. * <ul>
  7. * <li>Oplets are only inserted upstream from a FanOut oplet.</li>
  8. * <li>If a chain of Peek oplets exists between oplets A and B, a Metric
  9. * oplet is inserted after the last Peek, right upstream from oplet B.</li>
  10. * <li>If a chain a Peek oplets is followed by a FanOut, a metric oplet is
  11. * inserted between the last Peek and the FanOut oplet.</li>
  12. * <li>Oplets are not inserted immediately downstream from another
  13. * {@code CounterOp} oplet (but they are inserted upstream from one.)</li>
  14. * </ul>
  15. * The implementation is not idempotent: Calling the method twice
  16. * will insert a new set of metric oplets into the graph.
  17. * @param t
  18. * The topology
  19. * @see org.apache.edgent.graph.Graph#peekAll(org.apache.edgent.function.Supplier, org.apache.edgent.function.Predicate) Graph.peekAll()
  20. */
  21. public static void counter(Topology t) {
  22. // peekAll() embodies the above exclusion semantics
  23. t.graph().peekAll(
  24. () -> new CounterOp<>(),
  25. v -> !(v.getInstance() instanceof CounterOp)
  26. );
  27. }
  28. }

代码示例来源:origin: org.apache.edgent/edgent-spi-graph

  1. @Override
  2. public <N extends Oplet<C, P>, C, P> Connector<P> pipe(Connector<C> output, N oplet) {
  3. Vertex<N, C, P> pipeVertex = insert(oplet, 1, 1);
  4. output.connect(pipeVertex, 0);
  5. return pipeVertex.getConnectors().get(0);
  6. }

代码示例来源:origin: apache/incubator-edgent

  1. @Test
  2. public void testMetricsEverywhere() throws Exception {
  3. Topology t = newTopology();
  4. TStream<String> s = t.strings("a", "b", "c");
  5. // Condition inserts a sink
  6. Condition<Long> tc = t.getTester().tupleCount(s, 3);
  7. Graph g = t.graph();
  8. Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
  9. // Two vertices before submission
  10. assertEquals(2, vertices.size());
  11. complete(t, tc);
  12. // At least three vertices after submission
  13. // (provide may have added other oplets as well)
  14. Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> verticesAfterSubmit = g.getVertices();
  15. assertTrue("size="+verticesAfterSubmit.size(), verticesAfterSubmit.size() >= 3);
  16. // There is exactly one vertex for a metric oplet
  17. int numOplets = 0;
  18. for (Vertex<? extends Oplet<?, ?>, ?, ?> v : verticesAfterSubmit) {
  19. Oplet<?,?> oplet = v.getInstance();
  20. if (oplet instanceof CounterOp) {
  21. numOplets++;
  22. }
  23. }
  24. assertEquals(1, numOplets);
  25. }

代码示例来源:origin: apache/incubator-edgent

  1. @Override
  2. public <N extends Oplet<C, P>, C, P> Connector<P> pipe(Connector<C> output, N oplet) {
  3. Vertex<N, C, P> pipeVertex = insert(oplet, 1, 1);
  4. output.connect(pipeVertex, 0);
  5. return pipeVertex.getConnectors().get(0);
  6. }

代码示例来源:origin: apache/incubator-edgent

  1. PeriodicSource<?> src = null;
  2. for (Vertex<? extends Oplet<?, ?>, ?, ?> v : vertices) {
  3. Oplet<?,?> op = v.getInstance();
  4. assertTrue(op instanceof PeriodicSource);
  5. src = (PeriodicSource<?>) op;

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

  1. @Override
  2. public <U> TStream<U> fanin(FanIn<T,U> fanin, List<TStream<T>> others) {
  3. if (others.isEmpty() || others.size() == 1 && others.contains(this))
  4. throw new IllegalArgumentException("others"); // use pipe()
  5. if (new HashSet<>(others).size() != others.size())
  6. throw new IllegalArgumentException("others has dups");
  7. for (TStream<T> other : others)
  8. verify(other);
  9. others = new ArrayList<>(others);
  10. others.add(0, this);
  11. Vertex<Oplet<T,U>, T, U> fanInVertex = graph().insert(fanin, others.size(), 1);
  12. int inputPort = 0;
  13. for (TStream<T> other : others) {
  14. @SuppressWarnings("unchecked")
  15. ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
  16. cs.connector.connect(fanInVertex, inputPort++);
  17. }
  18. return derived(fanInVertex.getConnectors().get(0));
  19. }

代码示例来源:origin: apache/incubator-edgent

  1. Oplet<?,?> oplet = v.getInstance();
  2. if (oplet instanceof StreamScope) {
  3. numOplets++;

代码示例来源:origin: apache/incubator-edgent

  1. @Override
  2. public <U> TStream<U> fanin(FanIn<T,U> fanin, List<TStream<T>> others) {
  3. if (others.isEmpty() || others.size() == 1 && others.contains(this))
  4. throw new IllegalArgumentException("others"); // use pipe()
  5. if (new HashSet<>(others).size() != others.size())
  6. throw new IllegalArgumentException("others has dups");
  7. for (TStream<T> other : others)
  8. verify(other);
  9. others = new ArrayList<>(others);
  10. others.add(0, this);
  11. Vertex<Oplet<T,U>, T, U> fanInVertex = graph().insert(fanin, others.size(), 1);
  12. int inputPort = 0;
  13. for (TStream<T> other : others) {
  14. @SuppressWarnings("unchecked")
  15. ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
  16. cs.connector.connect(fanInVertex, inputPort++);
  17. }
  18. return derived(fanInVertex.getConnectors().get(0));
  19. }

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

  1. @Override
  2. public List<TStream<T>> split(int n, ToIntFunction<T> splitter) {
  3. if (n <= 0)
  4. throw new IllegalArgumentException("n <= 0");
  5. Split<T> splitOp = new Split<T>(splitter);
  6. Vertex<Split<T>, T, T> splitVertex = graph().insert(splitOp, 1, n);
  7. connector.connect(splitVertex, 0);
  8. List<TStream<T>> outputs = new ArrayList<>(n);
  9. for (int i = 0; i < n; i++) {
  10. outputs.add(derived(splitVertex.getConnectors().get(i)));
  11. }
  12. return outputs;
  13. }

代码示例来源:origin: apache/incubator-edgent

  1. @Override
  2. public List<TStream<T>> split(int n, ToIntFunction<T> splitter) {
  3. if (n <= 0)
  4. throw new IllegalArgumentException("n <= 0");
  5. Split<T> splitOp = new Split<T>(splitter);
  6. Vertex<Split<T>, T, T> splitVertex = graph().insert(splitOp, 1, n);
  7. connector.connect(splitVertex, 0);
  8. List<TStream<T>> outputs = new ArrayList<>(n);
  9. for (int i = 0; i < n; i++) {
  10. outputs.add(derived(splitVertex.getConnectors().get(i)));
  11. }
  12. return outputs;
  13. }

代码示例来源:origin: apache/incubator-edgent

  1. @Override
  2. public TStream<T> union(Set<TStream<T>> others) {
  3. if (others.isEmpty())
  4. return this;
  5. if (others.size() == 1 && others.contains(this))
  6. return this;
  7. for (TStream<T> other : others)
  8. verify(other);
  9. // Create a set we can modify and add this stream
  10. others = new HashSet<>(others);
  11. others.add(this);
  12. Union<T> fanInOp = new Union<T>();
  13. Vertex<Union<T>, T, T> fanInVertex = graph().insert(fanInOp, others.size(), 1);
  14. int inputPort = 0;
  15. for (TStream<T> other : others) {
  16. @SuppressWarnings("unchecked")
  17. ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
  18. cs.connector.connect(fanInVertex, inputPort++);
  19. }
  20. return derived(fanInVertex.getConnectors().get(0));
  21. }

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

  1. @Override
  2. public TStream<T> union(Set<TStream<T>> others) {
  3. if (others.isEmpty())
  4. return this;
  5. if (others.size() == 1 && others.contains(this))
  6. return this;
  7. for (TStream<T> other : others)
  8. verify(other);
  9. // Create a set we can modify and add this stream
  10. others = new HashSet<>(others);
  11. others.add(this);
  12. Union<T> fanInOp = new Union<T>();
  13. Vertex<Union<T>, T, T> fanInVertex = graph().insert(fanInOp, others.size(), 1);
  14. int inputPort = 0;
  15. for (TStream<T> other : others) {
  16. @SuppressWarnings("unchecked")
  17. ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
  18. cs.connector.connect(fanInVertex, inputPort++);
  19. }
  20. return derived(fanInVertex.getConnectors().get(0));
  21. }

代码示例来源:origin: org.apache.edgent/edgent-spi-graph

  1. @SuppressWarnings({ "unchecked", "rawtypes" })
  2. @Override
  3. public void peekAll(Supplier<? extends Peek<?>> supplier, Predicate<Vertex<?, ?, ?>> select) {
  4. // Select vertices which satisfy the specified predicate
  5. List<Vertex<?, ?, ?>> vertices = new ArrayList<>();
  6. for (Vertex<?, ?, ?> v : getVertices()) {
  7. if (select.test(v)) {
  8. vertices.add(v);
  9. }
  10. }
  11. // Insert peek oplets on isConnected() output ports
  12. for (Vertex<?, ?, ?> v : vertices) {
  13. List<? extends Connector<?>> connectors = v.getConnectors();
  14. for (Connector<?> c : connectors) {
  15. if (c.isConnected()) {
  16. Peek<?> oplet = supplier.get();
  17. c.peek((Peek) oplet);
  18. }
  19. }
  20. }
  21. }
  22. }

代码示例来源:origin: apache/incubator-edgent

  1. @SuppressWarnings({ "unchecked", "rawtypes" })
  2. @Override
  3. public void peekAll(Supplier<? extends Peek<?>> supplier, Predicate<Vertex<?, ?, ?>> select) {
  4. // Select vertices which satisfy the specified predicate
  5. List<Vertex<?, ?, ?>> vertices = new ArrayList<>();
  6. for (Vertex<?, ?, ?> v : getVertices()) {
  7. if (select.test(v)) {
  8. vertices.add(v);
  9. }
  10. }
  11. // Insert peek oplets on isConnected() output ports
  12. for (Vertex<?, ?, ?> v : vertices) {
  13. List<? extends Connector<?>> connectors = v.getConnectors();
  14. for (Connector<?> c : connectors) {
  15. if (c.isConnected()) {
  16. Peek<?> oplet = supplier.get();
  17. c.peek((Peek) oplet);
  18. }
  19. }
  20. }
  21. }
  22. }

代码示例来源:origin: apache/incubator-edgent

  1. @Test
  2. public void testGraphToJson2() {
  3. Graph g = getGraph();
  4. TestOp<String, Integer> op1 = new TestOp<>();
  5. Vertex<TestOp<String, Integer>, String, Integer> v = g.insert(op1, 1, 1);
  6. TestOp<Integer, Integer> op2 = new TestOp<>();
  7. /*Connector<Integer> out2 = */g.pipe(v.getConnectors().get(0), op2);
  8. Gson gson = new GsonBuilder().setPrettyPrinting().create();
  9. String json = gson.toJson(new GraphType(g));
  10. GraphType gt2 = new Gson().fromJson(json, GraphType.class);
  11. assertEquals(2, gt2.getVertices().size());
  12. assertEquals(1, gt2.getEdges().size());
  13. }

相关文章