diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-12-07 08:12:31 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-12-07 08:12:31 +0000 |
commit | cee2677c3d2d2d31a5a921b625050fbb4ea45d59 (patch) | |
tree | 3efc7c8929ac96eb0b89ef0a5789455bc9052793 /src/main/java/com/amazon/carbonado/repo/replicated | |
parent | cdc247a2677611af81567cfc9b570601cdc4c06d (diff) |
Added @Authoritative annotation.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/replicated')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java | 31 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java | 6 |
2 files changed, 29 insertions, 8 deletions
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 <S extends Storable> Storage<S> createStorage(Class<S> type)
throws SupportException, RepositoryException
{
- Storage<S> replicaStorage = mReplicaRepository.storageFor(type);
+ StorableInfo<S> info = StorableIntrospector.examine(type);
- try {
- return new ReplicatedStorage<S>(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<S> replicaStorage = mReplicaRepository.storageFor(type);
+ try {
+ return new ReplicatedStorage<S>(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<S extends Storable> implements Storage<S> { Storage<S> masterStorage =
creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS);
mTrigger = new ReplicationTrigger<S>(aRepository, mReplicaStorage, masterStorage);
- addTrigger(mTrigger);
+ mReplicaStorage.addTrigger(mTrigger);
}
/**
@@ -76,7 +76,7 @@ class ReplicatedStorage<S extends Storable> implements Storage<S> { {
mReplicaStorage = replicaStorage;
mTrigger = new ReplicationTrigger<S>(aRepository, mReplicaStorage, masterStorage);
- addTrigger(mTrigger);
+ mReplicaStorage.addTrigger(mTrigger);
}
public Class<S> getStorableType() {
@@ -100,10 +100,12 @@ class ReplicatedStorage<S extends Storable> implements Storage<S> { }
public boolean addTrigger(Trigger<? super S> trigger) {
+ // FIXME: Should trigger be added to master?
return mReplicaStorage.addTrigger(trigger);
}
public boolean removeTrigger(Trigger<? super S> trigger) {
+ // FIXME: Should trigger be added to master?
return mReplicaStorage.removeTrigger(trigger);
}
|