本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.computer.Messenger类的典型用法代码示例。如果您正苦于以下问题:Java Messenger类的具体用法?Java Messenger怎么用?Java Messenger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Messenger类属于org.apache.tinkerpop.gremlin.process.computer包,在下文中一共展示了Messenger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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);
}
}
}
示例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");
}
}
示例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));
}
}
示例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));
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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()));
}
}
}
示例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);
}
}
示例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);
}
示例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");
}
}
示例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);
}
}
示例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));
}
}
}