use of jetbrains.exodus.core.dataStructures.ObjectCacheBase.CriticalSection in project xodus by JetBrains.
the class SharedOpenFilesCache method getCachedFile.
@NotNull
SharedRandomAccessFile getCachedFile(@NotNull final File file) throws IOException {
SharedRandomAccessFile result;
try (CriticalSection ignored = cache.newCriticalSection()) {
result = cache.tryKey(file);
if (result != null && result.employ() > 1) {
result.close();
result = null;
}
}
if (result == null) {
result = openFile(file);
SharedRandomAccessFile obsolete = null;
try (CriticalSection ignored = cache.newCriticalSection()) {
if (cache.getObject(file) == null) {
result.employ();
obsolete = cache.cacheObject(file, result);
}
}
if (obsolete != null) {
obsolete.close();
}
}
return result;
}
use of jetbrains.exodus.core.dataStructures.ObjectCacheBase.CriticalSection in project xodus by JetBrains.
the class SharedOpenFilesCache method removeDirectory.
void removeDirectory(@NotNull final File dir) throws IOException {
final List<SharedRandomAccessFile> result = new ArrayList<>();
final List<File> obsoleteFiles = new ArrayList<>();
try (CriticalSection ignored = cache.newCriticalSection()) {
final Iterator<File> keys = cache.keys();
while (keys.hasNext()) {
final File file = keys.next();
if (file.getParentFile().equals(dir)) {
obsoleteFiles.add(file);
result.add(cache.getObject(file));
}
}
for (final File file : obsoleteFiles) {
cache.remove(file);
}
}
for (final SharedRandomAccessFile obsolete : result) {
obsolete.close();
}
}
use of jetbrains.exodus.core.dataStructures.ObjectCacheBase.CriticalSection in project xodus by JetBrains.
the class SharedOpenFilesCache method clear.
private void clear() throws IOException {
final List<SharedRandomAccessFile> openFiles = new ArrayList<>();
try (CriticalSection ignored = cache.newCriticalSection()) {
final Iterator<SharedRandomAccessFile> it = cache.values();
while (it.hasNext()) {
openFiles.add(it.next());
}
cache.clear();
}
for (final SharedRandomAccessFile file : openFiles) {
file.close();
}
}
Aggregations