mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-15 10:20:47 +00:00
Make Recorder facility usable independent of special crawler threads
* Recorder.java
store reusable per-thread Recorder instance in Recorder static thread-local
* ToeThread.java
setup reusable instance into Recorder
* RecorderMarker.java
deleted -- unnecessary
This commit is contained in:
1 parent
f35da10154
commit
248f720cab
3 files changed
+10
-52
No files matched your search
@@ -251,6 +251,13 @@ public class Recorder {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ThreadLocal<Recorder> currentRecorder = new ThreadLocal<Recorder>();
|
||||
|
||||
public static void setHttpRecorder(Recorder httpRecorder) {
|
||||
currentRecorder.set(httpRecorder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current threads' HttpRecorder.
|
||||
*
|
||||
@@ -258,12 +265,7 @@ public class Recorder {
|
||||
* HttpRecorder in current instance.
|
||||
*/
|
||||
public static Recorder getHttpRecorder() {
|
||||
Recorder recorder = null;
|
||||
Thread thread = Thread.currentThread();
|
||||
if (thread instanceof RecorderMarker) {
|
||||
recorder = ((RecorderMarker)thread).getHttpRecorder();
|
||||
}
|
||||
return recorder;
|
||||
return currentRecorder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
|
||||
/**
|
||||
* A marker interface to denote a class with a gettable HttpRecorder.
|
||||
*
|
||||
* @author stack
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface RecorderMarker
|
||||
{
|
||||
/**
|
||||
* @return An instance of HttpRecorder.
|
||||
*/
|
||||
public Recorder getHttpRecorder();
|
||||
}
|
||||
@@ -45,7 +45,6 @@ import org.archive.util.DevUtils;
|
||||
import org.archive.util.MultiReporter;
|
||||
import org.archive.util.ProgressStatisticsReporter;
|
||||
import org.archive.util.Recorder;
|
||||
import org.archive.util.RecorderMarker;
|
||||
|
||||
import com.sleepycat.util.RuntimeExceptionWrapper;
|
||||
|
||||
@@ -56,7 +55,7 @@ import com.sleepycat.util.RuntimeExceptionWrapper;
|
||||
* @author Gordon Mohr
|
||||
*/
|
||||
public class ToeThread extends Thread
|
||||
implements RecorderMarker, MultiReporter, ProgressStatisticsReporter,
|
||||
implements MultiReporter, ProgressStatisticsReporter,
|
||||
HostResolver, SinkHandlerLogThread, ChainStatusReceiver {
|
||||
|
||||
public enum Step {
|
||||
@@ -123,6 +122,7 @@ implements RecorderMarker, MultiReporter, ProgressStatisticsReporter,
|
||||
public void run() {
|
||||
String name = controller.getMetadata().getJobName();
|
||||
logger.fine(getName()+" started for order '"+name+"'");
|
||||
Recorder.setHttpRecorder(httpRecorder);
|
||||
|
||||
try {
|
||||
while ( true ) {
|
||||
@@ -303,16 +303,6 @@ implements RecorderMarker, MultiReporter, ProgressStatisticsReporter,
|
||||
public int getSerialNumber() {
|
||||
return this.serialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get current threads HttpRecorder instance.
|
||||
* Implementation of the HttpRecorderMarker interface.
|
||||
* @return Returns instance of HttpRecorder carried by this thread.
|
||||
* @see org.archive.util.RecorderMarker#getHttpRecorder()
|
||||
*/
|
||||
public Recorder getHttpRecorder() {
|
||||
return this.httpRecorder;
|
||||
}
|
||||
|
||||
/** Get the CrawlController acossiated with this thread.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user