Package de.jungblut.crawl
Class FetchResultPersister<T extends FetchResult>
- java.lang.Object
-
- de.jungblut.crawl.FetchResultPersister<T>
-
- All Implemented Interfaces:
java.lang.Runnable
public final class FetchResultPersister<T extends FetchResult> extends java.lang.Object implements java.lang.RunnableAsynchronous persister thread, taking a resultwriter and handles the logic behind asynchronous writing to disk or an arbitrary sink implemented by theResultWriter. The lifecycle is the following, you can submit an instance of this class as a thread and if you want to stop it you can call thestop()method. Then it will make the backed queue read-only and flush all items in it to the result writer.- Author:
- thomas.jungblut
-
-
Constructor Summary
Constructors Constructor Description FetchResultPersister(ResultWriter<T> resWriter)FetchResultPersister(ResultWriter<T> resWriter, org.apache.hadoop.conf.Configuration conf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T result)Add a crawled result to the back queue.voidrun()Run logic of thisRunnable.voidstop()Stop this persister and make the queue read-only.
-
-
-
Constructor Detail
-
FetchResultPersister
public FetchResultPersister(ResultWriter<T> resWriter) throws java.io.IOException
- Throws:
java.io.IOException
-
FetchResultPersister
public FetchResultPersister(ResultWriter<T> resWriter, org.apache.hadoop.conf.Configuration conf) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
add
public final void add(T result)
Add a crawled result to the back queue. Notice that afterstop()has been called, this queue will not accept any items anymore.
-
stop
public void stop()
Stop this persister and make the queue read-only.
-
run
public final void run()
Run logic of thisRunnable. Basically if we haven't stopped, we will poll the queue, if there is no item anymore we will wait for 10 seconds. If we have received astop()command, the queue will be freezed and all exisiting items will be flushed to disk.ResultWriterclose is guaranteed to run in case of failure (guarded by finally).- Specified by:
runin interfacejava.lang.Runnable
-
-