use of org.apache.jena.dboe.base.file.ProcessFileLock in project jena by apache.
the class StoreConnection method make.
/**
* Return a {@code StoreConnection} for a particular location,
* creating it if it does not exist in storage.
*/
private static synchronized StoreConnection make(Location location, StoreParams params) {
StoreConnection sConn = cache.get(location);
if (sConn == null) {
ProcessFileLock lock = null;
// This is a tdb.lock file in the storage database, not the switchable.
if (SystemTDB.DiskLocationMultiJvmUsagePrevention && !location.isMem()) {
lock = lockForLocation(location);
// Take the lock. This is atomic and non-reentrant.
lock.lockEx();
}
// Recovery happens when TransactionCoordinator.start is called
// during the building of the DatasetGraphTDB
DatasetGraphTDB dsg = TDB2StorageBuilder.build(location, params);
sConn = new StoreConnection(dsg, lock);
if (!location.isMemUnique())
cache.put(location, sConn);
}
return sConn;
}
use of org.apache.jena.dboe.base.file.ProcessFileLock in project jena by apache.
the class DatabaseConnection method build.
private static DatabaseConnection build(Location location, StoreParams params) {
if (location.isMemUnique()) {
throw new TDBException("Can't buildForCache a memory-unique location");
}
ProcessFileLock lock = null;
if (SystemTDB.DiskLocationMultiJvmUsagePrevention && !location.isMem()) {
// Take the lock for the swithable.
// StoreConnection will take a lock for the storage.
lock = lockForLocation(location);
// Take the lock. This is atomic and non-reentrant.
lock.lockEx();
}
// c.f. StoreConnection.make
DatasetGraph dsg = DatabaseOps.create(location, params);
return new DatabaseConnection(dsg, location, lock);
}
use of org.apache.jena.dboe.base.file.ProcessFileLock in project jena by apache.
the class TestStoreConnectionLock method lock_store_connection_01.
@Test
public void lock_store_connection_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
ProcessFileLock lock = StoreConnection.lockForLocation(dir);
assertFalse(lock.isLockedHere());
StoreConnection sConn = StoreConnection.connectCreate(dir);
assertEquals(dir, sConn.getLocation());
assertEquals(lock, sConn.getLock());
assertTrue(lock.isLockedHere());
StoreConnection.release(dir);
assertFalse(lock.isLockedHere());
}
use of org.apache.jena.dboe.base.file.ProcessFileLock in project jena by apache.
the class TestStoreConnectionLock method lock_store_connection_02.
@Test(expected = AlreadyLocked.class)
public void lock_store_connection_02() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
ProcessFileLock lock = StoreConnection.lockForLocation(dir);
lock.lockEx();
StoreConnection sConn = StoreConnection.connectCreate(dir);
}
Aggregations