• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Messenger类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.computer.Messenger的典型用法代码示例。如果您正苦于以下问题:Java Messenger类的具体用法?Java Messenger怎么用?Java Messenger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Messenger类属于org.apache.tinkerpop.gremlin.process.computer包,在下文中一共展示了Messenger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: safeExecute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<PathMessage> messenger, final Memory memory) {
    if (memory.isInitialIteration()) {
        // The type of id will likely have to change as we support more and more vendors
        String id = getVertexId(vertex);
        if (persistentProperties.get(SOURCE).equals(id)) {
            LOGGER.debug("Found source vertex");
            vertex.property(VISITED_IN_ITERATION, 1);
            sendMessage(messenger, PathMessage.of(FROM_SOURCE, id));
        } else if (persistentProperties.get(DESTINATION).equals(id)) {
            LOGGER.debug("Found destination vertex");
            vertex.property(VISITED_IN_ITERATION, -1);
            sendMessage(messenger, PathMessage.of(FROM_DESTINATION, id));
        }
    } else {
        if (memory.<Boolean>get(FOUND_PATH)) {
            if (messenger.receiveMessages().hasNext() && vertex.property(VISITED_IN_ITERATION).isPresent()) {
                recordPredecessors(vertex, messenger, memory);
            }
        } else if (messenger.receiveMessages().hasNext()) {
            updateInstance(vertex, messenger, memory);
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:25,代码来源:ShortestPathVertexProgram.java


示例2: updateEntityAndAttribute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
private void updateEntityAndAttribute(Vertex vertex, Messenger<String> messenger, Memory memory) {
    if (vertex.property(CLUSTER_LABEL).isPresent()) {
        String id = vertex.value(Schema.VertexProperty.ID.name());
        int messageCount = getMessageCount(messenger, id) +
                (vertex.property(IMPLICIT_MESSAGE_COUNT).isPresent() ?
                        (int) vertex.value(IMPLICIT_MESSAGE_COUNT) : 0);

        if (messageCount >= k) {
            LOGGER.trace("Sending msg from " + id);
            sendMessage(messenger, id);
            memory.add(K_CORE_EXIST, true);
        } else {
            LOGGER.trace("Removing label of " + id);
            vertex.property(CLUSTER_LABEL).remove();
            memory.add(K_CORE_STABLE, false);
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:19,代码来源:KCoreVertexProgram.java


示例3: safeExecute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) {
    switch (memory.getIteration()) {
        case 0:
            degreeStatisticsStepResourceOwner(vertex, messenger, ofLabelIds);
            break;
        case 1:
            degreeStatisticsStepResourceRelation(vertex, messenger, ofLabelIds);
            break;
        case 2:
            degreeStatisticsStepResource(vertex, messenger, ofLabelIds);
            break;
        default:
            throw CommonUtil.unreachableStatement("Exceeded expected maximum number of iterations");
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:17,代码来源:DegreeStatisticsVertexProgram.java


示例4: execute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) {
    if (memory.isInitialIteration()) {
        messenger.sendMessage(this.countMessageScope, 1.0d);
    } else if (1 == memory.getIteration()) {
        double initialPageRank = (null == this.initialRankTraversal ?
                1.0d :
                TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / this.vertexCountAsDouble;
        double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
        vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
        vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
        if (!this.terminate(memory)) // don't send messages if this is the last iteration
            messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
    } else {
        double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
        newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / this.vertexCountAsDouble);
        vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
        if (!this.terminate(memory)) // don't send messages if this is the last iteration
            messenger.sendMessage(this.incidentMessageScope, newPageRank / vertex.<Double>value(EDGE_COUNT));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:22,代码来源:PageRankVertexProgram.java


示例5: execute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void execute(Vertex vertex, Messenger<Double> messenger, Memory memory) {
    if (memory.isInitialIteration()) {
        messenger.sendMessage(inE, 1D);
    } else if (1 == memory.getIteration()) {
        double initialPageRank = 1D / vertexCount;
        double edgeCount = IteratorUtils.stream(messenger.receiveMessages()).reduce(0D, (a, b) -> a + b);
        vertex.property(VertexProperty.Cardinality.single, PAGE_RANK, initialPageRank);
        vertex.property(VertexProperty.Cardinality.single, OUTGOING_EDGE_COUNT, edgeCount);
        messenger.sendMessage(outE, initialPageRank / edgeCount);
    } else {
        double newPageRank = IteratorUtils.stream(messenger.receiveMessages()).reduce(0D, (a, b) -> a + b);
        newPageRank =  (dampingFactor * newPageRank) + ((1D - dampingFactor) / vertexCount);
        vertex.property(VertexProperty.Cardinality.single, PAGE_RANK, newPageRank);
        messenger.sendMessage(outE, newPageRank / vertex.<Double>value(OUTGOING_EDGE_COUNT));
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:18,代码来源:PageRankVertexProgram.java


示例6: getPredecessors

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
private static Map<String, Set<String>> getPredecessors(Vertex vertex, Messenger<PathMessage> messenger) {
    Set<String> predecessors = new HashSet<>();
    Iterator<PathMessage> iterator = messenger.receiveMessages();
    while (iterator.hasNext()) {
        PathMessage message = iterator.next();
        if (message.direction() == FROM_MIDDLE) {
            predecessors.add(message.id());
        }
    }
    if (predecessors.isEmpty()) return Collections.emptyMap();

    Map<String, Set<String>> predecessorMap = new HashMap<>();
    predecessorMap.put(getVertexId(vertex), predecessors);
    return predecessorMap;
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:16,代码来源:ShortestPathVertexProgram.java


示例7: execute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void execute(Vertex vertex, Messenger<T> messenger, Memory memory) {
    // try to deal with ghost vertex issues by ignoring them
    if (Utility.isAlive(vertex)) {
        safeExecute(vertex, messenger, memory);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:8,代码来源:GraknVertexProgram.java


示例8: safeExecute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<String> messenger, final Memory memory) {
    if (memory.isInitialIteration()) {
        String id = vertex.value(Schema.VertexProperty.ID.name());
        vertex.property(CLUSTER_LABEL, id);
        messenger.sendMessage(messageScopeIn, id);
        messenger.sendMessage(messageScopeOut, id);
    } else {
        updateClusterLabel(vertex, messenger, memory);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:12,代码来源:ConnectedComponentsVertexProgram.java


示例9: updateClusterLabel

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
private static void updateClusterLabel(Vertex vertex, Messenger<String> messenger, Memory memory) {
    String currentMax = vertex.value(CLUSTER_LABEL);
    String max = IteratorUtils.reduce(messenger.receiveMessages(), currentMax,
            (a, b) -> a.compareTo(b) > 0 ? a : b);
    if (max.compareTo(currentMax) > 0) {
        vertex.property(CLUSTER_LABEL, max);
        messenger.sendMessage(messageScopeIn, max);
        messenger.sendMessage(messageScopeOut, max);
        memory.add(VOTE_TO_HALT, false);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:12,代码来源:ConnectedComponentsVertexProgram.java


示例10: relayOrSaveMessages

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
private static void relayOrSaveMessages(Vertex vertex, Messenger<String> messenger) {
    if (messenger.receiveMessages().hasNext()) {
        if (vertex.label().equals(Schema.BaseType.RELATIONSHIP.name())) {
            // relay the messages
            messenger.receiveMessages().forEachRemaining(msg -> sendMessage(messenger, msg));
        } else if ((vertex.label().equals(Schema.BaseType.ENTITY.name()) ||
                vertex.label().equals(Schema.BaseType.ATTRIBUTE.name())) &&
                vertex.property(CLUSTER_LABEL).isPresent()) {
            // messages received via implicit edge, save the count for next iteration
            vertex.property(IMPLICIT_MESSAGE_COUNT, Iterators.size(messenger.receiveMessages()));
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:14,代码来源:KCoreVertexProgram.java


示例11: updateClusterLabel

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
private static void updateClusterLabel(Vertex vertex, Messenger<String> messenger, Memory memory) {
    String currentMax = vertex.value(CLUSTER_LABEL);
    String max = IteratorUtils.reduce(messenger.receiveMessages(), currentMax,
            (a, b) -> a.compareTo(b) > 0 ? a : b);
    if (!max.equals(currentMax)) {
        LOGGER.trace("Cluster label of " + vertex + " changed from " + currentMax + " to " + max);
        vertex.property(CLUSTER_LABEL, max);
        sendMessage(messenger, max);
        memory.add(VOTE_TO_HALT, false);
    } else {
        LOGGER.trace("Cluster label of " + vertex + " is still " + currentMax);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:14,代码来源:KCoreVertexProgram.java


示例12: relayClusterLabel

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
private static void relayClusterLabel(Messenger<String> messenger, Memory memory) {
    String firstMessage = messenger.receiveMessages().next();
    String max = IteratorUtils.reduce(messenger.receiveMessages(), firstMessage,
            (a, b) -> a.compareTo(b) > 0 ? a : b);
    sendMessage(messenger, max);
    memory.add(VOTE_TO_HALT, false);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:8,代码来源:KCoreVertexProgram.java


示例13: safeExecute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) {
    switch (memory.getIteration()) {
        case 0:
            degreeMessagePassing(messenger);
            break;
        case 1:
            degreeMessageCounting(messenger, vertex);
            break;
        default:
            throw CommonUtil.unreachableStatement("Exceeded expected maximum number of iterations");
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:14,代码来源:DegreeVertexProgram.java


示例14: degreeStatisticsStepResourceOwner

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
static void degreeStatisticsStepResourceOwner(Vertex vertex, Messenger<Long> messenger, Set<LabelId> ofLabelIds) {
    LabelId labelId = Utility.getVertexTypeId(vertex);
    if (labelId.isValid() && !ofLabelIds.contains(labelId)) {
        messenger.sendMessage(messageScopeShortcutIn, 1L);
        messenger.sendMessage(messageScopeResourceOut, 1L);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:8,代码来源:DegreeStatisticsVertexProgram.java


示例15: degreeStatisticsStepResourceRelation

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
static void degreeStatisticsStepResourceRelation(Vertex vertex, Messenger<Long> messenger, Set<LabelId> ofLabelIds) {
    if (messenger.receiveMessages().hasNext()) {
        if (vertex.label().equals(Schema.BaseType.RELATIONSHIP.name())) {
            messenger.sendMessage(messageScopeOut, 1L);
        } else if (ofLabelIds.contains(Utility.getVertexTypeId(vertex))) {
            vertex.property(DEGREE, getMessageCount(messenger));
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:10,代码来源:DegreeStatisticsVertexProgram.java


示例16: degreeStatisticsStepResource

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
static void degreeStatisticsStepResource(Vertex vertex, Messenger<Long> messenger,
                                         Set<LabelId> ofLabelIds) {
    if (vertexHasSelectedTypeId(vertex, ofLabelIds)) {
        vertex.property(DEGREE, vertex.property(DEGREE).isPresent() ?
                getMessageCount(messenger) + (Long) vertex.value(DEGREE) : getMessageCount(messenger));
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:8,代码来源:DegreeStatisticsVertexProgram.java


示例17: safeExecute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<Boolean> messenger, final Memory memory) {
    if (memory.isInitialIteration()) {
        if (vertex.<String>value(Schema.VertexProperty.ID.name()).equals(persistentProperties.get(SOURCE))) {
            update(vertex, messenger, memory, (String) persistentProperties.get(SOURCE));
        }
    } else {
        if (messenger.receiveMessages().hasNext() && !vertex.property(CLUSTER_LABEL).isPresent()) {
            update(vertex, messenger, memory, (String) persistentProperties.get(SOURCE));
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:13,代码来源:ConnectedComponentVertexProgram.java


示例18: safeExecute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) {
    switch (memory.getIteration()) {
        case 0:
            messenger.sendMessage(messageScopeOut, 1L);
            break;
        case 1:
            if (messenger.receiveMessages().hasNext()) {
                vertex.property(EDGE_COUNT, getMessageCount(messenger));
            }
            break;
        default:
            throw CommonUtil.unreachableStatement("Exceeded expected maximum number of iterations");
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:16,代码来源:CountVertexProgram.java


示例19: execute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void execute(final Vertex sourceVertex, final Messenger<Tuple> messenger, final Memory memory) {
    try {
        executeInternal(sourceVertex, messenger, memory);
    } catch (Exception e) {
        if (graph.features().graph().supportsTransactions()) {
            graph.tx().rollback();
        }
        throw e;
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:12,代码来源:BulkLoaderVertexProgram.java


示例20: execute

import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入依赖的package包/类
@Override
public void execute(final Vertex vertex, final Messenger messenger, final Memory memory) {
    assertFalse(memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS));
    final TraverserGenerator generator = this.traversal.get().getTraverserGenerator();
    MemoryTraversalSideEffects.setMemorySideEffects(this.traversal.get(), memory, ProgramPhase.EXECUTE);
    this.checkSideEffects();
    final TraverserSet<Vertex> activeTraversers = memory.get(TraversalVertexProgram.ACTIVE_TRAVERSERS);
    if (vertex.label().equals("software")) {
        assertEquals(1, activeTraversers.stream().filter(v -> v.get().equals(vertex)).count());
        if (memory.isInitialIteration()) {
            assertFalse(vertex.property(TraversalVertexProgram.HALTED_TRAVERSERS).isPresent());
            vertex.property(
                    TraversalVertexProgram.HALTED_TRAVERSERS,
                    new TraverserSet<>(generator.generate(vertex.value("name"), this.programStep, 1l)));
        } else {
            assertTrue(vertex.property(TraversalVertexProgram.HALTED_TRAVERSERS).isPresent());
        }
    } else {
        assertFalse(vertex.property(TraversalVertexProgram.HALTED_TRAVERSERS).isPresent());
        assertEquals(0, activeTraversers.stream().filter(v -> v.get().equals(vertex)).count());
        if (!memory.isInitialIteration()) {
            if (vertex.value("name").equals("marko"))
                memory.add(TraversalVertexProgram.HALTED_TRAVERSERS, new TraverserSet<>(generator.generate("marko-is-my-name", this.programStep, 1l)));
            else if (vertex.value("name").equals("vadas"))
                this.traversal.get().getSideEffects().add(TraversalVertexProgram.HALTED_TRAVERSERS, new TraverserSet<>(generator.generate("the-v-o-double-g", this.programStep, 1l)));
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:29,代码来源:ProgramTest.java



注:本文中的org.apache.tinkerpop.gremlin.process.computer.Messenger类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Interner类代码示例发布时间:2022-05-22
下一篇:
Java S28PacketEffect类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap