use of java.nio.channels.FileLock in project cryptofs by cryptomator.
the class OpenCryptoFileTest method testLockDelegatesToChannel.
@Theory
public void testLockDelegatesToChannel(boolean shared) throws IOException {
long position = 383872;
long size = 48483;
FileLock lock = mock(FileLock.class);
when(channel.lock(position, size, shared)).thenReturn(lock);
assertThat(inTest.lock(position, size, shared), is(lock));
}
use of java.nio.channels.FileLock in project cryptofs by cryptomator.
the class CryptoFileChannel method tryLock.
@Override
public FileLock tryLock(long position, long size, boolean shared) throws IOException {
assertOpen();
FileLock delegate = openCryptoFile.tryLock(position, size, shared);
if (delegate == null) {
return null;
}
CryptoFileLock result = //
CryptoFileLock.builder().withDelegate(//
delegate).withChannel(//
this).withPosition(//
position).withSize(//
size).thatIsShared(shared).build();
return result;
}
use of java.nio.channels.FileLock in project cryptofs by cryptomator.
the class CryptoFileChannel method lock.
@Override
public FileLock lock(long position, long size, boolean shared) throws IOException {
assertOpen();
return blockingIo(() -> {
FileLock delegate = openCryptoFile.lock(position, size, shared);
CryptoFileLock result = //
CryptoFileLock.builder().withDelegate(//
delegate).withChannel(//
this).withPosition(//
position).withSize(//
size).thatIsShared(shared).build();
return result;
});
}
use of java.nio.channels.FileLock in project cryptofs by cryptomator.
the class AsyncDelegatingFileChannelTest method testTryLock.
@Test
public void testTryLock() throws IOException {
Mockito.when(channel.tryLock(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyBoolean())).thenReturn(null);
Assert.assertNull(asyncChannel.tryLock(0l, 42l, true));
FileLock lock = Mockito.mock(FileLock.class);
Mockito.when(channel.tryLock(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyBoolean())).thenReturn(lock);
Assert.assertEquals(lock, asyncChannel.tryLock(0l, 42l, true));
}
use of java.nio.channels.FileLock in project activemq-artemis by apache.
the class FileLockNodeManager method isBackupLive.
@Override
public boolean isBackupLive() throws Exception {
FileLock liveAttemptLock;
liveAttemptLock = tryLock(FileLockNodeManager.LIVE_LOCK_POS);
if (liveAttemptLock == null) {
return true;
} else {
liveAttemptLock.release();
return false;
}
}
Aggregations