From 25a91552987960650f9f7035329404d4aea005ba Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Tue, 25 Sep 2012 13:38:25 -0700 Subject: [PATCH] New parent class AbstractContentDigestHistory for implementations to extend * AbstractContentDigestHistory.java abstract methods load(), store(); non-abstract persistKeyFor(); javadocs * BdbContentDigestHistory.java extend AbstractContentDigestHistory * ContentDigestHistoryLoader.java, ContentDigestHistoryStorer.java use AbstractContentDigestHistory --- .../recrawl/AbstractContentDigestHistory.java | 59 +++++++++++++++++++ .../recrawl/BdbContentDigestHistory.java | 6 +- .../recrawl/ContentDigestHistoryLoader.java | 4 +- .../recrawl/ContentDigestHistoryStorer.java | 4 +- 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 modules/src/main/java/org/archive/modules/recrawl/AbstractContentDigestHistory.java diff --git a/modules/src/main/java/org/archive/modules/recrawl/AbstractContentDigestHistory.java b/modules/src/main/java/org/archive/modules/recrawl/AbstractContentDigestHistory.java new file mode 100644 index 00000000..e0f39934 --- /dev/null +++ b/modules/src/main/java/org/archive/modules/recrawl/AbstractContentDigestHistory.java @@ -0,0 +1,59 @@ +/* + * This file is part of the Heritrix web crawler (crawler.archive.org). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.modules.recrawl; + +import org.archive.modules.CrawlURI; + +/** + * Represents a store of information, presumably persistent, keyed by content + * digest. + * + * @contributor nlevitt + */ +public abstract class AbstractContentDigestHistory { + /** + * Looks up the history by key {@code persistKeyFor(curi)} and loads it into + * {@code curi.getContentDigestHistory()}. + * + * @param curi + */ + public abstract void load(CrawlURI curi); + + /** + * Stores {@code curi.getContentDigestHistory()} for the key + * {@code persistKeyFor(curi)}. + * + * @param curi + */ + public abstract void store(CrawlURI curi); + + /** + * + * @param curi + * @return {@code curi.getContentDigestSchemeString()} + * @throws IllegalStateException if {@code curi.getContentDigestSchemeString()} is null + */ + protected String persistKeyFor(CrawlURI curi) { + String key = curi.getContentDigestSchemeString(); + if (key == null) { + throw new IllegalStateException("cannot load content digest history, CrawlURI does not have content digest value for " + curi); + } + return key; + } +} diff --git a/modules/src/main/java/org/archive/modules/recrawl/BdbContentDigestHistory.java b/modules/src/main/java/org/archive/modules/recrawl/BdbContentDigestHistory.java index 7d1c902a..81fc9f35 100644 --- a/modules/src/main/java/org/archive/modules/recrawl/BdbContentDigestHistory.java +++ b/modules/src/main/java/org/archive/modules/recrawl/BdbContentDigestHistory.java @@ -35,7 +35,7 @@ import com.sleepycat.je.Database; import com.sleepycat.je.DatabaseException; /** Needs to be a toplevel bean for Lifecyle? */ -public class BdbContentDigestHistory implements Lifecycle { +public class BdbContentDigestHistory extends AbstractContentDigestHistory implements Lifecycle { private static final Logger logger = Logger.getLogger(BdbContentDigestHistory.class.getName()); @@ -58,10 +58,6 @@ public class BdbContentDigestHistory implements Lifecycle { protected StoredSortedMap store; protected Database historyDb; - protected String persistKeyFor(CrawlURI curi) { - return curi.getContentDigestSchemeString(); - } - @Override @SuppressWarnings({"rawtypes"}) public void start() { diff --git a/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryLoader.java b/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryLoader.java index 8ec9a52a..2f0f13cf 100644 --- a/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryLoader.java +++ b/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryLoader.java @@ -24,10 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; public class ContentDigestHistoryLoader extends Processor { - protected BdbContentDigestHistory contentDigestHistory; + protected AbstractContentDigestHistory contentDigestHistory; @Autowired public void setContentDigestHistory( - BdbContentDigestHistory contentDigestHistory) { + AbstractContentDigestHistory contentDigestHistory) { this.contentDigestHistory = contentDigestHistory; } diff --git a/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryStorer.java b/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryStorer.java index 0462b90a..f0c779ed 100644 --- a/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryStorer.java +++ b/modules/src/main/java/org/archive/modules/recrawl/ContentDigestHistoryStorer.java @@ -24,10 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; public class ContentDigestHistoryStorer extends Processor { - protected BdbContentDigestHistory contentDigestHistory; + protected AbstractContentDigestHistory contentDigestHistory; @Autowired public void setContentDigestHistory( - BdbContentDigestHistory contentDigestHistory) { + AbstractContentDigestHistory contentDigestHistory) { this.contentDigestHistory = contentDigestHistory; }