java.nio.channels.FileLockInterruptionException Java Examples
The following examples show how to use
java.nio.channels.FileLockInterruptionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JimfsFileChannel.java From jimfs with Apache License 2.0 | 6 votes |
@Override public FileLock lock(long position, long size, boolean shared) throws IOException { checkLockArguments(position, size, shared); // lock is interruptible boolean completed = false; try { begin(); completed = true; return new FakeFileLock(this, position, size, shared); } finally { try { end(completed); } catch (ClosedByInterruptException e) { throw new FileLockInterruptionException(); } } }
Example #2
Source File: JimfsFileChannelTest.java From jimfs with Apache License 2.0 | 6 votes |
/** * Asserts that when the given operation is run on an interrupted thread, {@code * ClosedByInterruptException} is thrown, the channel is closed and the thread is no longer * interrupted. */ private static void assertClosedByInterrupt(FileChannelMethod method) throws IOException { FileChannel channel = channel(regularFile(10), READ, WRITE); Thread.currentThread().interrupt(); try { method.call(channel); fail( "expected the method to throw ClosedByInterruptException or " + "FileLockInterruptionException"); } catch (ClosedByInterruptException | FileLockInterruptionException expected) { assertFalse("expected the channel to be closed", channel.isOpen()); assertTrue("expected the thread to still be interrupted", Thread.interrupted()); } finally { Thread.interrupted(); // ensure the thread isn't interrupted when this method returns } }
Example #3
Source File: FileLock.java From embedded-cassandra with Apache License 2.0 | 5 votes |
/** * Acquires an exclusive lock on the file. * * @param timeout the maximum time to wait * @param timeUnit the time unit of the {@code timeout} argument * @return {@code true} if lock has been acquired otherwise {@code false} * @throws FileLockInterruptionException If the invoking thread is interrupted while blocked in this method * @throws IOException If some other I/O error occurs */ public boolean tryLock(long timeout, TimeUnit timeUnit) throws FileLockInterruptionException, IOException { Objects.requireNonNull(timeUnit, "'timeUnit' must not be null"); java.nio.channels.FileLock fileLock = this.locks.get(Thread.currentThread()); if (fileLock != null && fileLock.isValid()) { return true; } long startTime = System.nanoTime(); long rem = timeUnit.toNanos(timeout); do { fileLock = lock(this.fileChannel); if (fileLock != null) { this.locks.put(Thread.currentThread(), fileLock); return true; } if (rem > 0) { try { Thread.sleep(Math.min(TimeUnit.NANOSECONDS.toMillis(rem) + 1, 100)); } catch (InterruptedException ex) { throw new FileLockInterruptionException(); } } rem = timeUnit.toNanos(timeout) - (System.nanoTime() - startTime); } while (rem > 0); return false; }
Example #4
Source File: FileLockInterruptionExceptionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests {@link java.nio.channels.FileLockInterruptionException#FileLockInterruptionException()} */ public void test_Constructor() { FileLockInterruptionException e = new FileLockInterruptionException(); assertNull(e.getMessage()); assertNull(e.getLocalizedMessage()); assertNull(e.getCause()); }
Example #5
Source File: FileLockInterruptionExceptionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * @tests serialization/deserialization compatibility. */ public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new FileLockInterruptionException()); }
Example #6
Source File: FileLockInterruptionExceptionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * @tests serialization/deserialization compatibility with RI. */ public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new FileLockInterruptionException()); }