1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.edge;
2021import org.apache.giraph.bsp.CentralizedServiceWorker;
22import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
23import org.apache.giraph.edge.primitives.IntEdgeStore;
24import org.apache.giraph.edge.primitives.LongEdgeStore;
25import org.apache.hadoop.io.IntWritable;
26import org.apache.hadoop.io.LongWritable;
27import org.apache.hadoop.io.Writable;
28import org.apache.hadoop.io.WritableComparable;
29import org.apache.hadoop.util.Progressable;
3031/**32 * Edge store factory which produces message stores which hold all33 * edges in memory. It creates primitive edges stores when vertex id is34 * IntWritable or LongWritable35 *36 * @param <I> Vertex id37 * @param <V> Vertex value38 * @param <E> Edge value39 */40 @SuppressWarnings("unchecked")
41publicclass InMemoryEdgeStoreFactory<I extends WritableComparable,
42 V extends Writable, E extends Writable>
43implements EdgeStoreFactory<I, V, E> {
44/** Service worker. */45protected CentralizedServiceWorker<I, V, E> service;
46/** Giraph configuration. */47protected ImmutableClassesGiraphConfiguration<I, V, E> conf;
48/** Progressable to report progress. */49protected Progressable progressable;
5051 @Override
52public EdgeStore<I, V, E> newStore() {
53 Class<I> vertexIdClass = conf.getVertexIdClass();
54 EdgeStore<I, V, E> edgeStore;
55if (vertexIdClass.equals(IntWritable.class)) {
56 edgeStore = (EdgeStore<I, V, E>) new IntEdgeStore<>(
57 (CentralizedServiceWorker<IntWritable, V, E>) service,
58 (ImmutableClassesGiraphConfiguration<IntWritable, V, E>) conf,
59 progressable);
60 } elseif (vertexIdClass.equals(LongWritable.class)) {
61 edgeStore = (EdgeStore<I, V, E>) new LongEdgeStore<>(
62 (CentralizedServiceWorker<LongWritable, V, E>) service,
63 (ImmutableClassesGiraphConfiguration<LongWritable, V, E>) conf,
64 progressable);
65 } else {
66 edgeStore = new SimpleEdgeStore<>(service, conf, progressable);
67 }
68return edgeStore;
69 }
7071 @Override
72publicvoid initialize(CentralizedServiceWorker<I, V, E> service,
73 ImmutableClassesGiraphConfiguration<I, V, E> conf,
74 Progressable progressable) {
75this.service = service;
76this.conf = conf;
77this.progressable = progressable;
78 }
79 }