From cee2677c3d2d2d31a5a921b625050fbb4ea45d59 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 7 Dec 2006 08:12:31 +0000 Subject: Added @Authoritative annotation. --- .../repo/replicated/ReplicatedRepository.java | 31 +++++++++++++++++----- .../repo/replicated/ReplicatedStorage.java | 6 +++-- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/replicated') 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 ebfd87f..11c11b6 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java @@ -50,6 +50,7 @@ import com.amazon.carbonado.capability.ShutdownCapability; import com.amazon.carbonado.capability.StorableInfoCapability; import com.amazon.carbonado.info.Direction; +import com.amazon.carbonado.info.StorableInfo; import com.amazon.carbonado.info.StorableIntrospector; import com.amazon.carbonado.spi.StorageCollection; @@ -152,13 +153,31 @@ class ReplicatedRepository protected Storage createStorage(Class type) throws SupportException, RepositoryException { - Storage replicaStorage = mReplicaRepository.storageFor(type); + StorableInfo info = StorableIntrospector.examine(type); - try { - return new ReplicatedStorage(ReplicatedRepository.this, replicaStorage); - } catch (UnsupportedTypeException e) { - // Okay, no master. - return replicaStorage; + if (info.isAuthoritative()) { + // Cannot rely on replica to be up-to-date, so always go to master. + try { + return mMasterRepository.storageFor(type); + } catch (UnsupportedTypeException e) { + if (info.isIndependent()) { + // Okay, no master. A standalone replica is + // considered to be authoritative. + return mReplicaRepository.storageFor(type); + } + throw e; + } + } else { + Storage replicaStorage = mReplicaRepository.storageFor(type); + try { + return new ReplicatedStorage(ReplicatedRepository.this, replicaStorage); + } catch (UnsupportedTypeException e) { + if (info.isIndependent()) { + // Okay, no master. + return replicaStorage; + } + throw e; + } } } }; diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java index 38c57c4..34b6880 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java @@ -64,7 +64,7 @@ class ReplicatedStorage implements Storage { Storage masterStorage = creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS); mTrigger = new ReplicationTrigger(aRepository, mReplicaStorage, masterStorage); - addTrigger(mTrigger); + mReplicaStorage.addTrigger(mTrigger); } /** @@ -76,7 +76,7 @@ class ReplicatedStorage implements Storage { { mReplicaStorage = replicaStorage; mTrigger = new ReplicationTrigger(aRepository, mReplicaStorage, masterStorage); - addTrigger(mTrigger); + mReplicaStorage.addTrigger(mTrigger); } public Class getStorableType() { @@ -100,10 +100,12 @@ class ReplicatedStorage implements Storage { } public boolean addTrigger(Trigger trigger) { + // FIXME: Should trigger be added to master? return mReplicaStorage.addTrigger(trigger); } public boolean removeTrigger(Trigger trigger) { + // FIXME: Should trigger be added to master? return mReplicaStorage.removeTrigger(trigger); } -- cgit v1.2.3