@Override public AcquiredLock lockForDelete(final String path) { try { return new AcquiredMultiPathLock(normalizePath(path)); } catch (InterruptedException e) { throw new InterruptedRuntimeException(e); } } }
@Override public Response toResponse(final InterruptedRuntimeException e) { debugException(this, e, LOGGER); return status(SERVICE_UNAVAILABLE).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); } }
@Override public AcquiredLock lockForRead(final String path) { final List<ActivePath.PathScopedLock> locks = new ArrayList<>(); synchronized (this) { locks.add(getActivePath(normalizePath(path)).getReadLock()); } try { return new AcquiredMultiPathLock(locks); } catch (InterruptedException e) { throw new InterruptedRuntimeException(e); } }
@Override public AcquiredLock lockForWrite(final String path, final FedoraSession session, final NodeService nodeService) { final List<ActivePath.PathScopedLock> locks = new ArrayList<>(); synchronized (this) { // lock the specified path while iterating through the path's // ancestry to also lock each path that would be created implicitly // by this write (ie, non-existent ancestral paths) final String startingPath = normalizePath(path); for (String currentPath = startingPath ; currentPath == null || currentPath.length() > 0; currentPath = getParentPath(currentPath)) { if (currentPath == null || (!Objects.equals(currentPath, startingPath) && nodeService.exists(session, currentPath))) { // either we've followed the path back to the root, or we've found an ancestor that exists... // so there are no more locks to create. break; } locks.add(getActivePath(currentPath).getWriteLock()); } } try { return new AcquiredMultiPathLock(locks); } catch (InterruptedException e) { throw new InterruptedRuntimeException(e); } }