本文整理了Java中org.apache.jena.tdb.base.file.Location.getLock()
方法的一些代码示例,展示了Location.getLock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Location.getLock()
方法的具体详情如下:
包路径:org.apache.jena.tdb.base.file.Location
类名称:Location
方法名:getLock
暂无
代码示例来源:origin: apache/jena
/** Stop managing a location. Use with great care (testing only). */
public static synchronized void expel(Location location, boolean force) {
StoreConnection sConn = cache.get(location) ;
if (sConn == null)
return ;
if (!force && sConn.transactionManager.activeTransactions())
throw new TDBTransactionException("Can't expel: Active transactions for location: " + location) ;
// No transactions at this point (or we don't care and are clearing up forcefully.)
sConn.transactionManager.closedown() ;
sConn.baseDSG.close() ;
sConn.isValid = false ;
cache.remove(location) ;
ChannelManager.release(sConn.transactionManager.getJournal().getFilename()) ;
// Release the lock
if (SystemTDB.DiskLocationMultiJvmUsagePrevention) {
if (location.getLock().isOwned()) {
location.getLock().release();
} else if (location.getLock().canLock()) {
SystemTDB.errlog.warn("Location " + location.getDirectoryPath() + " was not locked, if another JVM accessed this location simultaneously data corruption may have occurred");
}
}
}
代码示例来源:origin: apache/jena
LocationLock lock = location.getLock();
if (lock.canLock()) {
if (!lock.canObtain()) {
代码示例来源:origin: apache/jena
@Test
public void location_lock_dir_error_03() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a TDB2 format lock file
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// TDB2 format lock file, this writes a new line to the end of the lock file
writer.write(Integer.toString(-1234));
writer.write('\n');
}
// Trying to get the owner should error accordingly
try {
lock.canObtain();
Assert.fail("Expected the lock file to be considered invalid");
} catch (FileException e) {
String errMsg = e.getMessage();
Assert.assertNotNull(errMsg);
Assert.assertTrue(errMsg.contains("appear to be for a TDB2 database"));
}
}
}
代码示例来源:origin: apache/jena
@Test
public void location_lock_dir_02() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
writer.write(Integer.toString(-1234)); // Fake PID that would never
// be valid
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertFalse(lock.canObtain());
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test
public void location_lock_dir_02() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try(BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
writer.write(Integer.toString(-1234)); // Fake PID that would never be valid
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertFalse(lock.canObtain());
}
代码示例来源:origin: apache/jena
@Test(expected = TDBException.class)
public void location_lock_store_connection_02() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try(BufferedWriter writer =
new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// Fake PID that would never be valid
writer.write(Integer.toString(-1234));
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
// Attempting to create a connection on this location should error
StoreConnection.make(dir);
}
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test(expected = TDBException.class)
public void location_lock_store_connection_02() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try(BufferedWriter writer =
new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// Fake PID that would never be valid
writer.write(Integer.toString(-1234));
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
// Attempting to create a connection on this location should error
StoreConnection.make(dir);
}
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test(expected = TDBException.class)
public void location_lock_dir_error_01() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try(BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// Fake PID that would never be valid
writer.write(Integer.toString(-1234));
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
// Attempting to obtain the lock should now error
Assert.assertFalse(lock.canObtain());
lock.obtain();
}
代码示例来源:origin: apache/jena
@Test(expected = TDBException.class)
public void location_lock_dir_error_01() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// Fake PID that would never be valid
writer.write(Integer.toString(-1234));
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
// Attempting to obtain the lock should now error
Assert.assertFalse(lock.canObtain());
lock.obtain();
}
代码示例来源:origin: apache/jena
@Test(expected = TDBException.class)
public void location_lock_dir_error_02() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// Fake PID that would never be valid
writer.write(Integer.toString(-1234));
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
// Attempting to release a lock we don't own should error
Assert.assertFalse(lock.canObtain());
lock.release();
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test(expected = TDBException.class)
public void location_lock_dir_error_02() throws IOException {
Assume.assumeTrue(negativePidsTreatedAsAlive);
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Write a fake PID to the lock file
try(BufferedWriter writer =
new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
// Fake PID that would never be valid
writer.write(Integer.toString(-1234));
}
Assert.assertTrue(lock.isLocked());
Assert.assertFalse(lock.isOwned());
// Attempting to release a lock we don't own should error
Assert.assertFalse(lock.canObtain());
lock.release();
}
}
代码示例来源:origin: apache/jena
@Test
public void location_lock_mem() {
Location mem = Location.mem();
LocationLock lock = mem.getLock();
Assert.assertFalse(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertFalse(lock.canObtain());
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test
public void location_lock_mem() {
Location mem = Location.mem();
LocationLock lock = mem.getLock();
Assert.assertFalse(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertFalse(lock.canObtain());
}
代码示例来源:origin: apache/jena
@Test
public void location_lock_dir_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Try to obtain the lock
lock.obtain();
Assert.assertTrue(lock.isLocked());
Assert.assertTrue(lock.isOwned());
// Release the lock
lock.release();
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test
public void location_lock_dir_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Try to obtain the lock
lock.obtain();
Assert.assertTrue(lock.isLocked());
Assert.assertTrue(lock.isOwned());
// Release the lock
lock.release();
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
}
代码示例来源:origin: apache/jena
@Test
public void location_lock_store_connection_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Creating a StoreConnection on the location will obtain the lock
StoreConnection.make(dir);
Assert.assertTrue(lock.isLocked());
Assert.assertTrue(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Releasing the connection releases the lock
StoreConnection.release(dir);
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
}
代码示例来源:origin: org.apache.jena/jena-tdb
@Test
public void location_lock_store_connection_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Creating a StoreConnection on the location will obtain the lock
StoreConnection.make(dir);
Assert.assertTrue(lock.isLocked());
Assert.assertTrue(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Releasing the connection releases the lock
StoreConnection.release(dir);
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
}
内容来源于网络,如有侵权,请联系作者删除!