import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
+import org.simantics.acorn.FileCache;
import org.simantics.acorn.FileIO;
import org.simantics.acorn.Persistable;
import org.simantics.acorn.exception.AcornAccessVerificationException;
// Final stuff
final protected LRU<MapKey, MapValue> LRU;
+ final protected FileCache fileCache;
final private Semaphore mutex = new Semaphore(1);
final private MapKey key;
final private String fileName;
private Thread mutexOwner;
// for loading
- public LRUObject(LRU<MapKey, MapValue> LRU, MapKey key, Path readDirectory, String fileName, int offset, int length, boolean dirty, boolean resident) {
+ public LRUObject(LRU<MapKey, MapValue> LRU, FileCache fileCache, MapKey key, Path readDirectory, String fileName, int offset, int length, boolean dirty, boolean resident) {
this.LRU = LRU;
+ this.fileCache = fileCache;
this.key = key;
this.fileName = fileName;
this.offset = offset;
}
// for creating
- public LRUObject(LRU<MapKey, MapValue> LRU, MapKey key, Path readDirectory, String fileName, boolean dirty, boolean resident) {
- this(LRU, key, readDirectory, fileName, -1, -1, dirty, resident);
+ public LRUObject(LRU<MapKey, MapValue> LRU, FileCache fileCache, MapKey key, Path readDirectory, String fileName, boolean dirty, boolean resident) {
+ this(LRU, fileCache, key, readDirectory, fileName, -1, -1, dirty, resident);
}
/*
Pair<byte[], Integer> pair = toBytes();
byte[] data = pair.first;
int length = pair.second;
- FileIO fio = FileIO.get(bytes);
+ FileIO fio = fileCache.get(bytes);
int offset = fio.saveBytes(data, length, overwrite());
setPosition(offset, length);
} catch (AcornAccessVerificationException | IllegalAcornStateException e) {
if(VERIFY) verifyAccess();
Path dir = getDirectory();
Path f = dir.resolve(getFileName());
- FileIO fio = FileIO.get(f);
+ FileIO fio = fileCache.get(f);
return fio.readBytes(getOffset(), getLength());
}