1
|
package edu.ucsb.nceas.metacat.dataone.hazelcast;
|
2
|
|
3
|
import java.util.Collection;
|
4
|
import java.util.HashMap;
|
5
|
import java.util.HashSet;
|
6
|
import java.util.Map;
|
7
|
import java.util.Set;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.dataone.service.types.v1.Identifier;
|
11
|
import org.dataone.service.types.v1.ObjectInfo;
|
12
|
import org.dataone.service.types.v1.ObjectList;
|
13
|
import org.dataone.service.types.v1.SystemMetadata;
|
14
|
|
15
|
import com.hazelcast.core.MapLoader;
|
16
|
import com.hazelcast.core.MapStore;
|
17
|
|
18
|
import edu.ucsb.nceas.metacat.IdentifierManager;
|
19
|
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
|
20
|
import edu.ucsb.nceas.metacat.dataone.CNodeService;
|
21
|
|
22
|
/**
|
23
|
* Storage implementation for Hazelcast System Metadata
|
24
|
* @author leinfelder
|
25
|
*
|
26
|
*/
|
27
|
public class SystemMetadataMap
|
28
|
implements MapStore<Identifier, SystemMetadata>, MapLoader<Identifier, SystemMetadata> {
|
29
|
|
30
|
private Logger logMetacat = null;
|
31
|
|
32
|
@Override
|
33
|
public void delete(Identifier arg0) {
|
34
|
// we do not delete system metadata
|
35
|
}
|
36
|
|
37
|
@Override
|
38
|
public void deleteAll(Collection<Identifier> arg0) {
|
39
|
// we do not delete system metadata
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public void store(Identifier pid, SystemMetadata sm) {
|
44
|
try {
|
45
|
//System.out.println("Storing System Metadata to store: " + pid.getValue());
|
46
|
if (!IdentifierManager.getInstance().systemMetadataExists(pid.getValue())) {
|
47
|
IdentifierManager.getInstance().createSystemMetadata(sm);
|
48
|
} else {
|
49
|
IdentifierManager.getInstance().updateSystemMetadata(sm);
|
50
|
}
|
51
|
} catch (McdbDocNotFoundException e) {
|
52
|
throw new RuntimeException(e.getMessage(), e);
|
53
|
}
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public void storeAll(Map<Identifier, SystemMetadata> map) {
|
58
|
for (Identifier key: map.keySet()) {
|
59
|
store(key, map.get(key));
|
60
|
}
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public SystemMetadata load(Identifier pid) {
|
65
|
SystemMetadata sm = null;
|
66
|
logMetacat = Logger.getLogger(SystemMetadataMap.class);
|
67
|
|
68
|
try {
|
69
|
logMetacat.debug("loading from store: " + pid.getValue());
|
70
|
sm = IdentifierManager.getInstance().getSystemMetadata(pid.getValue());
|
71
|
} catch (McdbDocNotFoundException e) {
|
72
|
//throw new RuntimeException(e.getMessage(), e);
|
73
|
// not found => null
|
74
|
return null;
|
75
|
}
|
76
|
catch (Exception e) {
|
77
|
throw new RuntimeException(e.getMessage(), e);
|
78
|
}
|
79
|
return sm;
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public Map<Identifier, SystemMetadata> loadAll(Collection<Identifier> keys) {
|
84
|
Map<Identifier, SystemMetadata> map = new HashMap<Identifier, SystemMetadata>();
|
85
|
for (Identifier key: keys) {
|
86
|
SystemMetadata value = load(key);
|
87
|
map.put(key, value);
|
88
|
}
|
89
|
return map;
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public Set<Identifier> loadAllKeys() {
|
94
|
Set<Identifier> pids = new HashSet<Identifier>();
|
95
|
try {
|
96
|
ObjectList ol = IdentifierManager.getInstance().querySystemMetadata(
|
97
|
null, //startTime,
|
98
|
null, //endTime,
|
99
|
null, //objectFormatId,
|
100
|
false, //replicaStatus,
|
101
|
0, //start,
|
102
|
-1 //count
|
103
|
);
|
104
|
for (ObjectInfo o: ol.getObjectInfoList()) {
|
105
|
Identifier pid = o.getIdentifier();
|
106
|
pids.add(pid);
|
107
|
}
|
108
|
} catch (Exception e) {
|
109
|
throw new RuntimeException(e.getMessage(), e);
|
110
|
}
|
111
|
|
112
|
return pids;
|
113
|
}
|
114
|
|
115
|
}
|