diff options
Diffstat (limited to 'src/main')
8 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/Repository.java b/src/main/java/com/amazon/carbonado/Repository.java index 7128fea..0d08f3d 100644 --- a/src/main/java/com/amazon/carbonado/Repository.java +++ b/src/main/java/com/amazon/carbonado/Repository.java @@ -154,4 +154,11 @@ public interface Repository { * @throws SecurityException if caller does not have permission
*/
void close();
+
+ /**
+ * Returns true if repository was explicitly closed or shutdown.
+ *
+ * @since 1.2.2
+ */
+ boolean isClosed();
}
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java index 44cc5d1..de6b8df 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java @@ -227,6 +227,10 @@ class IndexedRepository implements Repository, mRepository.close();
}
+ public boolean isClosed() {
+ return mRepository.isClosed();
+ }
+
public Repository getRootRepository() {
return mRootRef.get();
}
diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java index 3c47857..a3d1d4b 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java @@ -106,6 +106,10 @@ class LoggingRepository implements Repository, LogAccessCapability { public void close() {
mRepo.close();
}
+
+ public boolean isClosed() {
+ return mRepo.isClosed();
+ }
public Log getLog() {
return mLog;
diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java index d3414af..e4fdd4c 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java @@ -266,6 +266,10 @@ class ReplicatedRepository mMasterRepository.close();
}
+ public boolean isClosed() {
+ return mReplicaRepository.isClosed() || mMasterRepository.isClosed();
+ }
+
public String[] getUserStorableTypeNames() throws RepositoryException {
StorableInfoCapability replicaCap =
mReplicaRepository.getCapability(StorableInfoCapability.class);
diff --git a/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java b/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java index 688134b..03a6b75 100644 --- a/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java +++ b/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java @@ -139,10 +139,16 @@ public abstract class AbstractRepository<Txn> return null;
}
+ @Override
public void close() {
shutdown(false);
}
+ @Override
+ public boolean isClosed() {
+ return transactionManager().isClosed();
+ }
+
// Required by ShutdownCapability.
public synchronized boolean isAutoShutdownEnabled() {
return mShutdownHook != null;
diff --git a/src/main/java/com/amazon/carbonado/spi/BelatedRepositoryCreator.java b/src/main/java/com/amazon/carbonado/spi/BelatedRepositoryCreator.java index b5676a4..6a7bad6 100644 --- a/src/main/java/com/amazon/carbonado/spi/BelatedRepositoryCreator.java +++ b/src/main/java/com/amazon/carbonado/spi/BelatedRepositoryCreator.java @@ -145,6 +145,10 @@ public class BelatedRepositoryCreator extends BelatedCreator<Repository, Support public void close() {
}
+ public boolean isClosed() {
+ return false;
+ }
+
private IllegalStateException error() {
return new IllegalStateException
("Creation of Repository \"" + mBuilder.getName() + "\" is delayed");
diff --git a/src/main/java/com/amazon/carbonado/txn/TransactionManager.java b/src/main/java/com/amazon/carbonado/txn/TransactionManager.java index 36d2e22..0f203aa 100644 --- a/src/main/java/com/amazon/carbonado/txn/TransactionManager.java +++ b/src/main/java/com/amazon/carbonado/txn/TransactionManager.java @@ -134,6 +134,10 @@ public abstract class TransactionManager<Txn> { }
}
+ public synchronized boolean isClosed() {
+ return mState != OPEN;
+ }
+
/**
* Returns supported isolation level, which may be higher. If isolation
* level cannot go higher (or lower than parent) then return null.
diff --git a/src/main/java/com/amazon/carbonado/txn/TransactionScope.java b/src/main/java/com/amazon/carbonado/txn/TransactionScope.java index bce8ca6..4def72d 100644 --- a/src/main/java/com/amazon/carbonado/txn/TransactionScope.java +++ b/src/main/java/com/amazon/carbonado/txn/TransactionScope.java @@ -57,6 +57,14 @@ public class TransactionScope<Txn> { TransactionScope(TransactionManager<Txn> txnMgr, boolean closed) {
mTxnMgr = txnMgr;
mLock = new ReentrantLock(true);
+ if (closed) {
+ mLock.lock();
+ try {
+ mClosed = true;
+ } finally {
+ mLock.unlock();
+ }
+ }
}
/**
|