本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.computer.MessageScope类的典型用法代码示例。如果您正苦于以下问题:Java MessageScope类的具体用法?Java MessageScope怎么用?Java MessageScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageScope类属于org.apache.tinkerpop.gremlin.process.computer包,在下文中一共展示了MessageScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void sendMessage(final MessageScope messageScope, final M message) {
if (messageScope instanceof MessageScope.Local) {
final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope;
final Traversal.Admin<Vertex, Edge> incidentTraversal = GiraphMessenger.setVertexStart(localMessageScope.getIncidentTraversal().get().asAdmin(), this.giraphVertex.getValue().get());
final Direction direction = GiraphMessenger.getOppositeDirection(incidentTraversal);
incidentTraversal.forEachRemaining(edge ->
this.giraphComputation.sendMessage(
new ObjectWritable<>(edge.vertices(direction).next().id()),
new ObjectWritable<>(localMessageScope.getEdgeFunction().apply(message, edge))));
} else {
final MessageScope.Global globalMessageScope = (MessageScope.Global) messageScope;
globalMessageScope.vertices().forEach(vertex ->
this.giraphComputation.sendMessage(new ObjectWritable<>(vertex.id()), new ObjectWritable<>(message)));
}
}
示例2: receiveMessages
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public Iterator<M> receiveMessages() {
final MultiIterator<M> multiIterator = new MultiIterator<>();
for (final MessageScope messageScope : this.messageBoard.previousMessageScopes) {
if (messageScope instanceof MessageScope.Local) {
final MessageScope.Local<M> localMessageScope = (MessageScope.Local<M>) messageScope;
final Traversal.Admin<Vertex, Edge> incidentTraversal = TinkerMessenger.setVertexStart(localMessageScope.getIncidentTraversal().get().asAdmin(), this.vertex);
final Direction direction = TinkerMessenger.getDirection(incidentTraversal);
final Edge[] edge = new Edge[1]; // simulates storage side-effects available in Gremlin, but not Java8 streams
multiIterator.addIterator(StreamSupport.stream(Spliterators.spliteratorUnknownSize(VertexProgramHelper.reverse(incidentTraversal.asAdmin()), Spliterator.IMMUTABLE | Spliterator.SIZED), false)
.map(e -> this.messageBoard.receiveMessages.get((edge[0] = e).vertices(direction).next()))
.filter(q -> null != q)
.flatMap(Queue::stream)
.map(message -> localMessageScope.getEdgeFunction().apply(message, edge[0]))
.iterator());
} else {
multiIterator.addIterator(Stream.of(this.vertex)
.map(this.messageBoard.receiveMessages::get)
.filter(q -> null != q)
.flatMap(Queue::stream)
.iterator());
}
}
return multiIterator;
}
示例3: receiveMessages
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
public Stream<M> receiveMessages(MessageScope messageScope) {
if (messageScope instanceof MessageScope.Global) {
M message = vertexMemory.getMessage(vertexId,messageScope);
if (message == null) return Stream.empty();
else return Stream.of(message);
} else {
final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope;
final Traversal<Vertex, Edge> reverseIncident = FulgoraUtil.getReverseElementTraversal(localMessageScope,vertex,vertex.tx());
final BiFunction<M,Edge,M> edgeFct = localMessageScope.getEdgeFunction();
return IteratorUtils.stream(reverseIncident)
.map(e -> {
M msg = vertexMemory.getMessage(vertexMemory.getCanonicalId(((TitanEdge) e).otherVertex(vertex).longId()), localMessageScope);
return msg == null ? null : edgeFct.apply(msg, e);
})
.filter(m -> m != null);
}
}
示例4: addMessage
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
public synchronized void addMessage(M message, MessageScope scope, Map<MessageScope,Integer> scopeMap,
MessageCombiner<M> combiner) {
assert message!=null && scope!=null && combiner!=null;
Preconditions.checkArgument(scopeMap.containsKey(scope),"Provided scope was not declared in the VertexProgram: %s",scope);
assert scopeMap.containsKey(scope);
initializeCurrentMessages(scopeMap);
if (scopeMap.size()==1) {
if (currentMessages==null) currentMessages = message;
else currentMessages = combiner.combine(message,(M)currentMessages);
} else {
int pos = scopeMap.get(scope);
Object[] msgs = (Object[])currentMessages;
if (msgs[pos]==null) msgs[pos]=message;
else msgs[pos] = combiner.combine(message,(M)msgs[pos]);
}
}
示例5: loadState
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void loadState(final Graph graph, final Configuration configuration) {
if (configuration.containsKey(INITIAL_RANK_TRAVERSAL))
this.initialRankTraversal = PureTraversal.loadState(configuration, INITIAL_RANK_TRAVERSAL, graph);
if (configuration.containsKey(EDGE_TRAVERSAL)) {
this.edgeTraversal = PureTraversal.loadState(configuration, EDGE_TRAVERSAL, graph);
this.incidentMessageScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
this.countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
}
this.alpha = configuration.getDouble(ALPHA, this.alpha);
this.epsilon = configuration.getDouble(EPSILON, this.epsilon);
this.maxIterations = configuration.getInt(MAX_ITERATIONS, 20);
this.property = configuration.getString(PROPERTY, PAGE_RANK);
this.vertexComputeKeys = new HashSet<>(Arrays.asList(
VertexComputeKey.of(this.property, false),
VertexComputeKey.of(EDGE_COUNT, true)));
this.memoryComputeKeys = new HashSet<>(Arrays.asList(
MemoryComputeKey.of(TELEPORTATION_ENERGY, Operator.sum, true, true),
MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true),
MemoryComputeKey.of(CONVERGENCE_ERROR, Operator.sum, false, true)));
}
示例6: receiveMessages
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public Iterator<M> receiveMessages() {
final MultiIterator<M> multiIterator = new MultiIterator<>();
for (final MessageScope messageScope : this.messageBoard.receiveMessages.keySet()) {
// for (final MessageScope messageScope : this.messageBoard.previousMessageScopes) {
if (messageScope instanceof MessageScope.Local) {
final MessageScope.Local<M> localMessageScope = (MessageScope.Local<M>) messageScope;
final Traversal.Admin<Vertex, Edge> incidentTraversal = TinkerMessenger.setVertexStart(localMessageScope.getIncidentTraversal().get().asAdmin(), this.vertex);
final Direction direction = TinkerMessenger.getDirection(incidentTraversal);
final Edge[] edge = new Edge[1]; // simulates storage side-effects available in Gremlin, but not Java8 streams
multiIterator.addIterator(StreamSupport.stream(Spliterators.spliteratorUnknownSize(VertexProgramHelper.reverse(incidentTraversal.asAdmin()), Spliterator.IMMUTABLE | Spliterator.SIZED), false)
.map(e -> this.messageBoard.receiveMessages.get(messageScope).get((edge[0] = e).vertices(direction).next()))
.filter(q -> null != q)
.flatMap(Queue::stream)
.map(message -> localMessageScope.getEdgeFunction().apply(message, edge[0]))
.iterator());
} else {
multiIterator.addIterator(Stream.of(this.vertex)
.map(this.messageBoard.receiveMessages.get(messageScope)::get)
.filter(q -> null != q)
.flatMap(Queue::stream)
.iterator());
}
}
return multiIterator;
}
示例7: sendMessage
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void sendMessage(final MessageScope messageScope, final M message) {
// this.messageBoard.currentMessageScopes.add(messageScope);
if (messageScope instanceof MessageScope.Local) {
addMessage(this.vertex, message, messageScope);
} else {
((MessageScope.Global) messageScope).vertices().forEach(v -> addMessage(v, message, messageScope));
}
}
示例8: addMessage
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
private void addMessage(final Vertex vertex, final M message, MessageScope messageScope) {
this.messageBoard.sendMessages.compute(messageScope, (ms, messages) -> {
if(null==messages) messages = new ConcurrentHashMap<>();
return messages;
});
this.messageBoard.sendMessages.get(messageScope).compute(vertex, (v, queue) -> {
if (null == queue) queue = new ConcurrentLinkedQueue<>();
queue.add(null != this.combiner && !queue.isEmpty() ? this.combiner.combine(queue.remove(), message) : message);
return queue;
});
}
示例9: getMessageScopes
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public Set<MessageScope> getMessageScopes(final Memory memory) {
switch (memory.getIteration()) {
case 0:
return Sets.newHashSet(messageScopeShortcutIn, messageScopeResourceOut);
case 1:
return Collections.singleton(messageScopeShortcutOut);
default:
return Collections.emptySet();
}
}
示例10: loadState
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void loadState(final Graph graph, final Configuration configuration) {
if (configuration.containsKey(INITIAL_RANK_TRAVERSAL))
this.initialRankTraversal = PureTraversal.loadState(configuration, INITIAL_RANK_TRAVERSAL, graph);
if (configuration.containsKey(EDGE_TRAVERSAL)) {
this.edgeTraversal = PureTraversal.loadState(configuration, EDGE_TRAVERSAL, graph);
this.incidentMessageScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
this.countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
}
this.vertexCountAsDouble = configuration.getDouble(VERTEX_COUNT, 1.0d);
this.alpha = configuration.getDouble(ALPHA, 0.85d);
this.totalIterations = configuration.getInt(TOTAL_ITERATIONS, 30);
this.property = configuration.getString(PROPERTY, PAGE_RANK);
this.vertexComputeKeys = new HashSet<>(Arrays.asList(VertexComputeKey.of(this.property, false), VertexComputeKey.of(EDGE_COUNT, true)));
}
示例11: loadState
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void loadState(final Graph graph, final Configuration configuration) {
if (configuration.containsKey(INITIAL_VOTE_STRENGTH_TRAVERSAL))
this.initialVoteStrengthTraversal = PureTraversal.loadState(configuration, INITIAL_VOTE_STRENGTH_TRAVERSAL, graph);
if (configuration.containsKey(EDGE_TRAVERSAL)) {
this.edgeTraversal = PureTraversal.loadState(configuration, EDGE_TRAVERSAL, graph);
this.voteScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
this.countScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.voteScope));
}
this.property = configuration.getString(PROPERTY, CLUSTER);
this.maxIterations = configuration.getInt(MAX_ITERATIONS, 30);
this.distributeVote = configuration.getBoolean(DISTRIBUTE_VOTE, false);
}
示例12: sendMessage
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void sendMessage(final MessageScope messageScope, final M message) {
this.messageBoard.currentMessageScopes.add(messageScope);
if (messageScope instanceof MessageScope.Local) {
addMessage(this.vertex, message);
} else {
((MessageScope.Global) messageScope).vertices().forEach(v -> addMessage(v, message));
}
}
示例13: sendMessage
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void sendMessage(final MessageScope messageScope, final M message) {
if (messageScope instanceof MessageScope.Local) {
final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope;
final Traversal.Admin<Vertex, Edge> incidentTraversal = SparkMessenger.setVertexStart(localMessageScope.getIncidentTraversal().get().asAdmin(), this.vertex);
final Direction direction = SparkMessenger.getOppositeDirection(incidentTraversal);
incidentTraversal.forEachRemaining(edge -> this.outgoingMessages.add(new Tuple2<>(edge.vertices(direction).next().id(), message)));
} else {
((MessageScope.Global) messageScope).vertices().forEach(v -> this.outgoingMessages.add(new Tuple2<>(v.id(), message)));
}
}
示例14: loadState
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void loadState(final Graph graph, final Configuration configuration) {
maxDepth = configuration.getInt(MAX_DEPTH);
seed = configuration.getLong(SEED);
weightProperty = configuration.getString(WEIGHT_PROPERTY, "distance");
incidentMessageScope = MessageScope.Local.of(__::inE, (msg, edge) -> msg + edge.<Integer>value(weightProperty));
log.debug("Loaded maxDepth={}", maxDepth);
}
示例15: process
import org.apache.tinkerpop.gremlin.process.computer.MessageScope; //导入依赖的package包/类
@Override
public void process(TitanVertex vertex, ScanMetrics metrics) {
PreloadedVertex v = (PreloadedVertex)vertex;
long vertexId = v.longId();
VertexMemoryHandler<M> vh = new VertexMemoryHandler(vertexMemory,v);
v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK);
if (idManager.isPartitionedVertex(vertexId)) {
if (idManager.isCanonicalVertexId(vertexId)) {
EntryList results = v.getFromCache(SYSTEM_PROPS_QUERY);
if (results == null) results = EntryList.EMPTY_LIST;
vertexMemory.setLoadedProperties(vertexId,results);
}
for (MessageScope scope : vertexMemory.getPreviousScopes()) {
if (scope instanceof MessageScope.Local) {
M combinedMsg = null;
for (Iterator<M> msgIter = vh.receiveMessages(scope).iterator(); msgIter.hasNext(); ) {
M msg = msgIter.next();
if (combinedMsg==null) combinedMsg=msg;
else combinedMsg = combiner.combine(combinedMsg,msg);
}
if (combinedMsg!=null) vertexMemory.aggregateMessage(vertexId,combinedMsg,scope);
}
}
} else {
v.setPropertyMixing(vh);
vertexProgram.execute(v, vh, memory);
}
}