mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-09 07:24:41 +00:00
more rapidly release refs for finished CrawlURIs
* UriProcessingFormatter, Preformatter, GenerationFileHandler
improve preformat-outside-synchronized optimization so that the LogRecord/CrawlURI doesn't linger until next displaces it
* CrawlURI
(processingCleanup) null more of last-processing-run collected values
This commit is contained in:
1 parent
c84e87c648
commit
6a3072ef46
4 files changed
+66
-11
No files matched your search
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.crawler.io;
|
||||
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Interface indicating a logging Formatter can preformat a record (outside
|
||||
* the standard-implementation synchronized block) and cache it, returning it
|
||||
* for the next request for formatting from the same thread.
|
||||
* @contributor gojomo
|
||||
*/
|
||||
public interface Preformatter {
|
||||
public void preformat(LogRecord record);
|
||||
public void clear();
|
||||
}
|
||||
@@ -34,7 +34,7 @@ import org.archive.util.MimetypeUtils;
|
||||
* @author gojomo
|
||||
*/
|
||||
public class UriProcessingFormatter
|
||||
extends Formatter implements CoreAttributeConstants {
|
||||
extends Formatter implements Preformatter, CoreAttributeConstants {
|
||||
private final static String NA = "-";
|
||||
/**
|
||||
* Guess at line length (URIs are assumed avg. of 128 bytes).
|
||||
@@ -57,7 +57,6 @@ extends Formatter implements CoreAttributeConstants {
|
||||
}
|
||||
};
|
||||
|
||||
protected final ThreadLocal<LogRecord> cachedRecord = new ThreadLocal<LogRecord>();
|
||||
protected final ThreadLocal<String> cachedFormat = new ThreadLocal<String>();
|
||||
protected boolean logExtraInfo;
|
||||
|
||||
@@ -66,7 +65,7 @@ extends Formatter implements CoreAttributeConstants {
|
||||
}
|
||||
|
||||
public String format(LogRecord lr) {
|
||||
if(lr==cachedRecord.get()) {
|
||||
if(cachedFormat.get()!=null) {
|
||||
return cachedFormat.get();
|
||||
}
|
||||
CrawlURI curi = (CrawlURI)lr.getParameters()[0];
|
||||
@@ -153,10 +152,7 @@ extends Formatter implements CoreAttributeConstants {
|
||||
}
|
||||
|
||||
buffer.append("\n");
|
||||
cachedRecord.set(lr);
|
||||
String formatted = buffer.toString();
|
||||
cachedFormat.set(formatted);
|
||||
return formatted;
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +162,16 @@ extends Formatter implements CoreAttributeConstants {
|
||||
protected String checkForNull(String str) {
|
||||
return (str == null || str.length() <= 0)? NA: str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
cachedFormat.set(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preformat(LogRecord record) {
|
||||
cachedFormat.set(format(record));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user