@Test public void testLock() throws Exception { final StoregateIdProvider nodeid = new StoregateIdProvider(session).withCache(cache); final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir(new Path( String.format("/My files/%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final Path fileInRoom = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new StoregateTouchFeature(session, nodeid).touch(fileInRoom, new TransferStatus()); assertTrue(new DefaultFindFeature(session).find(fileInRoom)); final String lock = new StoregateLockFeature(session, nodeid).lock(fileInRoom); assertNotNull(lock); try { new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(fileInRoom), new DisabledLoginCallback(), new Delete.DisabledCallback()); fail(); } catch(LockedException e) { } new StoregateLockFeature(session, nodeid).unlock(fileInRoom, lock); new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(fileInRoom), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(new DefaultFindFeature(session).find(fileInRoom)); new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public String lock(final Path file) throws BackgroundException { try { final FileLockRequest request = new FileLockRequest(); request.setExpire(new DateTime().plusMillis(PreferencesFactory.get().getInteger("storegate.lock.ttl"))); request.setOwner(session.getHost().getCredentials().getUsername()); final FileLock lock = new FileLocksApi(this.session.getClient()).fileLocksCreateLock(fileid.getFileid(file, new DisabledListProgressListener()), request); return lock.getLockId(); } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
StoregateLockFeature implements Lock<String> { @Override public String lock(final Path file) throws BackgroundException { try { final FileLockRequest request = new FileLockRequest(); request.setExpire(new DateTime().plusMillis(PreferencesFactory.get().getInteger("storegate.lock.ttl"))); request.setOwner(session.getHost().getCredentials().getUsername()); final FileLock lock = new FileLocksApi(this.session.getClient()).fileLocksCreateLock(fileid.getFileid(file, new DisabledListProgressListener()), request); return lock.getLockId(); } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }
StoregateLockFeature implements Lock<String> { @Override public String lock(final Path file) throws BackgroundException { try { final FileLockRequest request = new FileLockRequest(); request.setExpire(new DateTime().plusMillis(PreferencesFactory.get().getInteger("storegate.lock.ttl"))); request.setOwner(session.getHost().getCredentials().getUsername()); final FileLock lock = new FileLocksApi(this.session.getClient()).fileLocksCreateLock(fileid.getFileid(file, new DisabledListProgressListener()), request); return lock.getLockId(); } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } StoregateLockFeature(final StoregateSession session, final StoregateIdProvider fileid); }
StoregateLockFeature implements Lock<String> { @Override public String lock(final Path file) throws BackgroundException { try { final FileLockRequest request = new FileLockRequest(); request.setExpire(new DateTime().plusMillis(PreferencesFactory.get().getInteger("storegate.lock.ttl"))); request.setOwner(session.getHost().getCredentials().getUsername()); final FileLock lock = new FileLocksApi(this.session.getClient()).fileLocksCreateLock(fileid.getFileid(file, new DisabledListProgressListener()), request); return lock.getLockId(); } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } StoregateLockFeature(final StoregateSession session, final StoregateIdProvider fileid); @Override String lock(final Path file); @Override void unlock(final Path file, final String token); }
StoregateLockFeature implements Lock<String> { @Override public String lock(final Path file) throws BackgroundException { try { final FileLockRequest request = new FileLockRequest(); request.setExpire(new DateTime().plusMillis(PreferencesFactory.get().getInteger("storegate.lock.ttl"))); request.setOwner(session.getHost().getCredentials().getUsername()); final FileLock lock = new FileLocksApi(this.session.getClient()).fileLocksCreateLock(fileid.getFileid(file, new DisabledListProgressListener()), request); return lock.getLockId(); } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } StoregateLockFeature(final StoregateSession session, final StoregateIdProvider fileid); @Override String lock(final Path file); @Override void unlock(final Path file, final String token);  }