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.worker;
2021import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable;
22import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
23import org.apache.giraph.mapping.MappingStore;
24import org.apache.giraph.mapping.MappingStoreOps;
25import org.apache.hadoop.io.Writable;
26import org.apache.hadoop.io.WritableComparable;
27import org.apache.log4j.Logger;
2829/**30 * Stores LocalData for each worker31 *32 * @param <I> vertexId type33 * @param <V> vertex value type34 * @param <E> edge value type35 * @param <B> mappingTarget type36 */37 @SuppressWarnings("unchecked")
38publicclass LocalData<I extends WritableComparable, V extends Writable,
39 E extends Writable, B extends Writable>
40extends DefaultImmutableClassesGiraphConfigurable<I, V, E> {
41/** Logger Instance */42privatestaticfinal Logger LOG = Logger.getLogger(LocalData.class);
43/**MappingStore from vertexId - target */44private MappingStore<I, B> mappingStore;
45/** Do operations using mapping store */46private MappingStoreOps<I, B> mappingStoreOps;
47/**48 * Constructor49 *50 * Set configuration, create & initialize mapping store51 * @param conf giraph configuration52 */53publicLocalData(ImmutableClassesGiraphConfiguration<I, V, E> conf) {
54// set configuration55 setConf(conf);
56// check if user set the mapping store => create & initialize it57 mappingStore = (MappingStore<I, B>) getConf().createMappingStore();
58if (mappingStore != null) {
59 mappingStore.initialize();
60 }
61 mappingStoreOps = (MappingStoreOps<I, B>) getConf().createMappingStoreOps();
62if (mappingStoreOps != null) {
63 mappingStoreOps.initialize(mappingStore);
64 }
65 }
6667public MappingStore<I, B> getMappingStore() {
68return mappingStore;
69 }
7071public MappingStoreOps<I, B> getMappingStoreOps() {
72return mappingStoreOps;
73 }
7475/**76 * Remove mapping store from localData77 * if mapping data is already embedded into vertexIds78 */79publicvoid removeMappingStoreIfPossible() {
80if (mappingStoreOps != null && mappingStoreOps.hasEmbedding()) {
81 mappingStore = null;
82 }
83 }
8485/**86 * Prints Stats of individual data it stores87 */88publicvoid printStats() {
89if (LOG.isInfoEnabled()) {
90 LOG.info("MappingStore has : " + mappingStore.getStats() + " entries");
91 }
92 }
93 }