@Override public boolean isAccessible(final ContentClaim claim) throws IOException { if (claim == null) { return false; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { final ContentBlock contentBlock = claimMap.get(claim); return contentBlock != null; } return getBackupRepository().isAccessible(backupClaim); }
public long getSize() throws IOException { if (amos == null) { final ContentClaim backupClaim = getBackupClaim(claim); return getBackupRepository().size(backupClaim); } else { return amos.size(); } }
public InputStream read() throws IOException { if (amos == null) { final ContentClaim backupClaim = getBackupClaim(claim); return getBackupRepository().read(backupClaim); } else { return amos.newInputStream(); } } }
@Override public boolean remove(final ContentClaim claim) { if (claim == null) { return false; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { final ContentBlock content = claimMap.remove(claim); if (content == null) { logger.debug("Removed {} from repo but it did not exist", claim); } else { logger.debug("Removed {} from repo; Content = {}", claim, content); content.destroy(); } } else { getBackupRepository().remove(backupClaim); } return true; }
private void redirect() throws IOException { final ContentRepository backupRepo = getBackupRepository(); if (backupRepo == null) { throw new IOException("Content Repository is out of space"); } final ContentClaim backupClaim = backupRepo.create(true); backupRepoClaimMap.put(claim, backupClaim); out = backupRepo.write(backupClaim); amos.writeTo(out); amos.destroy(); amos = null; }
@Override public ContentClaim create(boolean lossTolerant) throws IOException { if (lossTolerant) { return createLossTolerant(); } else { final ContentRepository backupRepo = getBackupRepository(); if (backupRepo == null) { // TODO: Loss Tolerance is not yet configurable. // Therefore, since this is an in-memory content repository, assume that this claim is loss-tolerant if there // is not a backup repository return createLossTolerant(); } final ContentClaim backupClaim = backupRepo.create(lossTolerant); backupRepoClaimMap.put(backupClaim, backupClaim); return backupClaim; } }
@Override public InputStream read(final ContentClaim claim) throws IOException { if (claim == null) { return new ByteArrayInputStream(new byte[0]); } final ContentClaim backupClaim = getBackupClaim(claim); return backupClaim == null ? getContent(claim).read() : getBackupRepository().read(backupClaim); }
@Override public ContentClaim clone(final ContentClaim original, final boolean lossTolerant) throws IOException { final ContentClaim createdClaim = create(lossTolerant); try (final InputStream dataIn = read(original)) { final ContentRepository createdClaimRepo = lossTolerant ? this : getBackupRepository(); if (createdClaimRepo == null) { throw new IllegalStateException("Cannot create non-loss-tolerant ContentClaim because there is no persistent Content Repository configured"); } try (final OutputStream dataOut = createdClaimRepo.write(createdClaim)) { StreamUtils.copy(dataIn, dataOut); } } return createdClaim; }
@Override public void purge() { for (final ContentClaim claim : claimMap.keySet()) { claimManager.decrementClaimantCount(resolveClaim(claim).getResourceClaim()); final ContentClaim backup = getBackupClaim(claim); if (backup != null) { getBackupRepository().remove(backup); } } }
@Override public long size(final ContentClaim claim) throws IOException { if (claim == null) { return 0L; } final ContentClaim backupClaim = getBackupClaim(claim); return backupClaim == null ? getContent(claim).getSize() : getBackupRepository().size(claim); }
@Override public OutputStream write(final ContentClaim claim) throws IOException { final ContentClaim backupClaim = getBackupClaim(claim); return backupClaim == null ? getContent(claim).write() : getBackupRepository().write(backupClaim); }
@Override public int incrementClaimaintCount(final ContentClaim claim) { if (claim == null) { return 0; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { return claimManager.incrementClaimantCount(resolveClaim(claim).getResourceClaim()); } else { return getBackupRepository().incrementClaimaintCount(backupClaim); } }
@Override public int decrementClaimantCount(final ContentClaim claim) { if (claim == null) { return 0; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { return claimManager.decrementClaimantCount(resolveClaim(claim).getResourceClaim()); } else { return getBackupRepository().decrementClaimantCount(backupClaim); } }
@Override public int getClaimantCount(final ContentClaim claim) { if (claim == null) { return 0; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { return claimManager.getClaimantCount(resolveClaim(claim).getResourceClaim()); } else { return getBackupRepository().getClaimantCount(backupClaim); } }
@Override public long importFrom(final InputStream in, final ContentClaim claim) throws IOException { final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { final ContentBlock content = getContent(claim); content.reset(); return StreamUtils.copy(in, content.write()); } else { return getBackupRepository().importFrom(in, claim); } }