use of org.apache.camel.component.file.GenericFileEndpoint in project camel by apache.
the class GenericFileDeleteProcessStrategy method commit.
@Override
public void commit(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
// special for file lock strategy as we must release that lock first before we can delete the file
boolean releaseEager = exclusiveReadLockStrategy instanceof FileLockExclusiveReadLockStrategy;
if (releaseEager) {
exclusiveReadLockStrategy.releaseExclusiveReadLockOnCommit(operations, file, exchange);
}
try {
deleteLocalWorkFile(exchange);
operations.releaseRetreivedFileResources(exchange);
int retries = 3;
boolean deleted = false;
while (retries > 0 && !deleted) {
retries--;
if (operations.deleteFile(file.getAbsoluteFilePath())) {
// file is deleted
deleted = true;
break;
}
// some OS can report false when deleting but the file is still deleted
// use exists to check instead
boolean exits = operations.existsFile(file.getAbsoluteFilePath());
if (!exits) {
deleted = true;
} else {
log.trace("File was not deleted at this attempt will try again in 1 sec.: {}", file);
// sleep a bit and try again
Thread.sleep(1000);
}
}
if (!deleted) {
throw new GenericFileOperationFailedException("Cannot delete file: " + file);
}
} finally {
// must release lock last
if (!releaseEager && exclusiveReadLockStrategy != null) {
exclusiveReadLockStrategy.releaseExclusiveReadLockOnCommit(operations, file, exchange);
}
}
}
Aggregations