|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.netarkivet.common.utils.batch.FileBatchJob
public abstract class FileBatchJob
Interface defining a batch job to run on a set of files. The job is initialized by calling initialize(), executed on a file by calling processFile() and any cleanup is handled by finish().
Nested Class Summary | |
---|---|
static class |
FileBatchJob.ExceptionOccurrence
This class holds the information about exceptions that occurred in a batchjob. |
Field Summary | |
---|---|
protected long |
batchJobTimeout
If positiv it is the timeout of specific Batch Job in miliseconds. |
protected java.util.List<FileBatchJob.ExceptionOccurrence> |
exceptions
A list with information about the exceptions thrown during the execution of the batchjob. |
protected java.util.Set<java.io.File> |
filesFailed
A Set of files which generated errors. |
protected int |
noOfFilesProcessed
The total number of files processed (including any that generated errors). |
Constructor Summary | |
---|---|
FileBatchJob()
|
Method Summary | |
---|---|
protected void |
addException(java.io.File currentFile,
long currentOffset,
long outputOffset,
java.lang.Exception e)
Record an exception that occurred during the processFile of this job and that should be returned with the result. |
protected void |
addFinishException(long outputOffset,
java.lang.Exception e)
Record an exception that occurred during the finish() method of this job. |
protected void |
addInitializeException(long outputOffset,
java.lang.Exception e)
Record an exception that occurred during the initialize() method of this job. |
abstract void |
finish(java.io.OutputStream os)
Finish up the job. |
long |
getBatchJobTimeout()
Getter for batchJobTimeout. |
java.util.List<FileBatchJob.ExceptionOccurrence> |
getExceptions()
Get the list of exceptions that have occurred during processing. |
java.util.regex.Pattern |
getFilenamePattern()
Get the pattern for files that should be processed. |
java.util.Collection<java.io.File> |
getFilesFailed()
Return the list of names of files where processing failed. |
int |
getNoOfFilesProcessed()
Return the number of files processed in this job. |
abstract void |
initialize(java.io.OutputStream os)
Initialize the job before runnning. |
protected boolean |
maxExceptionsReached()
Returns true if we have already recorded the maximum number of exceptions. |
boolean |
postProcess(java.io.InputStream input,
java.io.OutputStream output)
Processes the concatenated result files. |
abstract boolean |
processFile(java.io.File file,
java.io.OutputStream os)
Process one file stored in the bit archive. |
void |
processOnlyFileNamed(java.lang.String specifiedFilename)
Helper method for only processing one file. |
void |
processOnlyFilesMatching(java.util.List<java.lang.String> specifiedPatterns)
Set this job to match only a certain set of patterns. |
void |
processOnlyFilesMatching(java.lang.String specifiedPattern)
Set this job to match only a certain pattern. |
void |
processOnlyFilesNamed(java.util.List<java.lang.String> specifiedFilenames)
Mark the job to process only the specified files. |
void |
setBatchJobTimeout(long batchJobTimeout)
Override predefined timeout period for batchjob |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int noOfFilesProcessed
protected long batchJobTimeout
protected java.util.Set<java.io.File> filesFailed
protected java.util.List<FileBatchJob.ExceptionOccurrence> exceptions
Constructor Detail |
---|
public FileBatchJob()
Method Detail |
---|
public abstract void initialize(java.io.OutputStream os)
os
- the OutputStream to which output should be writtenpublic abstract boolean processFile(java.io.File file, java.io.OutputStream os)
file
- the file to be processed.os
- the OutputStream to which output should be written
public abstract void finish(java.io.OutputStream os)
os
- the OutputStream to which output should be writtenpublic void processOnlyFilesNamed(java.util.List<java.lang.String> specifiedFilenames)
specifiedFilenames
- A list of filenamess to process (without
paths). If null, all files will be processed.public void processOnlyFileNamed(java.lang.String specifiedFilename)
specifiedFilename
- The name of the single file that should
be processed. Should not include any path information.public void processOnlyFilesMatching(java.util.List<java.lang.String> specifiedPatterns)
specifiedPatterns
- The patterns of file names that this job
will operate on. These should not include any path information, but
should match the entire filename (e.g. .*foo.* for any file with foo in
the name).public void processOnlyFilesMatching(java.lang.String specifiedPattern)
specifiedPattern
- Regular expression of file names that this job
will operate on. This should not include any path information, but should
match the entire filename (e.g. .*foo.* for any file with foo in the
name).public java.util.regex.Pattern getFilenamePattern()
public int getNoOfFilesProcessed()
public java.util.Collection<java.io.File> getFilesFailed()
public java.util.List<FileBatchJob.ExceptionOccurrence> getExceptions()
public boolean postProcess(java.io.InputStream input, java.io.OutputStream output)
input
- The inputstream to the file containing the concatenated
results.output
- The outputstream where the resulting data should be
written.
ArgumentNotValid
- If the concatenated file is null.protected void addException(java.io.File currentFile, long currentOffset, long outputOffset, java.lang.Exception e)
currentFile
- The file that is currently being processed.currentOffset
- The relevant offset into the file when the
exception happened (e.g. the start of an ARC record).outputOffset
- The offset we were at in the outputstream when the
exception happened. If UNKNOWN_OFFSET, the offset could not be found.e
- The exception thrown. This exception must be serializable.protected void addInitializeException(long outputOffset, java.lang.Exception e)
outputOffset
- The offset we were at in the outputstream when the
exception happened. If UNKNOWN_OFFSET, the offset could not be found.e
- The exception thrown. This exception must be serializable.protected void addFinishException(long outputOffset, java.lang.Exception e)
outputOffset
- The offset we were at in the outputstream when the
exception happened. If UNKNOWN_OFFSET, the offset could not be found.e
- The exception thrown. This exception must be serializable.public long getBatchJobTimeout()
protected boolean maxExceptionsReached()
public void setBatchJobTimeout(long batchJobTimeout)
batchJobTimeout
- timout period
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |