public abstract class FileBatchJob extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
FileBatchJob.ExceptionOccurrence
This class holds the information about exceptions that occurred in a batchjob.
|
Modifier and Type | Field and Description |
---|---|
protected long |
batchJobTimeout
If positiv it is the timeout of specific Batch Job in miliseconds.
|
protected List<FileBatchJob.ExceptionOccurrence> |
exceptions
A list with information about the exceptions thrown during the execution of the batchjob.
|
protected Set<File> |
filesFailed
A Set of files which generated errors.
|
protected int |
noOfFilesProcessed
The total number of files processed (including any that generated errors).
|
Constructor and Description |
---|
FileBatchJob() |
Modifier and Type | Method and Description |
---|---|
protected void |
addException(File currentFile,
long currentOffset,
long outputOffset,
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,
Exception e)
Record an exception that occurred during the finish() method of this job.
|
protected void |
addInitializeException(long outputOffset,
Exception e)
Record an exception that occurred during the initialize() method of this job.
|
abstract void |
finish(OutputStream os)
Finish up the job.
|
long |
getBatchJobTimeout()
Getter for batchJobTimeout.
|
List<FileBatchJob.ExceptionOccurrence> |
getExceptions()
Get the list of exceptions that have occurred during processing.
|
Pattern |
getFilenamePattern()
Get the pattern for files that should be processed.
|
Collection<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(OutputStream os)
Initialize the job before runnning.
|
protected boolean |
maxExceptionsReached()
Returns true if we have already recorded the maximum number of exceptions.
|
boolean |
postProcess(InputStream input,
OutputStream output)
Processes the concatenated result files.
|
abstract boolean |
processFile(File file,
OutputStream os)
Process one file stored in the bit archive.
|
void |
processOnlyFileNamed(String specifiedFilename)
Helper method for only processing one file.
|
void |
processOnlyFilesMatching(List<String> specifiedPatterns)
Set this job to match only a certain set of patterns.
|
void |
processOnlyFilesMatching(String specifiedPattern)
Set this job to match only a certain pattern.
|
void |
processOnlyFilesNamed(List<String> specifiedFilenames)
Mark the job to process only the specified files.
|
void |
setBatchJobTimeout(long batchJobTimeout)
Override predefined timeout period for batchjob.
|
protected int noOfFilesProcessed
protected long batchJobTimeout
protected Set<File> filesFailed
protected List<FileBatchJob.ExceptionOccurrence> exceptions
public FileBatchJob()
public abstract void initialize(OutputStream os)
os
- the OutputStream to which output should be writtenpublic abstract boolean processFile(File file, OutputStream os)
file
- the file to be processed.os
- the OutputStream to which output should be writtenpublic abstract void finish(OutputStream os)
os
- the OutputStream to which output should be writtenpublic void processOnlyFilesNamed(List<String> specifiedFilenames)
specifiedFilenames
- A list of filenamess to process (without paths). If null, all files will be processed.public void processOnlyFileNamed(String specifiedFilename)
specifiedFilename
- The name of the single file that should be processed. Should not include any path
information.public void processOnlyFilesMatching(List<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(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 Pattern getFilenamePattern()
public int getNoOfFilesProcessed()
public Collection<File> getFilesFailed()
public List<FileBatchJob.ExceptionOccurrence> getExceptions()
public boolean postProcess(InputStream input, 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(File currentFile, long currentOffset, long outputOffset, 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, 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, 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 periodCopyright © 2005–2015 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.