Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -105,7 +106,7 @@ public class DefaultOcflRepository implements OcflRepository {

private Clock clock;

private boolean closed = false;
private final AtomicBoolean closed = new AtomicBoolean(false);

/**
* @see OcflRepositoryBuilder
Expand Down Expand Up @@ -550,8 +551,9 @@ public void importObject(Path objectPath, OcflOption... options) {
public void close() {
LOG.debug("Close OCFL repository");

closed = true;
storage.close();
if (closed.compareAndSet(false, true)) {
storage.close();
}
}

/**
Expand Down Expand Up @@ -875,7 +877,7 @@ protected OffsetDateTime now(VersionInfo versionInfo) {
}

protected void ensureOpen() {
if (closed) {
if (closed.get()) {
throw new OcflStateException(DefaultOcflRepository.class.getName() + " is closed.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
import edu.wisc.library.ocfl.core.extension.ExtensionSupportEvaluator;
import edu.wisc.library.ocfl.core.extension.OcflExtensionConfig;
import edu.wisc.library.ocfl.core.inventory.InventoryMapper;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* OcflStorage abstract implementation that handles managing the repository's state, initialized, open, close.
*/
public abstract class AbstractOcflStorage implements OcflStorage {

private final AtomicBoolean closed = new AtomicBoolean(false);
private final AtomicBoolean initialized = new AtomicBoolean(false);

protected InventoryMapper inventoryMapper;
protected ExtensionSupportEvaluator supportEvaluator;

private boolean closed = false;
private boolean initialized = false;
private RepositoryConfig repositoryConfig;

/**
Expand All @@ -52,15 +53,15 @@ public synchronized RepositoryConfig initializeStorage(
OcflExtensionConfig layoutConfig,
InventoryMapper inventoryMapper,
ExtensionSupportEvaluator supportEvaluator) {
if (this.initialized) {
if (this.initialized.get()) {
return this.repositoryConfig;
}

this.inventoryMapper = Enforce.notNull(inventoryMapper, "inventoryMapper cannot be null");
this.supportEvaluator = Enforce.notNull(supportEvaluator, "supportEvaluator cannot be null");

this.repositoryConfig = doInitialize(ocflVersion, layoutConfig);
this.initialized = true;
this.initialized.set(true);
return repositoryConfig;
}

Expand All @@ -69,7 +70,7 @@ public synchronized RepositoryConfig initializeStorage(
*/
@Override
public void close() {
closed = true;
closed.set(true);
}

/**
Expand Down Expand Up @@ -100,11 +101,11 @@ public void invalidateCache() {
* Throws an exception if the repository has not been initialized or is closed
*/
protected void ensureOpen() {
if (closed) {
if (closed.get()) {
throw new OcflStateException(this.getClass().getName() + " is closed.");
}

if (!initialized) {
if (!initialized.get()) {
throw new OcflStateException(this.getClass().getName() + " must be initialized before it can be used.");
}
}
Expand Down