List of usage examples for org.apache.hadoop.io LongWritable get
public long get()
From source file:org.apache.giraph.comm.messages.primitives.LongDoubleMessageStore.java
License:Apache License
@Override public boolean hasMessagesForVertex(LongWritable vertexId) { return getPartitionMap(vertexId).containsKey(vertexId.get()); }
From source file:org.apache.giraph.comm.messages.primitives.LongDoubleMessageStore.java
License:Apache License
@Override public Iterable<DoubleWritable> getVertexMessages(LongWritable vertexId) throws IOException { Long2DoubleOpenHashMap partitionMap = getPartitionMap(vertexId); if (!partitionMap.containsKey(vertexId.get())) { return EmptyIterable.get(); } else {//from w w w.j a v a 2s. c o m return Collections.singleton(new DoubleWritable(partitionMap.get(vertexId.get()))); } }
From source file:org.apache.giraph.comm.messages.primitives.LongDoubleMessageStore.java
License:Apache License
@Override public void clearVertexMessages(LongWritable vertexId) throws IOException { getPartitionMap(vertexId).remove(vertexId.get()); }
From source file:org.apache.giraph.comm.messages.primitives.LongLongMessageStore.java
License:Apache License
@Override public void addPartitionMessage(int partitionId, LongWritable destVertexId, LongWritable message) throws IOException { // TODO-YH: this creates a new object for EVERY message, which // can result in substantial overheads. ////from w ww .j a v a 2 s.c om // A better solution is to have a resuable LongWritable for each // partition id (i.e., per-instance map), which are then automatically // protected when synchronized on partitionMap below. LongWritable reusableCurrentMessage = new LongWritable(); Long2LongOpenHashMap partitionMap = map.get(partitionId); synchronized (partitionMap) { long vertexId = destVertexId.get(); long msg = message.get(); if (partitionMap.containsKey(vertexId)) { reusableCurrentMessage.set(partitionMap.get(vertexId)); messageCombiner.combine(destVertexId, reusableCurrentMessage, message); msg = reusableCurrentMessage.get(); } partitionMap.put(vertexId, msg); } }
From source file:org.apache.giraph.comm.messages.primitives.LongLongMessageStore.java
License:Apache License
@Override public void addPartitionMessages(int partitionId, VertexIdMessages<LongWritable, LongWritable> messages) throws IOException { LongWritable reusableVertexId = new LongWritable(); LongWritable reusableMessage = new LongWritable(); LongWritable reusableCurrentMessage = new LongWritable(); Long2LongOpenHashMap partitionMap = map.get(partitionId); synchronized (partitionMap) { VertexIdMessageIterator<LongWritable, LongWritable> iterator = messages.getVertexIdMessageIterator(); while (iterator.hasNext()) { iterator.next();// www. j a v a 2 s. c o m long vertexId = iterator.getCurrentVertexId().get(); long message = iterator.getCurrentMessage().get(); if (partitionMap.containsKey(vertexId)) { reusableVertexId.set(vertexId); reusableMessage.set(message); reusableCurrentMessage.set(partitionMap.get(vertexId)); messageCombiner.combine(reusableVertexId, reusableCurrentMessage, reusableMessage); message = reusableCurrentMessage.get(); } partitionMap.put(vertexId, message); } } }
From source file:org.apache.giraph.comm.messages.primitives.LongLongMessageStore.java
License:Apache License
@Override public boolean hasMessagesForVertex(LongWritable vertexId) { Long2LongOpenHashMap partitionMap = getPartitionMap(vertexId); if (partitionMap == null) { return false; }// w ww . j a v a 2s. co m synchronized (partitionMap) { return partitionMap.containsKey(vertexId.get()); } }
From source file:org.apache.giraph.comm.messages.primitives.LongLongMessageStore.java
License:Apache License
@Override public Iterable<LongWritable> getVertexMessages(LongWritable vertexId) throws IOException { Long2LongOpenHashMap partitionMap = getPartitionMap(vertexId); if (partitionMap == null) { return EmptyIterable.get(); }//w w w . j a va 2 s .c om // YH: must synchronize, as writes are concurrent w/ reads in async synchronized (partitionMap) { if (!partitionMap.containsKey(vertexId.get())) { return EmptyIterable.get(); } else { return Collections.singleton(new LongWritable(partitionMap.get(vertexId.get()))); } } }
From source file:org.apache.giraph.comm.messages.primitives.LongLongMessageStore.java
License:Apache License
@Override public Iterable<LongWritable> removeVertexMessages(LongWritable vertexId) throws IOException { Long2LongOpenHashMap partitionMap = getPartitionMap(vertexId); if (partitionMap == null) { return EmptyIterable.get(); }/* w ww.j a va2s . c om*/ // YH: must synchronize, as writes are concurrent w/ reads in async synchronized (partitionMap) { if (!partitionMap.containsKey(vertexId.get())) { return EmptyIterable.get(); } else { return Collections.singleton(new LongWritable(partitionMap.remove(vertexId.get()))); } } }
From source file:org.apache.giraph.comm.messages.primitives.LongLongMessageStore.java
License:Apache License
@Override public void clearVertexMessages(LongWritable vertexId) throws IOException { // YH: not used in async, but synchronize anyway Long2LongOpenHashMap partitionMap = getPartitionMap(vertexId); if (partitionMap == null) { return;//ww w . j a v a 2s . co m } synchronized (partitionMap) { partitionMap.remove(vertexId.get()); } }
From source file:org.apache.giraph.comm.messages.primitives.long_id.LongByteArrayMessageStore.java
License:Apache License
@Override public Iterable<M> getVertexMessages(LongWritable vertexId) throws IOException { DataInputOutput dataInputOutput = getPartitionMap(vertexId).get(vertexId.get()); if (dataInputOutput == null) { return EmptyIterable.get(); } else {/*from ww w .ja v a2 s. co m*/ return new MessagesIterable<M>(dataInputOutput, messageValueFactory); } }