public static String readLockedBy(final Path path) { org.uberfire.java.nio.file.Path lock = convert(PathFactory.newLock(path)); if (!Files.exists(lock)) { return null; } else { return new String(Files.readAllBytes(lock)); } }
@Test public void lockTest() { Path path = mock(Path.class); when(path.toURI()).thenReturn("default://master@myteam/dora/src/main/resources/com/myteam/dora/sample.drl"); assertEquals("default://locks@system/system/myteam/master/dora/src/main/resources/com/myteam/dora/sample.drl.ulock", PathFactory.newLock(path).toURI()); Path lockPath = PathFactory.newLockPath(path); Path extractedPath = PathFactory.fromLock(lockPath); assertEquals(path.toURI(), extractedPath.toURI()); } }
@Test public void lockTest() { Path path = mock(Path.class); when(path.toURI()).thenReturn("default://master@myteam/dora/src/main/resources/com/myteam/dora/sample.drl"); assertEquals("default://locks@system/system/myteam/master/dora/src/main/resources/com/myteam/dora/sample.drl.ulock", PathFactory.newLock(path).toURI()); Path lockPath = PathFactory.newLockPath(path); Path extractedPath = PathFactory.fromLock(lockPath); assertEquals(path.toURI(), extractedPath.toURI()); } }
private LockInfo retrieveLockInfo(org.uberfire.backend.vfs.Path path) { final org.uberfire.java.nio.file.Path lockPath = Paths.convert(PathFactory.newLock(path)); try { //See https://issues.jboss.org/browse/GUVNOR-2399. We simply try to read the lock file returning a default. final String lockedBy = configIOService.readAllString(lockPath); return new LockInfo(true, lockedBy, path); } catch (NoSuchFileException nsfe) { return new LockInfo(false, "", path); } } }
private LockInfo retrieveLockInfo(org.uberfire.backend.vfs.Path path) { final org.uberfire.java.nio.file.Path lockPath = Paths.convert(PathFactory.newLock(path)); try { //See https://issues.jboss.org/browse/GUVNOR-2399. We simply try to read the lock file returning a default. final String lockedBy = configIOService.readAllString(lockPath); return new LockInfo(true, lockedBy, path); } catch (NoSuchFileException nsfe) { return new LockInfo(false, "", path); } } }
for (LockInfo lock : locks) { try { final Path lockPath = Paths.convert(PathFactory.newLock(lock.getFile()));
@Override public LockInfo retrieveLockInfo(Path path) throws IllegalArgumentException, IOException { final Path vfsLock = PathFactory.newLock(path); final org.uberfire.java.nio.file.Path realLock = Paths.convert(vfsLock); if (ioService.exists(realLock)) { try { final String lockedBy = ioService.readAllString(realLock); return new LockInfo(true, lockedBy, path, vfsLock); } catch (NoSuchFileException nsfe) { // We want to avoid starting a batch (to ensure cluster-wide consistent reads) here since // this method is invoked very frequently. Therefore it's possible that the lock file // was deleted after the check to exists but before readAllString was invoked. There's // no need for special exception handling as it simply means that file is no longer locked. } } return new LockInfo(false, null, path, vfsLock); }