1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.worker; |
20 | |
|
21 | |
import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable; |
22 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
23 | |
import org.apache.giraph.mapping.MappingStore; |
24 | |
import org.apache.giraph.mapping.MappingStoreOps; |
25 | |
import org.apache.hadoop.io.Writable; |
26 | |
import org.apache.hadoop.io.WritableComparable; |
27 | |
import org.apache.log4j.Logger; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
@SuppressWarnings("unchecked") |
38 | |
public class LocalData<I extends WritableComparable, V extends Writable, |
39 | |
E extends Writable, B extends Writable> |
40 | |
extends DefaultImmutableClassesGiraphConfigurable<I, V, E> { |
41 | |
|
42 | 0 | private static final Logger LOG = Logger.getLogger(LocalData.class); |
43 | |
|
44 | |
private MappingStore<I, B> mappingStore; |
45 | |
|
46 | |
private MappingStoreOps<I, B> mappingStoreOps; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | public LocalData(ImmutableClassesGiraphConfiguration<I, V, E> conf) { |
54 | |
|
55 | 0 | setConf(conf); |
56 | |
|
57 | 0 | mappingStore = (MappingStore<I, B>) getConf().createMappingStore(); |
58 | 0 | if (mappingStore != null) { |
59 | 0 | mappingStore.initialize(); |
60 | |
} |
61 | 0 | mappingStoreOps = (MappingStoreOps<I, B>) getConf().createMappingStoreOps(); |
62 | 0 | if (mappingStoreOps != null) { |
63 | 0 | mappingStoreOps.initialize(mappingStore); |
64 | |
} |
65 | 0 | } |
66 | |
|
67 | |
public MappingStore<I, B> getMappingStore() { |
68 | 0 | return mappingStore; |
69 | |
} |
70 | |
|
71 | |
public MappingStoreOps<I, B> getMappingStoreOps() { |
72 | 0 | return mappingStoreOps; |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public void removeMappingStoreIfPossible() { |
80 | 0 | if (mappingStoreOps != null && mappingStoreOps.hasEmbedding()) { |
81 | 0 | mappingStore = null; |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void printStats() { |
89 | 0 | if (LOG.isInfoEnabled()) { |
90 | 0 | LOG.info("MappingStore has : " + mappingStore.getStats() + " entries"); |
91 | |
} |
92 | 0 | } |
93 | |
} |