Search in sources :

Example 1 with ProcessFileLock

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;
}
Also used : ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 2 with ProcessFileLock

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);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 3 with ProcessFileLock

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());
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) Location(org.apache.jena.dboe.base.file.Location) Test(org.junit.Test)

Example 4 with ProcessFileLock

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);
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) Location(org.apache.jena.dboe.base.file.Location) Test(org.junit.Test)

Aggregations

ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)4 Location (org.apache.jena.dboe.base.file.Location)2 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)2 Test (org.junit.Test)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 TDBException (org.apache.jena.tdb2.TDBException)1 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)1