本文整理汇总了Java中java.nio.channels.FileLockInterruptionException类的典型用法代码示例。如果您正苦于以下问题:Java FileLockInterruptionException类的具体用法?Java FileLockInterruptionException怎么用?Java FileLockInterruptionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileLockInterruptionException类属于java.nio.channels包,在下文中一共展示了FileLockInterruptionException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerializationSelf
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationSelf",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "FileLockInterruptionException",
args = {}
)
})
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new FileLockInterruptionException());
}
示例2: testSerializationCompatibility
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility with RI.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationGolden",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "FileLockInterruptionException",
args = {}
)
})
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this,
new FileLockInterruptionException());
}
示例3: lock
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
@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();
}
}
}
示例4: assertClosedByInterrupt
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
/**
* 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
}
}
示例5: updateServerMonitorData
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
public synchronized boolean updateServerMonitorData(Server s) {
if (!s.isLinked()) {
return false;
}
File file = new File(Storage.getSettings().getCommunicationDir() + "/" + s.getName() + EXTENSION);
if (file.isFile()) {
try (FileOutputStream fos = new FileOutputStream(file, true); FileInputStream fis = new FileInputStream(file)) {
locker = new Thread() {
public void run() {
try {
fos.getChannel().lock();
} catch (FileLockInterruptionException ex) {
} catch (IOException ex) {
Printer.printError(PNAME, "Failed to acquire lock on file \"" + file + "\".", ex);
}
}
};
locker.start();
locker.join(3000);
if (locker.isAlive()) {
Printer.printBackgroundFail(PNAME, "Failed to read the file \"" + file + "\". Could not acquire lock.");
return false;
}
Scanner sc = new Scanner(fis);
s.setFileUpdateInterval(Long.parseLong(sc.nextLine()));
s.setLastPing(Long.parseLong(sc.nextLine()));
ArrayList<String> msgs = new ArrayList();
while (sc.hasNextLine()) {
msgs.add(sc.nextLine());
}
s.setCustomMessages(msgs);
return true;
} catch (Exception e) {
Printer.printError(PNAME, "The server \"" + s.getName() + "\" monitor data file is broken.", e);
}
} else {
Printer.printBackgroundFail(PNAME, "The monitor data file \"" + file.getAbsolutePath() + "\" was not found for the server \"" + s.getName() + "\".");
}
return false;
}
示例6: test_Constructor
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
/**
* @tests {@link java.nio.channels.FileLockInterruptionException#FileLockInterruptionException()}
*/
public void test_Constructor() {
FileLockInterruptionException e = new FileLockInterruptionException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
示例7: testSerializationSelf
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility.
*/
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new FileLockInterruptionException());
}
示例8: testSerializationCompatibility
import java.nio.channels.FileLockInterruptionException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility with RI.
*/
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this,
new FileLockInterruptionException());
}