From f0ec30fd9cc7fa19f9f9bf82d7d7449a65d90359 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 15 Oct 2006 17:50:08 +0000 Subject: Created StorageCollection. More tests added. --- .../repo/replicated/ReplicatedRepository.java | 34 +++++++--------------- 1 file changed, 10 insertions(+), 24 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 9a3711f..b07b853 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java @@ -18,9 +18,7 @@ package com.amazon.carbonado.repo.replicated; import java.util.Comparator; -import java.util.IdentityHashMap; import java.util.LinkedHashSet; -import java.util.Map; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; @@ -53,6 +51,7 @@ import com.amazon.carbonado.capability.StorableInfoCapability; import com.amazon.carbonado.info.Direction; import com.amazon.carbonado.info.StorableIntrospector; +import com.amazon.carbonado.spi.StorageCollection; import com.amazon.carbonado.spi.TransactionPair; import com.amazon.carbonado.util.Throttle; @@ -136,8 +135,7 @@ class ReplicatedRepository private Repository mReplicaRepository; private Repository mMasterRepository; - // Map of storages by storable class - private final Map, ReplicatedStorage> mStorages; + private final StorageCollection mStorages; ReplicatedRepository(String aName, Repository aReplicaRepository, @@ -145,8 +143,13 @@ class ReplicatedRepository mName = aName; mReplicaRepository = aReplicaRepository; mMasterRepository = aMasterRepository; - - mStorages = new IdentityHashMap, ReplicatedStorage>(); + mStorages = new StorageCollection() { + protected Storage createStorage(Class type) + throws SupportException, RepositoryException + { + return new ReplicatedStorage(ReplicatedRepository.this, type); + } + }; } public String getName() { @@ -161,27 +164,10 @@ class ReplicatedRepository return mMasterRepository; } - @SuppressWarnings("unchecked") public Storage storageFor(Class type) throws MalformedTypeException, SupportException, RepositoryException { - synchronized (mStorages) { - ReplicatedStorage storage = mStorages.get(type); - if (storage == null) { - // Examine and throw exception if there is a problem. - StorableIntrospector.examine(type); - - storage = createStorage(type); - mStorages.put(type, storage); - } - return storage; - } - } - - private ReplicatedStorage createStorage(Class type) - throws SupportException, RepositoryException - { - return new ReplicatedStorage(this, type); + return mStorages.storageFor(type); } public Transaction enterTransaction() { -- cgit v1.2.3