use of dvoraka.avservice.storage.FileNotFoundException in project av-service by dvoraka.
the class DefaultReplicationService method loadFile.
@Override
public FileMessage loadFile(FileMessage message) throws FileServiceException {
log.debug("Load ({}): {}", nodeId, message);
int neighbours = neighbourCount();
try {
if (remoteLock.lockForFile(message.getFilename(), message.getOwner(), neighbours)) {
if (localCopyExists(message)) {
log.debug("Loading locally...");
return fileService.loadFile(message);
}
if (exists(message)) {
log.debug("Loading remotely {}...", idString);
sendLoadMessage(message);
Optional<ReplicationMessageList> replicationMessages = responseClient.getResponseWait(message.getId(), MAX_RESPONSE_TIME);
ReplicationMessageList messages = replicationMessages.orElseGet(ReplicationMessageList::new);
return messages.stream().filter(msg -> msg.getReplicationStatus() == ReplicationStatus.OK).peek(m -> log.debug("Load success {}.", idString)).findFirst().orElseThrow(FileNotFoundException::new);
}
log.debug("Loading failed {}.", idString);
throw new FileNotFoundException();
} else {
log.warn("Load lock problem for {}: {}", idString, message);
throw new CannotAcquireLockException();
}
} catch (InterruptedException e) {
log.warn("Locking interrupted!", e);
Thread.currentThread().interrupt();
} finally {
remoteLock.unlockForFile(message.getFilename(), message.getOwner(), neighbours);
}
throw new FileNotFoundException();
}
Aggregations