use of org.sirix.api.ResourceManager in project sirix by sirixdb.
the class ResourceStore method openResource.
/**
* Open a resource, that is get an instance of a {@link ResourceManager} in order to read/write
* from the resource.
*
* @param database The database.
* @param resourceConfig The resource configuration.
* @param resourceManagerConfig The resource manager configuration.
* @param bufferManager The buffer manager.
* @param resourceFile The resource to open.
* @return A resource manager.
*/
public ResourceManager openResource(@Nonnull final DatabaseImpl database, @Nonnull final ResourceConfiguration resourceConfig, @Nonnull final ResourceManagerConfiguration resourceManagerConfig, @Nonnull final BufferManager bufferManager, @Nonnull final Path resourceFile) {
checkNotNull(database);
checkNotNull(resourceConfig);
return mResourceManagers.computeIfAbsent(resourceFile, k -> {
final Storage storage = StorageType.getStorage(resourceConfig);
final UberPage uberPage;
if (storage.exists()) {
try (final Reader reader = storage.createReader()) {
final PageReference firstRef = reader.readUberPageReference();
if (firstRef.getPage() == null) {
uberPage = (UberPage) reader.read(firstRef, null);
} else {
uberPage = (UberPage) firstRef.getPage();
}
}
} else {
// Bootstrap uber page and make sure there already is a root node.
uberPage = new UberPage();
}
final ResourceManager resourceManager = new XdmResourceManager(database, this, resourceConfig, resourceManagerConfig, bufferManager, StorageType.getStorage(resourceConfig), uberPage, mReadSemaphore, mWriteSempahore);
Databases.putResourceManager(resourceFile, resourceManager);
return resourceManager;
});
}
Aggregations