From bdd7f7e1abe5106a3acc4620564d7baaa0fdb9ea Mon Sep 17 00:00:00 2001 From: gojomo Date: Fri, 7 Jan 2011 01:24:38 +0000 Subject: [PATCH] Fix exceptions at launch, post-crawl-finish * KryoBinding.java always default to registrationOptional, for now * StatisticsTracker.java explicitly set valueClass of sourceDistribution to ConcurrentHashMap * StoredQueue.java answer 0 for size() when backing DB closed --- commons/src/main/java/org/archive/bdb/KryoBinding.java | 2 ++ commons/src/main/java/org/archive/bdb/StoredQueue.java | 6 +++++- .../archive/crawler/reporting/StatisticsTracker.java | 10 +++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/commons/src/main/java/org/archive/bdb/KryoBinding.java b/commons/src/main/java/org/archive/bdb/KryoBinding.java index afe2bdda..e9202d46 100644 --- a/commons/src/main/java/org/archive/bdb/KryoBinding.java +++ b/commons/src/main/java/org/archive/bdb/KryoBinding.java @@ -53,6 +53,8 @@ public class KryoBinding implements EntryBinding { public KryoBinding(Class baseClass) { this.baseClass = baseClass; kryo.autoregister(baseClass); + // TODO: reevaluate if explicit registration should be required + kryo.setRegistrationOptional(true); } public Kryo getKryo() { diff --git a/commons/src/main/java/org/archive/bdb/StoredQueue.java b/commons/src/main/java/org/archive/bdb/StoredQueue.java index 636784e5..d45bbb15 100644 --- a/commons/src/main/java/org/archive/bdb/StoredQueue.java +++ b/commons/src/main/java/org/archive/bdb/StoredQueue.java @@ -91,7 +91,11 @@ public class StoredQueue extends AbstractQueue { @Override public int size() { - return queueMap.size(); + try { + return queueMap.size(); + } catch (IllegalStateException ise) { + return 0; + } } @Override diff --git a/engine/src/main/java/org/archive/crawler/reporting/StatisticsTracker.java b/engine/src/main/java/org/archive/crawler/reporting/StatisticsTracker.java index f84519b2..8c6f9950 100644 --- a/engine/src/main/java/org/archive/crawler/reporting/StatisticsTracker.java +++ b/engine/src/main/java/org/archive/crawler/reporting/StatisticsTracker.java @@ -332,8 +332,8 @@ public class StatisticsTracker /** Keep track of URL counts per host per seed */ @SuppressWarnings("unchecked") - protected ObjectIdentityCache sourceHostDistribution = - new ObjectIdentityMemCache(); // temp dummy; + protected ObjectIdentityCache sourceHostDistribution = + new ObjectIdentityMemCache(); // temp dummy; /* Keep track of 'top' hosts for live reports */ protected TopNSet hostsDistributionTop; @@ -367,7 +367,7 @@ public class StatisticsTracker boolean isRecover = (recoveryCheckpoint != null); try { this.sourceHostDistribution = bdb.getObjectCache("sourceHostDistribution", - isRecover, ConcurrentMap.class); + isRecover, ConcurrentHashMap.class); this.hostsDistribution = bdb.getObjectCache("hostsDistribution", isRecover, AtomicLong.class); this.hostsBytes = bdb.getObjectCache("hostsBytes", @@ -851,8 +851,8 @@ public class StatisticsTracker ConcurrentMap hostUriCount = sourceHostDistribution.getOrUse( source, - new Supplier() { - public ConcurrentMap get() { + new Supplier() { + public ConcurrentHashMap get() { return new ConcurrentHashMap(); }}); incrementMapCount(hostUriCount, hostname);