1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.crawler.processor.recrawl;
24
25 import org.archive.util.bdbje.EnhancedEnvironment;
26
27 import st.ata.util.AList;
28
29 import com.sleepycat.bind.serial.SerialBinding;
30 import com.sleepycat.bind.serial.StoredClassCatalog;
31 import com.sleepycat.bind.tuple.StringBinding;
32 import com.sleepycat.collections.StoredSortedMap;
33 import com.sleepycat.je.Database;
34 import com.sleepycat.je.DatabaseConfig;
35 import com.sleepycat.je.DatabaseException;
36
37 /***
38 * Common superclass for persisting Processors which directly store/load
39 * to persistence (as opposed to logging for batch load later).
40 * @author gojomo
41 */
42 public abstract class PersistOnlineProcessor extends PersistProcessor {
43 private static final long serialVersionUID = -666479480942267268L;
44
45 protected StoredSortedMap store;
46 protected Database historyDb;
47
48 /***
49 * Usual constructor
50 *
51 * @param name
52 * @param string
53 */
54 public PersistOnlineProcessor(String name, String string) {
55 super(name, string);
56 }
57
58 protected void initialTasks() {
59
60
61 store = initStore();
62 }
63
64 protected StoredSortedMap initStore() {
65 StoredSortedMap historyMap;
66 try {
67 EnhancedEnvironment env = getController().getBdbEnvironment();
68 StoredClassCatalog classCatalog = env.getClassCatalog();
69 DatabaseConfig dbConfig = historyDatabaseConfig();
70 historyDb = env.openDatabase(null, URI_HISTORY_DBNAME, dbConfig);
71 historyMap = new StoredSortedMap(historyDb,
72 new StringBinding(), new SerialBinding(classCatalog,
73 AList.class), true);
74 } catch (DatabaseException e) {
75 throw new RuntimeException(e);
76 }
77 return historyMap;
78 }
79
80 @Override
81 protected void finalTasks() {
82 try {
83 historyDb.sync();
84 historyDb.close();
85 } catch (DatabaseException e) {
86
87 throw new RuntimeException(e);
88 }
89 }
90
91 }