@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.gatherFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.gatherFunction.init(getIterationRuntimeContext()); } this.gatherFunction.preSuperstep(); }
/** * Sets the new value of this vertex. Setting a new value triggers the sending of outgoing messages from this vertex. * * <p>This should be called at most once per updateVertex. * * @param newValue The new vertex value. */ public void setNewVertexValue(VV newValue) { if (setNewVertexValueCalled) { throw new IllegalStateException("setNewVertexValue should only be called at most once per updateVertex"); } setNewVertexValueCalled = true; if (isOptDegrees()) { outValWithDegrees.f1.f0 = newValue; outWithDegrees.collect(outValWithDegrees); } else { outVal.setValue(newValue); out.collect(outVal); } }
@Override public void close() throws Exception { this.gatherFunction.postSuperstep(); }
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, VV>> vertex, Collector<Vertex<K, VV>> out) throws Exception { final Iterator<Vertex<K, VV>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, VV> vertexState = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setOutput(vertexState, out); gatherFunction.updateVertex(vertexState, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertex, Collector<Vertex<K, Tuple3<VV, LongValue, LongValue>>> out) throws Exception { final Iterator<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, Tuple3<VV, LongValue, LongValue>> vertexWithDegrees = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setInDegree(vertexWithDegrees.f1.f1.getValue()); gatherFunction.setOutDegree(vertexWithDegrees.f1.f2.getValue()); gatherFunction.setOutputWithDegrees(vertexWithDegrees, out); gatherFunction.updateVertexFromScatterGatherIteration(vertexWithDegrees, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
this.gatherFunction.setOptDegrees(this.configuration.isOptDegrees());
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertex, Collector<Vertex<K, Tuple3<VV, LongValue, LongValue>>> out) throws Exception { final Iterator<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, Tuple3<VV, LongValue, LongValue>> vertexWithDegrees = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setInDegree(vertexWithDegrees.f1.f1.getValue()); gatherFunction.setOutDegree(vertexWithDegrees.f1.f2.getValue()); gatherFunction.setOutputWithDegrees(vertexWithDegrees, out); gatherFunction.updateVertexFromScatterGatherIteration(vertexWithDegrees, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, VV>> vertex, Collector<Vertex<K, VV>> out) throws Exception { final Iterator<Vertex<K, VV>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, VV> vertexState = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setOutput(vertexState, out); gatherFunction.updateVertex(vertexState, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
this.gatherFunction.setOptDegrees(this.configuration.isOptDegrees());
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertex, Collector<Vertex<K, Tuple3<VV, LongValue, LongValue>>> out) throws Exception { final Iterator<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, Tuple3<VV, LongValue, LongValue>> vertexWithDegrees = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setInDegree(vertexWithDegrees.f1.f1.getValue()); gatherFunction.setOutDegree(vertexWithDegrees.f1.f2.getValue()); gatherFunction.setOutputWithDegrees(vertexWithDegrees, out); gatherFunction.updateVertexFromScatterGatherIteration(vertexWithDegrees, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.gatherFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.gatherFunction.init(getIterationRuntimeContext()); } this.gatherFunction.preSuperstep(); }
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, VV>> vertex, Collector<Vertex<K, VV>> out) throws Exception { final Iterator<Vertex<K, VV>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, VV> vertexState = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setOutput(vertexState, out); gatherFunction.updateVertex(vertexState, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
@Override public void close() throws Exception { this.gatherFunction.postSuperstep(); }
/** * Sets the new value of this vertex. Setting a new value triggers the sending of outgoing messages from this vertex. * * This should be called at most once per updateVertex. * * @param newValue The new vertex value. */ public void setNewVertexValue(VV newValue) { if(setNewVertexValueCalled) { throw new IllegalStateException("setNewVertexValue should only be called at most once per updateVertex"); } setNewVertexValueCalled = true; if(isOptDegrees()) { outValWithDegrees.f1.f0 = newValue; outWithDegrees.collect(outValWithDegrees); } else { outVal.setValue(newValue); out.collect(outVal); } }
this.gatherFunction.setOptDegrees(this.configuration.isOptDegrees());
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertex, Collector<Vertex<K, Tuple3<VV, LongValue, LongValue>>> out) throws Exception { final Iterator<Vertex<K, Tuple3<VV, LongValue, LongValue>>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, Tuple3<VV, LongValue, LongValue>> vertexWithDegrees = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setInDegree(vertexWithDegrees.f1.f1.getValue()); gatherFunction.setOutDegree(vertexWithDegrees.f1.f2.getValue()); gatherFunction.setOutputWithDegrees(vertexWithDegrees, out); gatherFunction.updateVertexFromScatterGatherIteration(vertexWithDegrees, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.gatherFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.gatherFunction.init(getIterationRuntimeContext()); } this.gatherFunction.preSuperstep(); }
@Override public void coGroup(Iterable<Tuple2<K, Message>> messages, Iterable<Vertex<K, VV>> vertex, Collector<Vertex<K, VV>> out) throws Exception { final Iterator<Vertex<K, VV>> vertexIter = vertex.iterator(); if (vertexIter.hasNext()) { Vertex<K, VV> vertexState = vertexIter.next(); @SuppressWarnings("unchecked") Iterator<Tuple2<?, Message>> downcastIter = (Iterator<Tuple2<?, Message>>) (Iterator<?>) messages.iterator(); messageIter.setSource(downcastIter); gatherFunction.setOutput(vertexState, out); gatherFunction.updateVertex(vertexState, messageIter); } else { final Iterator<Tuple2<K, Message>> messageIter = messages.iterator(); if (messageIter.hasNext()) { String message = "Target vertex does not exist!."; try { Tuple2<K, Message> next = messageIter.next(); message = "Target vertex '" + next.f0 + "' does not exist!."; } catch (Throwable ignored) {} throw new Exception(message); } else { throw new Exception(); } } } }
@Override public void close() throws Exception { this.gatherFunction.postSuperstep(); }
/** * Sets the new value of this vertex. Setting a new value triggers the sending of outgoing messages from this vertex. * * <p>This should be called at most once per updateVertex. * * @param newValue The new vertex value. */ public void setNewVertexValue(VV newValue) { if (setNewVertexValueCalled) { throw new IllegalStateException("setNewVertexValue should only be called at most once per updateVertex"); } setNewVertexValueCalled = true; if (isOptDegrees()) { outValWithDegrees.f1.f0 = newValue; outWithDegrees.collect(outValWithDegrees); } else { outVal.setValue(newValue); out.collect(outVal); } }