List of usage examples for org.apache.hadoop.io LongWritable get
public long get()
From source file:org.apache.giraph.comm.messages.primitives.long_id.LongPointerListMessageStore.java
License:Apache License
@Override public Iterable<M> getVertexMessages(LongWritable vertexId) throws IOException { LongArrayList list = getPartitionMap(vertexId).get(vertexId.get()); if (list == null) { return EmptyIterable.get(); } else {//from w ww . j a v a 2s. c o m return new PointerListMessagesIterable<>(messageValueFactory, list, bytesBuffer); } }
From source file:org.apache.giraph.comm.messages.TestLongDoublePrimitiveMessageStores.java
License:Apache License
@Before public void prepare() throws IOException { service = Mockito.mock(CentralizedServiceWorker.class); Mockito.when(service.getPartitionId(Mockito.any(LongWritable.class))).thenAnswer(new Answer<Integer>() { @Override// w w w . ja v a2 s. c om public Integer answer(InvocationOnMock invocation) { LongWritable vertexId = (LongWritable) invocation.getArguments()[0]; return (int) (vertexId.get() % NUM_PARTITIONS); } }); PartitionStore partitionStore = Mockito.mock(PartitionStore.class); Mockito.when(service.getPartitionStore()).thenReturn(partitionStore); Mockito.when(partitionStore.getPartitionIds()).thenReturn(Lists.newArrayList(0, 1)); Partition partition = Mockito.mock(Partition.class); Mockito.when(partition.getVertexCount()).thenReturn(Long.valueOf(1)); Mockito.when(partitionStore.getOrCreatePartition(0)).thenReturn(partition); Mockito.when(partitionStore.getOrCreatePartition(1)).thenReturn(partition); }
From source file:org.apache.giraph.comm.messages.with_source.primitives.LongDoubleMessageWithSourceStore.java
License:Apache License
/** * If there is already a map of sources related to the destination * vertex id, then return that map. Otherwise create a new one, put it * in the partition map, and return it.//w w w. j a v a2s . co m * * @param partitionMap Message map for this partition * @param dstId Id of the destination vertex (receiver) * @return Source map for the destination vertex */ private Long2DoubleOpenHashMap getOrCreateSourceMap(Long2ObjectOpenHashMap<Long2DoubleOpenHashMap> partitionMap, LongWritable dstId) { synchronized (partitionMap) { Long2DoubleOpenHashMap srcMap = partitionMap.get(dstId.get()); if (srcMap == null) { // YH: can't use number of dstId's neighbours as hint, // b/c that counts its OUT-edges rather than IN-edges Long2DoubleOpenHashMap tmpMap = new Long2DoubleOpenHashMap(); srcMap = partitionMap.put(dstId.get(), tmpMap); if (srcMap == null) { srcMap = tmpMap; } } return srcMap; } }
From source file:org.apache.giraph.comm.messages.with_source.primitives.LongDoubleMessageWithSourceStore.java
License:Apache License
@Override public Iterable<DoubleWritable> getVertexMessagesWithoutSource(LongWritable vertexId) throws IOException { Long2ObjectOpenHashMap<Long2DoubleOpenHashMap> partitionMap = getPartitionMap(vertexId); if (partitionMap == null) { return EmptyIterable.get(); }//from w ww . j av a2s. c o m synchronized (partitionMap) { Long2DoubleOpenHashMap srcMap = partitionMap.get(vertexId.get()); if (srcMap == null) { return EmptyIterable.get(); } else { return new DoubleMessagesIterable(srcMap); } } }
From source file:org.apache.giraph.comm.messages.with_source.primitives.LongDoubleMessageWithSourceStore.java
License:Apache License
@Override public void clearVertexMessages(LongWritable vertexId) throws IOException { // YH: not used in async, but synchronize anyway Long2ObjectOpenHashMap<?> partitionMap = getPartitionMap(vertexId); if (partitionMap == null) { return;//from w w w.j av a2 s . c o m } synchronized (partitionMap) { partitionMap.remove(vertexId.get()); } }
From source file:org.apache.giraph.comm.requests.SendWorkerAggregatorsRequest.java
License:Apache License
@Override public void doRequest(ServerData serverData) { DataInput input = getDataInput(); OwnerAggregatorServerData aggregatorData = serverData.getOwnerAggregatorData(); try {/*from w w w .ja v a2 s .co m*/ int num = input.readInt(); for (int i = 0; i < num; i++) { String name = input.readUTF(); GlobalCommType type = GlobalCommType.values()[input.readByte()]; if (type == GlobalCommType.SPECIAL_COUNT) { LongWritable value = new LongWritable(); value.readFields(input); aggregatorData.receivedRequestCountFromWorker(value.get(), getSenderTaskId()); } else if (type == GlobalCommType.REDUCED_VALUE) { Writable value = aggregatorData.createInitialValue(name); value.readFields(input); aggregatorData.reduce(name, value); } else { throw new IllegalStateException("SendWorkerAggregatorsRequest received " + type); } } } catch (IOException e) { throw new IllegalStateException("doRequest: " + "IOException occurred while processing request", e); } aggregatorData.receivedRequestFromWorker(); }
From source file:org.apache.giraph.conf.TestObjectCreation.java
License:Apache License
@Test public void testCreateClass() { startNanos = TIME.getNanoseconds();// w w w .ja v a2 s. c o m for (int i = 0; i < COUNT; ++i) { LongWritable value = configuration.createVertexValue(); value.set(i); total += value.get(); } }
From source file:org.apache.giraph.conf.TestObjectCreation.java
License:Apache License
@Test public void testNativeCreateClass() { startNanos = TIME.getNanoseconds();// w ww.ja va2s .c o m for (int i = 0; i < COUNT; ++i) { LongWritable value = new LongWritable(); value.set(i); total += value.get(); } }
From source file:org.apache.giraph.conf.TestObjectCreation.java
License:Apache License
@Test public void testNewInstance() throws IllegalAccessException, InstantiationException { startNanos = TIME.getNanoseconds();// www .j a v a 2 s . c o m for (int i = 0; i < COUNT; ++i) { LongWritable value = (LongWritable) getLongWritableClass().newInstance(); value.set(i); total += value.get(); } }
From source file:org.apache.giraph.conf.TestObjectCreation.java
License:Apache License
@Test public void testSyncNewInstance() throws IllegalAccessException, InstantiationException { startNanos = TIME.getNanoseconds();/* w w w. j a v a2s . c o m*/ for (int i = 0; i < COUNT; ++i) { LongWritable value = (LongWritable) getSyncLongWritableClass().newInstance(); value.set(i); total += value.get(); } }