try { if (ghStorage.getDirectory().getDefaultType().isStoring()) { lockFactory.setLockDir(new File(graphHopperLocation)); lock = lockFactory.create(fileLockName, true); if (!lock.tryLock()) throw new RuntimeException("To avoid multiple writers we need to obtain a write lock but it failed. In " + graphHopperLocation, lock.getObtainFailedReason());
@Test public void testForceDelete() { LockFactory instance = createLockFactory(); instance.setLockDir(lockDir); GHLock lock = instance.create("testlock", true); assertTrue(lock.tryLock()); assertTrue(lock.isLocked()); // on windows we cannot forcefully remove an unreleased lock if (Constants.WINDOWS) lock.release(); instance.forceRemove(lock.getName(), true); assertFalse(lock.isLocked()); } }
/** * Releases all associated resources like memory or files. But it does not remove them. To * remove the files created in graphhopperLocation you have to call clean(). */ public void close() { if (ghStorage != null) ghStorage.close(); if (locationIndex != null) locationIndex.close(); try { lockFactory.forceRemove(fileLockName, true); } catch (Exception ex) { // silently fail e.g. on Windows where we cannot remove an unreleased native lock } }
/** * Releases all associated resources like memory or files. But it does not remove them. To * remove the files created in graphhopperLocation you have to call clean(). */ public void close() { if (ghStorage != null) ghStorage.close(); if (locationIndex != null) locationIndex.close(); try { lockFactory.forceRemove(fileLockName, true); } catch (Exception ex) { // silently fail e.g. on Windows where we cannot remove an unreleased native lock } }
lockFactory.setLockDir(new File(ghLocation)); lock = lockFactory.create(fileLockName, false); if (!lock.tryLock()) throw new RuntimeException("To avoid reading partial data we need to obtain the read lock but it failed. In " + ghLocation, lock.getObtainFailedReason());
/** * Releases all associated resources like memory or files. But it does not remove them. To * remove the files created in graphhopperLocation you have to call clean(). */ public void close() { if (ghStorage != null) ghStorage.close(); if (locationIndex != null) locationIndex.close(); try { lockFactory.forceRemove(fileLockName, true); } catch (Exception ex) { // silently fail e.g. on Windows where we cannot remove an unreleased native lock } }
@Test public void testMultiReadObtain() { LockFactory instance = createLockFactory(); instance.setLockDir(lockDir); GHLock writeLock1 = instance.create("test", true); assertTrue(writeLock1.tryLock()); GHLock lock2 = instance.create("test", false); assertFalse(lock2.tryLock()); GHLock writeLock4 = instance.create("test", true); assertFalse(writeLock4.tryLock()); assertEquals(OverlappingFileLockException.class, writeLock4.getObtainFailedReason().getClass());
/** * Releases all associated resources like memory or files. But it does not remove them. To * remove the files created in graphhopperLocation you have to call clean(). */ public void close() { if (ghStorage != null) ghStorage.close(); if (locationIndex != null) locationIndex.close(); try { lockFactory.forceRemove(fileLockName, true); } catch (Exception ex) { // silently fail e.g. on Windows where we cannot remove an unreleased native lock } }
@Test public void testObtain() { LockFactory instance = createLockFactory(); instance.setLockDir(lockDir); GHLock lock = instance.create("test", true); assertTrue(lock.tryLock()); assertTrue(lock.isLocked()); assertFalse(lock.tryLock()); assertTrue(lock.isLocked()); GHLock lock2 = instance.create("test", true); assertFalse(lock2.tryLock()); assertTrue(lock2.isLocked()); // fails for SimpleFSLockFactory: // although it is locked do not allow release: // lock2.release(); // assertTrue(lock.isLocked()); lock.release(); assertFalse(lock.isLocked()); }
try { if (ghStorage.getDirectory().getDefaultType().isStoring()) { lockFactory.setLockDir(new File(graphHopperLocation)); lock = lockFactory.create(fileLockName, true); if (!lock.tryLock()) throw new RuntimeException("To avoid multiple writers we need to obtain a write lock but it failed. In " + graphHopperLocation, lock.getObtainFailedReason());
lockFactory.setLockDir(new File(ghLocation)); lock = lockFactory.create(fileLockName, false); if (!lock.tryLock()) throw new RuntimeException("To avoid reading partial data we need to obtain the read lock but it failed. In " + ghLocation, lock.getObtainFailedReason());
try { if (ghStorage.getDirectory().getDefaultType().isStoring()) { lockFactory.setLockDir(new File(graphHopperLocation)); lock = lockFactory.create(fileLockName, true); if (!lock.tryLock()) throw new RuntimeException("To avoid multiple writers we need to obtain a write lock but it failed. In " + graphHopperLocation, lock.getObtainFailedReason());
lockFactory.setLockDir(new File(graphHopperLocation)); lock = lockFactory.create(fileLockName, true); if (!lock.tryLock()) throw new RuntimeException("To avoid multiple writers we need to obtain a write lock but it failed. In " + graphHopperLocation, lock.getObtainFailedReason());
lockFactory.setLockDir(new File(ghLocation)); lock = lockFactory.create(fileLockName, false); if (!lock.tryLock()) throw new RuntimeException("To avoid reading partial data we need to obtain the read lock but it failed. In " + ghLocation, lock.getObtainFailedReason());
lockFactory.setLockDir(new File(ghLocation)); lock = lockFactory.create(fileLockName, false); if (!lock.tryLock()) throw new RuntimeException("To avoid reading partial data we need to obtain the read lock but it failed. In " + ghLocation, lock.getObtainFailedReason());