Skip to content

Commit 9616812

Browse files
committed
refs #71 - added ability to control the ExecutorService (and thus the threads) in the BagVerifier
1 parent 1629a43 commit 9616812

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/main/java/gov/loc/repository/bagit/verify/BagVerifier.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,26 @@ public final class BagVerifier {
5252
private static final String PAYLOAD_OXUM_REGEX = "\\d+\\.\\d+";
5353

5454
private final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping;
55+
private final ExecutorService executor;
5556

5657
public BagVerifier(){
5758
nameMapping = new StandardBagitAlgorithmNameToSupportedAlgorithmMapping();
59+
executor = Executors.newCachedThreadPool();
5860
}
5961

6062
public BagVerifier(final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping){
6163
this.nameMapping = nameMapping;
64+
executor = Executors.newCachedThreadPool();
65+
}
66+
67+
public BagVerifier(final ExecutorService executor){
68+
nameMapping = new StandardBagitAlgorithmNameToSupportedAlgorithmMapping();
69+
this.executor = executor;
70+
}
71+
72+
public BagVerifier(final ExecutorService executor, final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping){
73+
this.nameMapping = nameMapping;
74+
this.executor = executor;
6275
}
6376

6477
/**
@@ -163,7 +176,6 @@ public void isValid(final Bag bag, final boolean ignoreHiddenFiles) throws IOExc
163176
*/
164177
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
165178
void checkHashes(final Manifest manifest) throws CorruptChecksumException, InterruptedException, VerificationException{
166-
final ExecutorService executor = Executors.newCachedThreadPool();
167179
final CountDownLatch latch = new CountDownLatch( manifest.getFileToChecksumMap().size());
168180
final List<Exception> exceptions = new ArrayList<>(); //TODO maybe return all of these at some point...
169181

@@ -172,7 +184,6 @@ void checkHashes(final Manifest manifest) throws CorruptChecksumException, Inter
172184
}
173185

174186
latch.await();
175-
executor.shutdown();
176187

177188
if(!exceptions.isEmpty()){
178189
final Exception e = exceptions.get(0);
@@ -369,4 +380,8 @@ private void checkAllFilesInPayloadDirAreListedInAManifest(final Set<Path> files
369380
public BagitAlgorithmNameToSupportedAlgorithmMapping getNameMapping() {
370381
return nameMapping;
371382
}
383+
384+
public ExecutorService getExecutor() {
385+
return executor;
386+
}
372387
}

0 commit comments

Comments
 (0)