01: /* PersistOnlineProcessor.java
02: *
03: * Created on Feb 18, 2005
04: *
05: * Copyright (C) 2007 Internet Archive.
06: *
07: * This file is part of the Heritrix web crawler (crawler.archive.org).
08: *
09: * Heritrix is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU Lesser Public License as published by
11: * the Free Software Foundation; either version 2.1 of the License, or
12: * any later version.
13: *
14: * Heritrix is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * GNU Lesser Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser Public License
20: * along with Heritrix; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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: // TODO: share single store instance between Load and Store processors
60: // (shared context? EnhancedEnvironment?)
61: store = initStore();
62: }
63:
64: protected StoredSortedMap initStore() {
65: StoredSortedMap historyMap;
66: try {
67: EnhancedEnvironment env = getController()
68: .getBdbEnvironment();
69: StoredClassCatalog classCatalog = env.getClassCatalog();
70: DatabaseConfig dbConfig = historyDatabaseConfig();
71: historyDb = env.openDatabase(null, URI_HISTORY_DBNAME,
72: dbConfig);
73: historyMap = new StoredSortedMap(historyDb,
74: new StringBinding(), new SerialBinding(
75: classCatalog, AList.class), true);
76: } catch (DatabaseException e) {
77: throw new RuntimeException(e);
78: }
79: return historyMap;
80: }
81:
82: @Override
83: protected void finalTasks() {
84: try {
85: historyDb.sync();
86: historyDb.close();
87: } catch (DatabaseException e) {
88: // TODO Auto-generated catch block
89: throw new RuntimeException(e);
90: }
91: }
92:
93: }
|