From 4684549782accd0ffba1aefd15d42918effeddfd Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 22 Dec 2009 01:15:07 +0000 Subject: Added isClosed method to Repository. --- src/main/java/com/amazon/carbonado/Repository.java | 7 +++++++ .../java/com/amazon/carbonado/repo/indexed/IndexedRepository.java | 4 ++++ .../java/com/amazon/carbonado/repo/logging/LoggingRepository.java | 4 ++++ .../amazon/carbonado/repo/replicated/ReplicatedRepository.java | 4 ++++ src/main/java/com/amazon/carbonado/spi/AbstractRepository.java | 6 ++++++ .../java/com/amazon/carbonado/spi/BelatedRepositoryCreator.java | 4 ++++ src/main/java/com/amazon/carbonado/txn/TransactionManager.java | 4 ++++ src/main/java/com/amazon/carbonado/txn/TransactionScope.java | 8 ++++++++ 8 files changed, 41 insertions(+) (limited to 'src') 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 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 { } } + 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 { TransactionScope(TransactionManager txnMgr, boolean closed) { mTxnMgr = txnMgr; mLock = new ReentrantLock(true); + if (closed) { + mLock.lock(); + try { + mClosed = true; + } finally { + mLock.unlock(); + } + } } /** -- cgit v1.2.3